Ejemplo n.º 1
0
 def recode(self, text):
     encoding = self.encodings.get(text)
     if encoding is None:
         return text
     if sys.version_info[0] >= 3:
         # sys.stdin is set up for surrogates in GPGKeys.input()
         return decode(encode(text, encoding), errors='surrogateescape')
     else:
         return encode(decode(text), encoding)
Ejemplo n.º 2
0
def gpgdecode(text):
    """Decode a GnuPG string.

    Returns decoded string and source encoding.
    """
    try:
        encoding = 'utf-8'
        text = decode(text, encoding, errors='strict')
    except UnicodeDecodeError:
        try:
            encoding = 'latin-1'
            text = decode(text, encoding, errors='strict')
        except UnicodeDecodeError:
            encoding = getpreferredencoding()
            text = decode(text, encoding)
    return text, encoding