def parse_keys(self, stdoutdata): # Process stdoutdata as byte string since we must run # unescape before decoding. for line in stdoutdata.strip().split(b('\n')): if line[:3] == b('pub'): fields = line.split(b(':')) keyid = fields[4][8:] userid = unescape(fields[9]) keyid, key_enc = gpgdecode(keyid) userid, user_enc = gpgdecode(userid) if sys.version_info[0] < 3: keyid = encode(keyid) userid = encode(userid) self.encodings.setdefault(userid, user_enc) yield (keyid, userid)
from gpgkeys.config import GNUPGEXE from gpgkeys.config import GNUPGHOME from gpgkeys.utils import getpreferredencoding from gpgkeys.utils import decode from gpgkeys.utils import encode from gpgkeys.utils import char from gpgkeys.utils import b from kmd.completions.quoting import dequote_string from kmd.completions.quoting import quote_string keyid_re = re.compile(r'^[0-9A-F]+$', re.I) userid_re = re.compile(r'^(.+?)\s*(?:\((.*)\))*\s*(?:<(.*)>)*$') unescape_re = re.compile(b(r'([\\]x[0-9a-f]{2})')) def unescape(text): """Convert ``gpg --with-colons`` output to a byte string. The string is quoted like a C string to avoid control characters. The colon is encoded as '\x3a'. """ seen = {} for m in unescape_re.finditer(text): for g in m.groups(): if g not in seen: text = text.replace(g, char(int(g[2:], 16))) seen[g] = True return text