home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- __license__ = 'GPL 3'
- __copyright__ = '2009, John Schember <john@nachtimwald.com>'
- __docformat__ = 'restructuredtext en'
- import re
- from calibre.ebooks.unidecode.unicodepoints import CODEPOINTS
- from calibre.constants import preferred_encoding
-
- class Unidecoder(object):
-
- def decode(self, text):
- if not isinstance(text, unicode):
-
- try:
- text = unicode(text)
- try:
- text = text.decode(preferred_encoding)
- text = text.decode('utf-8', 'replace')
-
-
- isinstance(text, unicode)
- return re.sub(('[^\x00-\x7f]',), (lambda x: self.replace_point(x.group())), text)
-
-
- def replace_point(self, codepoint):
-
- try:
- return CODEPOINTS[self.code_group(codepoint)][self.grouped_point(codepoint)]
- except:
- return '?'
-
-
-
- def code_group(self, character):
- return u'x%02x' % (ord(unicode(character)) >> 8)
-
-
- def grouped_point(self, character):
- return ord(unicode(character)) & 255
-
-
-