Skip to main content

Pure python implementation of the BiDi layout algorithm

Project description

https://badge.fury.io/py/python-bidi.png https://travis-ci.org/MeirKriheli/python-bidi.png?branch=master

Bi-directional (BiDi) layout implementation in pure python

Package documentation

API

The algorithm starts with a single entry point bidi.algorithm.get_display.

Required arguments:

  • unicode_or_str: The orginal unicode or string (i.e: storage). If it’s a string use the optional argument encoding to specify it’s encoding.

Optional arguments:

  • encoding: If unicode_or_str is a string, specifies the encdoing. The algorithm uses unicodedata which requires unicode. This encoding will be used to decode and encode back to string before returning (default: “utf-8”).

  • upper_is_rtl: True to treat upper case chars as strong ‘R’ for debugging (default: False).

  • base_dir: ‘L’ or ‘R’, override the calculated base_level.

  • debug: True to display (using sys.stderr) the steps taken with the algorithm (default: False).

Returns the display layout, either as unicode or encoding encoded string (depending on the type of unicode_or_str').

Example:

>>> from bidi.algorithm import get_display
>>> get_display(u'car is THE CAR in arabic', upper_is_rtl=True)
u'car is RAC EHT in arabic'

CLI

pybidi is a command line utility (calling bidi.main) for running the bidi algorithm. the script can get a string as a parameter or read text from stdin. Usage:

$ pybidi -h
Usage: pybidi [options]

Options:
  -h, --help            show this help message and exit
  -e ENCODING, --encoding=ENCODING
                        Text encoding (default: utf-8)
  -u, --upper-is-rtl    treat upper case chars as strong 'R' for debugging
                        (default: False).
  -d, --debug           Output to stderr steps taken with the algorithm
  -b BASE_DIR, --base-dir=BASE_DIR
                        Override base direction [L|R]

Examples:

$ pybidi -u 'car is THE CAR in arabic'
car is RAC EHT in arabic

$ cat ~/Documents/example.txt | pybidi
...

Installation

See docs/INSTALL.rst

Running tests

To run the tests:

python setup.py test

Some explicit tests are failing right now (see TODO)

History

0.4.1

  • Merged Fix for mixed RTL and numbers, Thanks Just van Rossum

0.4.0

  • Move to cookiecutter template

  • Python 3 support (py2.6, 2.7, 3.3, 3.4 and pypy)

  • Better docs

  • Travis integration

  • Tox tests

  • PEP8 cleanup

0.3.4

  • Remove extra newline in console script output

0.3.3

  • Implement overriding base paragraph direction

  • Allow overriding base direction in pybidi console script

  • Fix returning display in same encoding

0.3.2

  • Test for surrogate pairs

  • Fix indentation in documentations

  • Specify license in setup.py

0.3.1

  • Added missing description

  • docs/INSTALL.rst

0.3

  • Apply bidi mirroring

  • Move to back function based implementation

0.2

  • Move the algorithm to a class based implementation

0.1

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-bidi-0.4.1.tar.gz (40.3 kB view details)

Uploaded Source

Built Distribution

python_bidi-0.4.1-py2.py3-none-any.whl (30.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file python-bidi-0.4.1.tar.gz.

File metadata

  • Download URL: python-bidi-0.4.1.tar.gz
  • Upload date:
  • Size: 40.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for python-bidi-0.4.1.tar.gz
Algorithm Hash digest
SHA256 d55be25389827889ac3d6ca010bc386aeb3762080c219f768fa4dfa02c975aa8
MD5 0bfd324a811627b14ef61a43c0dea24e
BLAKE2b-256 f393bc9315cece6605ad4f4ebacb67a0f558c216ae1c5444246b6d6d4667de12

See more details on using hashes here.

File details

Details for the file python_bidi-0.4.1-py2.py3-none-any.whl.

File metadata

  • Download URL: python_bidi-0.4.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 30.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for python_bidi-0.4.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c97eebbf2e3446d9fa7b1f5b34e7ee7ff664d6b5511acd6c4ad333f03c5edf1f
MD5 47592b00ec95007c717d4be4a3431356
BLAKE2b-256 4b4729eec20071ca621f04fc7b4b5e8b53c44e41ac0103e98f4e8bd432289659

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page