bidi package¶
Submodules¶
bidi.algorithm module¶
bidirectional algorithm implementation
- bidi.algorithm.calc_level_runs(storage)[source]¶
Split the storage to run of char types at the same level.
Applies X10. See http://unicode.org/reports/tr9/#X10
- bidi.algorithm.debug_storage(storage, base_info=False, chars=True, runs=False)[source]¶
Display debug information for the storage
- bidi.algorithm.explicit_embed_and_overrides(storage, debug=False)[source]¶
Apply X1 to X9 rules of the unicode algorithm.
See http://unicode.org/reports/tr9/#Explicit_Levels_and_Directions
- bidi.algorithm.get_base_level(text, upper_is_rtl=False) int[source]¶
Get the paragraph base embedding level. Returns 0 for LTR, 1 for RTL.
text a unicode object.
Set upper_is_rtl to True to treat upper case chars as strong ‘R’ for debugging (default: False).
- bidi.algorithm.get_display(str_or_bytes: str | bytes, encoding: str = 'utf-8', upper_is_rtl: bool = False, base_dir: str | None = None, debug: bool = False) str | bytes[source]¶
Accepts str or bytes. In case it’s bytes, encoding is needed as the algorithm works on str (default:”utf-8”).
Set upper_is_rtl to True to treat upper case chars as strong ‘R’ for debugging (default: False).
Set base_dir to ‘L’ or ‘R’ to override the calculated base_level.
Set debug to True to display (using sys.stderr) the steps taken with the algorithm.
Returns the display layout, either as unicode or encoding encoded string.
- bidi.algorithm.get_embedding_levels(text, storage, upper_is_rtl=False, debug=False)[source]¶
Get the paragraph base embedding level and direction, set the storage to the array of chars
- bidi.algorithm.resolve_implicit_levels(storage, debug)[source]¶
Resolving implicit levels (I1, I2)
See: http://unicode.org/reports/tr9/#Resolving_Implicit_Levels
- bidi.algorithm.resolve_neutral_types(storage, debug)[source]¶
Resolving neutral types. Implements N1 and N2
See: http://unicode.org/reports/tr9/#Resolving_Neutral_Types
- bidi.algorithm.reverse_contiguous_sequence(chars, line_start, line_end, highest_level, lowest_odd_level)[source]¶
L2. From the highest level found in the text to the lowest odd level on each line, including intermediate levels not actually present in the text, reverse any contiguous sequence of characters that are at that level or higher.
bidi.bidi module¶
- bidi.bidi.get_base_level_inner(text)¶
- bidi.bidi.get_display_inner(text, base_dir=None, debug=False)¶
bidi.mirror module¶
Mirrored chars
bidi.wrapper module¶
Provides a wrpper for the Rust based implementation.
- bidi.wrapper.get_base_level(text: str) int[source]¶
Returns the base unicode level of the 1st paragraph in text.
Return value of 0 means LTR, while 1 means RTL.
- bidi.wrapper.get_display(str_or_bytes: str | bytes, encoding: str = 'utf-8', base_dir: str | None = None, debug: bool = False) str | bytes[source]¶
Accepts string or bytes. In case of bytes, encoding is needed as the inner function expects a valid string (default:”utf-8”).
Set base_dir to ‘L’ or ‘R’ to override the calculated base_level.
Set debug to True to return the calculated levels.
Returns the display layout, either as unicode or encoding encoded string.
Module contents¶
- bidi.get_base_level(text: str) int[source]¶
Returns the base unicode level of the 1st paragraph in text.
Return value of 0 means LTR, while 1 means RTL.
- bidi.get_display(str_or_bytes: str | bytes, encoding: str = 'utf-8', base_dir: str | None = None, debug: bool = False) str | bytes[source]¶
Accepts string or bytes. In case of bytes, encoding is needed as the inner function expects a valid string (default:”utf-8”).
Set base_dir to ‘L’ or ‘R’ to override the calculated base_level.
Set debug to True to return the calculated levels.
Returns the display layout, either as unicode or encoding encoded string.