Skip to main content

Python codec for converting between a string of ASCII and Unicode chars maintaining readability

Project description

https://travis-ci.org/box/rotunicode.png?branch=master https://coveralls.io/repos/box/rotunicode/badge.png https://pypip.in/v/rotunicode/badge.png https://pypip.in/d/rotunicode/badge.png

Upcoming Breaking Change!

When RotUnicode was released through version 0.3.0, it was released under the namespace box.util. In version 1.1.2, importing rotunicode became easier:

from rotunicode import RotUnicode

vs.

from box.util.rotunicode import RotUnicode

In version 2.0.0, however, you will no longer be able to import rotunicode from box.util.

About

RotUnicode is a Python codec that can convert a string of ASCII characters to a Unicode string with non-ASCII characters maintaining readability.

>>> import codecs
>>> from rotunicode import RotUnicode
>>> codecs.register(RotUnicode.search_function)
>>> 'Hello World!'.encode('rotunicode')
Ĥȅľľő Ŵőŕľď!
>>> 'Ĥȅľľő Ŵőŕľď!'.decode('rotunicode')
Hello World!

RotUnicode is extremely helpful in testing your application because it makes it easy to create strings with non-ASCII characters. Example -

>>> import os, errno
>>> name = 'foo'.encode('rotunicode')
>>> os.mkdir(name)
>>> print(name)
ƒőő
>>> os.path.exists(name)
True
>>> os.statvfs(name)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2:
ordinal not in range(128)

This bug is filed at http://bugs.python.org/issue18695.

Supported Characters

RotUnicode converts lower case and upper case characters of the English alphabet and digits 0 to 9 to non-ASCII characters. All characters that are outside this range are left as is.

>>> 'हेलो World!'.encode('rotunicode')
हेलो Ŵőŕľď!
>>> 'हेलो Ŵőŕľď!'.decode('rotunicode')
हेलो World!

Installation

To install, simply:

pip install rotunicode

Contribute

See CONTRIBUTING.

Setup

Create a virtual environment and install packages:

mkvirtualenv rotunicode
pip install -r requirements-dev.txt

Testing

Run all tests using:

tox

The tox tests include code style checks via pep8 and pylint.

Why is this named RotUnicode?

RotUnicode stands for rotate-to-unicode. Or rotten-unicode for those who have nightmares about Unicode. It was inspired by Rot13.

Project details


Release history Release notifications

History Node

2.2.0

History Node

2.1.0

History Node

2.0.0

This version
History Node

1.1.2

History Node

1.0.2

History Node

1.0.1

History Node

1.0.0

History Node

0.1.6

History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
rotunicode-1.1.2.tar.gz (9.1 kB) Copy SHA256 hash SHA256 Source None Aug 29, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page