'Prepends a 0x to hexadecimal key ids.
For example, D13C70DA is converted to 0xD13C70DA. This is required
by version 2.x of GnuPG (and is accepted by 1.x).'

def _escape_hex_keyid_term(self, term):

    is_hex_keyid = False
    if ((len(term) == GPG_KEYID_LENGTH) or (len(term) == (2 * GPG_KEYID_LENGTH))):
        hex_digits = set(string.hexdigits)
        is_hex_keyid = all(((c in hex_digits) for c in term))
    if is_hex_keyid:
        return ('0x%s' % term)
    else:
        return term
