Skip to main content

The mayo on your unicode sandwich

Project description

unicode_mayo is the mayo in your unicode sandwich. In your development environment, use it as a wrapper around unicode and byte strings to see if they’re accidentally coming in to contact with byte strings. This can help catch unicode encode/decode errors before they happen in production!

unicode_mayo includes two classes: UnicodeSafetyWrapper and BytestringSafetyWrapper. The former is meant to envelope unicode strings, and warns when they come into contact with byte strings; the latter is meant for byte strings, and warns when it comes into contact with unicode. Place these in strategic places (likely in development environments only), like gettext() or all strings from your database.

Installation

Installation via pip:

pip install unicode_mayo

Usage

Something like:

>>> import unicode_mayo
>>> wrapped = unicode_mayo.UnicodeSafetyWrapper(u'safety at last!')
>>> wrapped.encode('utf-8')
'safety at last!'
>>> wrapped + u' woohoo!'
u'safety at last! woohoo!'
>>> wrapped + 'evil bytestring'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/eyalr/personal_work/unicode_mayo/src/unicode_mayo/__init__.py", line 55, in __add__
    _fail_on_bytes(other)
  File "/Users/eyalr/personal_work/unicode_mayo/src/unicode_mayo/__init__.py", line 90, in _fail_on_bytes
    _fail_on_bytes_helper(other)
  File "/Users/eyalr/personal_work/unicode_mayo/src/unicode_mayo/__init__.py", line 81, in _fail_on_bytes_helper
    'Attempted string formatting without decoding utf-8'
TypeError: Attempted string formatting without decoding utf-8

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

unicode_mayo-1.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

unicode_mayo-1.1.0-py2-none-any.whl (5.1 kB view details)

Uploaded Python 2

File details

Details for the file unicode_mayo-1.1.0.tar.gz.

File metadata

  • Download URL: unicode_mayo-1.1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.16

File hashes

Hashes for unicode_mayo-1.1.0.tar.gz
Algorithm Hash digest
SHA256 deb67db1a4d12d634cb21a939f39383b17160fd37ff4cf86075abb24a2578e27
MD5 b04384fb4b8ae83e5b55dc2459a36bbf
BLAKE2b-256 583f7f00da918abf8003bc52c3bc0301a4c80cd7d216f10ae4468466131ae3c1

See more details on using hashes here.

File details

Details for the file unicode_mayo-1.1.0-py2-none-any.whl.

File metadata

  • Download URL: unicode_mayo-1.1.0-py2-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.16

File hashes

Hashes for unicode_mayo-1.1.0-py2-none-any.whl
Algorithm Hash digest
SHA256 46f009fbfc50d6b358eb32f249b0ec3f77bf2f5eff70f396cbb60f06f1934ec9
MD5 dca5175c06fb4134fdd7390f2413ee29
BLAKE2b-256 183f687ee07dc3f980a2b300250ee831d12842c3a715f378234ecf27788cd7a9

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 Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page