xotl.tools.future.codecs - Codec registry, base classes and tools

This module extends the standard library’s functools. You may use it as a drop-in replacement in many cases.

Avoid importing * from this module since could be different in Python 2.7 and Python 3.3.

We added the following features.

xotl.tools.future.codecs.force_encoding(encoding=None)[source]

Validates an encoding value.

If encoding is None use locale.getdefaultlocale(). If that is also none, return ‘UTF-8’.

New in version 1.2.0.

Changed in version 1.8.0: migrated to ‘future.codecs’

Changed in version 1.8.7: Stop using locale.getpreferrededencoding() and improve documentation.

xotl.tools.future.codecs.safe_decode(s, encoding=None)[source]

Similar to bytes decode method returning unicode.

Decodes s using the given encoding, or determining one from the system.

Returning type depend on python version; if 2.x is unicode if 3.x str.

New in version 1.1.3.

Changed in version 1.8.0: migrated to ‘future.codecs’

xotl.tools.future.codecs.safe_encode(u, encoding=None)[source]

Similar to unicode encode method returning bytes.

Encodes u using the given encoding, or determining one from the system.

Returning type is always bytes; but in python 2.x is also str.

New in version 1.1.3.

Changed in version 1.8.0: migrated to ‘future.codecs’