Skip to content
This repository has been archived by the owner on Apr 24, 2018. It is now read-only.

A secret content decoder ring for Python (extracted from Requests).

Notifications You must be signed in to change notification settings

kennethreitz-archive/ovaltine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Ovaltine: a Secret Encoding Decoder Ring for Python

Ovaltine (extracted from Requests) is a simple Python library for working with unicode embedded within an undeterministic encoding.

For example, many web servers lie about what encoding their responses are. You can use Ovaltine, which in turn uses chardet, to detect the apparent encoding and get back as much usable data as possible.

Usage

Simply get back unicode, no matter what:

>>> import ovaltine

>>> ovaltine.drink(b'foo bar')
u'foo bar'

Or, for more advanced usage:

>>> from ovaltine import DecoderRing

>>> content = requests.get('https://kennethreitz.org/').content
>>> r = DecoderRing(content)

>>> r
<DecoderRing len=74773, encoding=None, apparently='ISO-8859-2'>
>>> r.apparently
'ISO-8859-2'
>>> r.text
... # Unicode is shown here.

# Set the encoding yourself.
>>> r.encoding = 'UTF-8'
>>> r.text
... # Unicode is shown here.

About

A secret content decoder ring for Python (extracted from Requests).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages