Skip to main content
http://opensource.box.com/badges/active.svg https://travis-ci.org/box/rotunicode.png?branch=master https://coveralls.io/repos/box/rotunicode/badge.png https://img.shields.io/pypi/v/rotunicode.svg https://img.shields.io/pypi/dm/rotunicode.svg

RotUnicode is a Python library that can convert a string containing ASCII characters to a string with non-ASCII characters without losing readability.

>>> 'Hello World!'.encode('rotunicode')
Ĥȅľľő Ŵőŕľď!
>>> 'Ĥȅľľő Ŵőŕľď!'.decode('rotunicode')
Hello World!

In the above example, the ‘Hello World’ string has all ASCII characters. Encoding it with RotUnicode gives you ‘Ĥȅľľő Ŵőŕľď’ which reads like ‘Hello World’ but has all non-ASCII characters.

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.

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

Use

>>> from rotunicode import ruencode
>>> ruencode('Hello World!')
Ĥȅľľő Ŵőŕľď!
>>> rudecode('Ĥȅľľő Ŵőŕľď!')
Hello World!

As a Codec

In Python 2, RotUnicode can also be used as a codec, but it must first be registered with the codecs library. This allows python to know what functions to call to encode or decode a string using RotUnicode.

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

Command Line

Installing RotUnicode also includes a command line tool.

$ rotunicode "Hello World"
Ĥȅľľő Ŵőŕľď!
$ rotunicode -d "Ĥȅľľő Ŵőŕľď!"
Hello World!
$ echo "Hello World!" > hello.txt
$ rotunicode -f hello.txt
Ĥȅľľő Ŵőŕľď!
$ cat hello.txt | rotunicode -f
Ĥȅľľő Ŵőŕľď!

Why should I use RotUnicode?

RotUnicode it extremely helpful in testing because it reduces the friction for developers to test with non-ASCII strings. Imagine for example that you have a class to represent a contact for your address book application:

class Contact(object):

    def __init__(self, first_name, last_name):
        super(Contact, self).__init__()
        self.first_name = first_name
        self.last_name = last_name

    def display_name(self):
        return '{} {}'.format(self.first_name, self.last_name)

Most developers would test this as follows:

from unittest import TestCase
from contact import Contact

class ContactTests(TestCase):

    def test_display_name(self):
        contact = Contact('John', 'Doe’)
        self.assertEqual('John Doe', contact.display_name()))

This test is good. But it is going to miss catching problems in the code with non-ASCII characters. Requiring developers to remember how to type non-ASCII characters is not practical. With RotUnicode, this is super easy:

from unittest import TestCase
from contact import Contact

class ContactTests(TestCase):

    def test_display_name_with_ascii_name(self):
        contact = Contact(u'John', u'Doe')
        self.assertEqual(u'John Doe', contact.display_name())

    def test_display_name_with_non_ascii_name(self):
        contact = Contact(ruencode(u'John'), ruencode(u'Doe'))
        self.assertEqual(ruencode(u'John Doe'), contact.display_name())

This is an example of a bug in Python (issue18695) with non-ASCII characters -

>>> 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)

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.

The tox tests are configured to run on Python 2.7, 3.4, 3.5, 3.6, 3.7, and PyPy2.7 (version 5.10).

Metadata

Release files for rotunicode 2.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rotunicode 2.3.0
File Size Uploaded Provenance
rotunicode-2.3.0.tar.gz 15.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for rotunicode 2.3.0
File Interpreter ABI Platform
rotunicode-2.3.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 28.0 kB

Release files / rotunicode-2.3.0.tar.gz

Download URL rotunicode-2.3.0.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
080f0cf13a2adfbd23b574b34df1c81279fc1a04006e6dfa75610cde691403cf
BLAKE2b-256 checksum
How to use checksums
0cba9c424818d955c8e9c2693d934c43a8dcfc93cbaa639621c2b4c1abec84c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.1 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.6.0

Release files / rotunicode-2.3.0-py2.py3-none-any.whl

Download URL rotunicode-2.3.0-py2.py3-none-any.whl
Size 12.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c5857185c2b3936f74090cbc04c7cda89593e1b4869156b67781268b8ce1dc68
BLAKE2b-256 checksum
How to use checksums
c13851fe998233934d5e1cf0dd2673253300ee094673f8cf5d2119cf53598f3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.1 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.6.0

Security for rotunicode 2.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page