Python base64 模块,b16encode() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用base64.b16encode()

项目:outis    作者:SySS-Research    | 项目源码 | 文件源码
def dnshostencode(data, zone):
    """
    encodes the data in a DNS transmittable hostname, 0-9A-F
    :param data: DNS transmittable hostname data
    :param zone: DNS zone to add at the end
    :return: encoded form
    """

    # TODO: sending 0-9A-Z would be better

    res = b""
    sdata = base64.b16encode(data)

    # every 60 characters, we will add a dot
    for i in range(len(sdata)):
        res += sdata[i:i+1]
        if (i+1) % 60 == 0 and (i+1) < len(sdata):
            res += b'.'

    return res + b'.' + zone.encode('utf-8') + b'.'
项目:outis    作者:SySS-Research    | 项目源码 | 文件源码
def dnsip6encode(data):
    """
    encodes the data as a single IPv6 address
    :param data: data to encode
    :return: encoded form
    """

    if len(data) != 16:
        print_error("dnsip6encode: data is more or less than 16 bytes, cannot encode")
        return None

    res = b''
    reslen = 0
    for i in range(len(data)):
        res += base64.b16encode(data[i:i+1])
        reslen += 1
        if reslen % 2 == 0:
            res += b':'

    return res[:-1]
项目:pomu    作者:Hummer12007    | 项目源码 | 文件源码
def parse_tree(blob, path=b''):
    """Parses a git tree"""
    res = []
    leng, _, tree = blob.partition(b'\0')
    if path is str:
        path = path.encode('utf-8')
    if not tree:
        return Result.Err('Invalid tree')
    while len(tree) > 0:
        mode, _, tree = tree.partition(b' ')
        name, _, tree = tree.partition(b'\0')
        sha = b16encode(tree[0:20]).decode('utf-8').lower()
        tree = tree[20:]
        if not name or not sha:
            return Result.Err()
        is_dir = mode[0:1] != b'1'
        res.append((is_dir, sha, path + b'/' + name))
    return Result.Ok(res)
项目:ndh-challenges    作者:the-mandarine    | 项目源码 | 文件源码
def main():
    submission = raw_input("flag> ")
    low_sub = submission.lower()
    temp_list = list(low_sub)
    temp_list.reverse()
    flag = "".join(temp_list)
    new_string = ""
    for char in flag:
        if char in BASE:
            new_char = BASE[char]
        else:
            new_char = char
        new_string += new_char

    to_encode = new_string.encode('utf8')

    to_give = base64.b16encode(to_encode)
    #to_give = base64.b32encode(to_encode)
    #to_give = base64.b64encode(to_encode)
    print to_give
项目:Th3g3ntl3man-CTF-Writeups    作者:hgarrereyn    | 项目源码 | 文件源码
def main():
    modulus = int("A9625641EE2E381A4A887EA3A8AE900DD1E27FD9184F2E01EA486A234909A22475F34B034B48E9B6FB407895B9EA66694A4951B032FBE60F11DFB1D145BB765F66B72FC7E0E1F938455620F141A5A85B2EF049F55C5B33E351943506889F826D6936DEC658B8926A26273C7B8E8AC9AF7123D106515F76ED37FC7C513AC19DA9",16)
    e = 65537
    p = int("00:b6:a0:fc:62:b3:d4:cd:68:06:cb:54:e5:0e:65:08:4a:49:b3:49:12:40:95:cb:9c:2c:de:40:f9:31:b5:6c:d9:1d:a6:80:e4:0c:ca:75:a0:0b:2c:4a:38:8b:5d:d9:15:87:71:6e:fd:c7:cf:5a:5b:90:88:37:83:b4:f3:fd:3d".replace(":",""),16)
    assert modulus % p == 0
    q = modulus //p
    d = modinv(e,(p-1)*(q-1))
    a = ""
    c = b"HPDng5QcgvfhFuVLfMrs1+kg3cyo2GEGwxdTICOsAYgpTA2qNuTBHetrfmVMDr1n2Iu1D7lTqSGY/eH/ZGbryyBr3MuOoc+R7m2ipxl1cL/5e/UaPP0rplohjCxduEDil7WlrLfwFR8GCGhF1usgV9gzo3Ok12v8J4veejWPe4k="
    import base64
    hexString = base64.b16encode(base64.standard_b64decode(c))
    print(hexString)
    c = int(hexString,16)
    msg = pow(c,d,modulus)
    print(msg)
    import binascii
    print(binascii.unhexlify(hex(msg)[2:]))
项目:gopro-py-api    作者:KonradIT    | 项目源码 | 文件源码
def getStatus(self, param, value=""):
       if self.whichCam() == "gpcontrol":
            try:
                req=urllib.request.urlopen("http://10.5.5.9/gp/gpControl/status", timeout=5)
                data = req.read()
                encoding = req.info().get_content_charset('utf-8')
                json_data = json.loads(data.decode(encoding))
                return json_data[param][value]
            except (HTTPError, URLError) as error:
                return ""
                print("Error code:" + str(error.code) + "\nMake sure the connection to the WiFi camera is still active.")
            except timeout:
                return ""
                print("HTTP Timeout\nMake sure the connection to the WiFi camera is still active.")
       else:
            response = urllib.request.urlopen("http://10.5.5.9/camera/sx?t=" + self.getPassword(), timeout=5).read()
            response_hex = str(bytes.decode(base64.b16encode(response), 'utf-8'))
            return str(response_hex[param[0]:param[1]])
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(photo, site=None):
    """Find duplicate images.

    Take the photo, calculate the SHA1 hash and ask the MediaWiki api
    for a list of duplicates.

    TODO: Add exception handling.

    @param photo: Photo
    @type photo: io.BytesIO
    @param site: Site to search for duplicates.
        Defaults to using Wikimedia Commons if not supplied.
    @type site: APISite or None
    """
    if not site:
        site = pywikibot.Site('commons', 'commons')
    hashObject = hashlib.sha1()
    hashObject.update(photo.getvalue())
    return site.getFilesFromAnHash(base64.b16encode(hashObject.digest()))
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(filename):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    f = open(filename, 'rb')

    result = []
    hashObject = hashlib.sha1()
    hashObject.update(f.read(-1)) 
    #f.close()
    sha1Hash = base64.b16encode(hashObject.digest())

    params = {
    'action'    : 'query',
        'list'      : 'allimages',
        'aisha1'    : sha1Hash,
        'aiprop'    : '',
    }
    data = query.GetData(params, site=wikipedia.getSite(), useAPI = True, encodeTitle = False)

    for image in data['query']['allimages']:
        result.append(image['name'])
    return result
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(filename):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    f = open(filename, 'rb')

    result = []
    hashObject = hashlib.sha1()
    hashObject.update(f.read(-1)) 
    #f.close()
    sha1Hash = base64.b16encode(hashObject.digest())

    params = {
    'action'    : 'query',
        'list'      : 'allimages',
        'aisha1'    : sha1Hash,
        'aiprop'    : '',
    }
    data = query.GetData(params, site=wikipedia.getSite(), useAPI = True, encodeTitle = False)

    for image in data['query']['allimages']:
        result.append(image['name'])
    return result
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(filename):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    f = open(filename, 'rb')

    result = []
    hashObject = hashlib.sha1()
    hashObject.update(f.read(-1)) 
    #f.close()
    sha1Hash = base64.b16encode(hashObject.digest())

    params = {
    'action'    : 'query',
        'list'      : 'allimages',
        'aisha1'    : sha1Hash,
        'aiprop'    : '',
    }
    data = query.GetData(params, site=wikipedia.getSite(), useAPI = True, encodeTitle = False)

    for image in data['query']['allimages']:
        result.append(image['name'])
    return result
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(filename):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    f = open(filename, 'rb')

    result = []
    hashObject = hashlib.sha1()
    hashObject.update(f.read(-1)) 
    #f.close()
    sha1Hash = base64.b16encode(hashObject.digest())

    params = {
    'action'    : 'query',
        'list'      : 'allimages',
        'aisha1'    : sha1Hash,
        'aiprop'    : '',
    }
    data = query.GetData(params, site=wikipedia.getSite(), useAPI = True, encodeTitle = False)

    for image in data['query']['allimages']:
        result.append(image['name'])
    return result
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(filename):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    f = open(filename, 'rb')

    result = []
    hashObject = hashlib.sha1()
    hashObject.update(f.read(-1)) 
    #f.close()
    sha1Hash = base64.b16encode(hashObject.digest())

    params = {
    'action'    : 'query',
        'list'      : 'allimages',
        'aisha1'    : sha1Hash,
        'aiprop'    : '',
    }
    data = query.GetData(params, site=wikipedia.getSite(), useAPI = True, encodeTitle = False)

    for image in data['query']['allimages']:
        result.append(image['name'])
    return result
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(filename):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    f = open(filename, 'rb')

    result = []
    hashObject = hashlib.sha1()
    hashObject.update(f.read(-1)) 
    #f.close()
    sha1Hash = base64.b16encode(hashObject.digest())

    params = {
    'action'    : 'query',
        'list'      : 'allimages',
        'aisha1'    : sha1Hash,
        'aiprop'    : '',
    }
    data = query.GetData(params, site=wikipedia.getSite(), useAPI = True, encodeTitle = False)

    for image in data['query']['allimages']:
        result.append(image['name'])
    return result
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(photo=None, site=wikipedia.getSite()):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    result = []
    hashObject = hashlib.sha1()
    hashObject.update(photo.getvalue())
    sha1Hash = base64.b16encode(hashObject.digest())

    params = {
    'action'    : 'query',
        'list'      : 'allimages',
        'aisha1'    : sha1Hash,
        'aiprop'    : '',
    }
    data = query.GetData(params, site=wikipedia.getSite(), useAPI = True, encodeTitle = False)
    for image in data['query']['allimages']:
        result.append(image['name'])
    return result
项目:love    作者:Yelp    | 项目源码 | 文件源码
def get_gravatar(self):
        """Creates gravatar URL from email address."""
        m = hashlib.md5()
        m.update(self.user.email())
        encoded_hash = base64.b16encode(m.digest()).lower()
        return 'https://gravatar.com/avatar/{}?s=200'.format(encoded_hash)
项目:GAMADV-XTD    作者:taers232c    | 项目源码 | 文件源码
def hex_key(self):
        """
        secret key encoded as hexadecimal string
        """
        return bascii_to_str(base64.b16encode(self.key)).lower()
项目:cbor_py    作者:brianolson    | 项目源码 | 文件源码
def _oso(self, ob):
        ser = self.dumps(ob)
        try:
            o2 = self.loads(ser)
            assert ob == o2, '%r != %r from %s' % (ob, o2, base64.b16encode(ser))
        except Exception as e:
            sys.stderr.write('failure on buf len={0} {1!r} ob={2!r} {3!r}; {4}\n'.format(len(ser), hexstr(ser), ob, ser, e))
            raise
项目:cbor_py    作者:brianolson    | 项目源码 | 文件源码
def _oso_bytearray(self, ob):
        ser = self.dumps(ob)
        try:
            o2 = self.loads(bytearray(ser))
            assert ob == o2, '%r != %r from %s' % (ob, o2, base64.b16encode(ser))
        except Exception as e:
            sys.stderr.write('failure on buf len={0} {1!r} ob={2!r} {3!r}; {4}\n'.format(len(ser), hexstr(ser), ob, ser, e))
            raise
项目:cbor_py    作者:brianolson    | 项目源码 | 文件源码
def _oso(self, ob):
        ser = self.tx.dumps(ob)
        try:
            o2 = self.tx.loads(ser)
            assert ob == o2, '%r != %r from %s' % (ob, o2, base64.b16encode(ser))
        except Exception as e:
            sys.stderr.write('failure on buf len={0} {1!r} ob={2!r} {3!r}; {4}\n'.format(len(ser), hexstr(ser), ob, ser, e))
            raise
项目:cbor_py    作者:brianolson    | 项目源码 | 文件源码
def _check(row, decoded):
    cbdata = base64.b64decode(row['cbor'])
    if cloads is not None:
        cb = cloads(cbdata)
        if cb != decoded:
            anyerr = True
            sys.stderr.write('expected {0!r} got {1!r} c failed to decode cbor {2}\n'.format(decoded, cb, base64.b16encode(cbdata)))

    cb = pyloads(cbdata)
    if cb != decoded:
        anyerr = True
        sys.stderr.write('expected {0!r} got {1!r} py failed to decode cbor {2}\n'.format(decoded, cb, base64.b16encode(cbdata)))
项目:cbor_py    作者:brianolson    | 项目源码 | 文件源码
def _check_foo(row, checkf):
    cbdata = base64.b64decode(row['cbor'])
    if cloads is not None:
        cb = cloads(cbdata)
        if not checkf(cb):
            anyerr = True
            sys.stderr.write('expected {0!r} got {1!r} c failed to decode cbor {2}\n'.format(decoded, cb, base64.b16encode(cbdata)))

    cb = pyloads(cbdata)
    if not checkf(cb):
        anyerr = True
        sys.stderr.write('expected {0!r} got {1!r} py failed to decode cbor {2}\n'.format(decoded, cb, base64.b16encode(cbdata)))
项目:aws-cfn-plex    作者:lordmuffin    | 项目源码 | 文件源码
def signature(self):
        try:
            from hashlib import md5
        except ImportError:
            from md5 import md5
        try:
            sig = md5()
            if self.start:
                sig.update(self.start.encode('latin-1'))
            if self.prec:
                sig.update(''.join([''.join(p) for p in self.prec]).encode('latin-1'))
            if self.tokens:
                sig.update(' '.join(self.tokens).encode('latin-1'))
            for f in self.pfuncs:
                if f[3]:
                    sig.update(f[3].encode('latin-1'))
        except (TypeError, ValueError):
            pass

        digest = base64.b16encode(sig.digest())
        if sys.version_info[0] >= 3:
            digest = digest.decode('latin-1')
        return digest

    # -----------------------------------------------------------------------------
    # validate_modules()
    #
    # This method checks to see if there are duplicated p_rulename() functions
    # in the parser module file.  Without this function, it is really easy for
    # users to make mistakes by cutting and pasting code fragments (and it's a real
    # bugger to try and figure out why the resulting parser doesn't work).  Therefore,
    # we just do a little regular expression pattern matching of def statements
    # to try and detect duplicates.
    # -----------------------------------------------------------------------------
项目:tracker    作者:Songbee    | 项目源码 | 文件源码
def b32_to_b16(s):
    return b16encode(b32decode(s.upper()))
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_b16encode(self):
        eq = self.assertEqual
        eq(base64.b16encode(b'\x01\x02\xab\xcd\xef'), b'0102ABCDEF')
        eq(base64.b16encode(b'\x00'), b'00')
        self.assertRaises(TypeError, base64.b16encode, "")
项目:plugin.video.brplay    作者:olavopeixoto    | 项目源码 | 文件源码
def K(a):
    # def I has been replaced with hashlib.md5.digest
    # def rstr2hex has been replaced with b16encode
    # note that def rstr2hex outputs in lower
    digest = hashlib.md5(a + H[1:]).digest()
    return base64.b16encode(digest).replace('=', '')
项目:fedoidc    作者:OpenIDC    | 项目源码 | 文件源码
def get_symkey(link):
    md5 = hashlib.md5()
    md5.update(link.encode("utf-8"))
    return base64.b16encode(md5.digest()).decode("utf-8")


# this pattern matches substrings of reserved and non-ASCII characters
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_b16encode(self):
        eq = self.assertEqual
        eq(base64.b16encode('\x01\x02\xab\xcd\xef'), '0102ABCDEF')
        eq(base64.b16encode('\x00'), '00')
        # Non-bytes
        eq(base64.b16encode(bytearray('\x01\x02\xab\xcd\xef')), '0102ABCDEF')
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_b16encode(self):
        eq = self.assertEqual
        eq(base64.b16encode('\x01\x02\xab\xcd\xef'), '0102ABCDEF')
        eq(base64.b16encode('\x00'), '00')
        # Non-bytes
        eq(base64.b16encode(bytearray('\x01\x02\xab\xcd\xef')), '0102ABCDEF')
项目:MiNode    作者:TheKysek    | 项目源码 | 文件源码
def clean_objects():
        for vector in set(shared.objects):
            if shared.objects[vector].is_expired():
                with shared.objects_lock:
                    del shared.objects[vector]
                logging.debug('Deleted expired object: {}'.format(base64.b16encode(vector).decode()))
项目:MiNode    作者:TheKysek    | 项目源码 | 文件源码
def __repr__(self):
        return 'type: header, command: "{}", payload_length: {}, payload_checksum: {}'\
            .format(self.command.decode(), self.payload_length, base64.b16encode(self.payload_checksum).decode())
项目:MiNode    作者:TheKysek    | 项目源码 | 文件源码
def __repr__(self):
        return '{}, payload_length: {}, payload_checksum: {}'\
            .format(self.command.decode(), self.payload_length, base64.b16encode(self.payload_checksum).decode())
项目:MiNode    作者:TheKysek    | 项目源码 | 文件源码
def __repr__(self):
        return 'version, protocol_version: {}, services: {}, host: {}, port: {}, nonce: {}, user_agent: {}'\
            .format(self.protocol_version, self.services, self.host, self.port, base64.b16encode(self.nonce).decode(), self.user_agent)
项目:MiNode    作者:TheKysek    | 项目源码 | 文件源码
def __repr__(self):
        return 'object, vector: {}'.format(base64.b16encode(self.vector).decode())
项目:clubsandwich    作者:irskep    | 项目源码 | 文件源码
def _bytes_to_int(bts):
    return int(base64.b16encode(bts), 16)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_b16encode(self):
        eq = self.assertEqual
        eq(base64.b16encode(b'\x01\x02\xab\xcd\xef'), b'0102ABCDEF')
        eq(base64.b16encode(b'\x00'), b'00')
        # Non-bytes
        eq(base64.b16encode(bytearray(b'\x01\x02\xab\xcd\xef')), b'0102ABCDEF')
        self.assertRaises(TypeError, base64.b16encode, "")
项目:SRL-Python    作者:SimpleRegex    | 项目源码 | 文件源码
def signature(self):
        try:
            from hashlib import md5
        except ImportError:
            from md5 import md5
        try:
            sig = md5()
            if self.start:
                sig.update(self.start.encode('latin-1'))
            if self.prec:
                sig.update(''.join([''.join(p) for p in self.prec]).encode('latin-1'))
            if self.tokens:
                sig.update(' '.join(self.tokens).encode('latin-1'))
            for f in self.pfuncs:
                if f[3]:
                    sig.update(f[3].encode('latin-1'))
        except (TypeError, ValueError):
            pass

        digest = base64.b16encode(sig.digest())
        if sys.version_info[0] >= 3:
            digest = digest.decode('latin-1')
        return digest

    # -----------------------------------------------------------------------------
    # validate_modules()
    #
    # This method checks to see if there are duplicated p_rulename() functions
    # in the parser module file.  Without this function, it is really easy for
    # users to make mistakes by cutting and pasting code fragments (and it's a real
    # bugger to try and figure out why the resulting parser doesn't work).  Therefore,
    # we just do a little regular expression pattern matching of def statements
    # to try and detect duplicates.
    # -----------------------------------------------------------------------------
项目:SpaghettIDE    作者:Bleu-royal    | 项目源码 | 文件源码
def signature(self):
        try:
            from hashlib import md5
        except ImportError:
            from md5 import md5
        try:
            sig = md5()
            if self.start:
                sig.update(self.start.encode('latin-1'))
            if self.prec:
                sig.update(''.join([''.join(p) for p in self.prec]).encode('latin-1'))
            if self.tokens:
                sig.update(' '.join(self.tokens).encode('latin-1'))
            for f in self.pfuncs:
                if f[3]:
                    sig.update(f[3].encode('latin-1'))
        except (TypeError, ValueError):
            pass

        digest = base64.b16encode(sig.digest())
        if sys.version_info[0] >= 3:
            digest = digest.decode('latin-1')
        return digest

    # -----------------------------------------------------------------------------
    # validate_modules()
    #
    # This method checks to see if there are duplicated p_rulename() functions
    # in the parser module file.  Without this function, it is really easy for
    # users to make mistakes by cutting and pasting code fragments (and it's a real
    # bugger to try and figure out why the resulting parser doesn't work).  Therefore,
    # we just do a little regular expression pattern matching of def statements
    # to try and detect duplicates.
    # -----------------------------------------------------------------------------
项目:securethenews    作者:freedomofpress    | 项目源码 | 文件源码
def generate_confirmation_nonce():
    # Use Base-16 to avoid potential URL encoding issues
    return b16encode(urandom(32))
项目:PyRai    作者:icarusglider    | 项目源码 | 文件源码
def to_ascii(s_bytes, prefix="", encoding="base64"):
    """Return a version-prefixed ASCII representation of the given binary
    string. 'encoding' indicates how to do the encoding, and can be one of:
     * base64
     * base32
     * base16 (or hex)

    This function handles bytes, not bits, so it does not append any trailing
    '=' (unlike standard base64.b64encode). It also lowercases the base32
    output.

    'prefix' will be prepended to the encoded form, and is useful for
    distinguishing the purpose and version of the binary string. E.g. you
    could prepend 'pub0-' to a VerifyingKey string to allow the receiving
    code to raise a useful error if someone pasted in a signature string by
    mistake.
    """
    assert isinstance(s_bytes, bytes)
    if not isinstance(prefix, bytes):
        prefix = prefix.encode('ascii')
    if encoding == "base64":
        s_ascii = base64.b64encode(s_bytes).decode('ascii').rstrip("=")
    elif encoding == "base32":
        s_ascii = base64.b32encode(s_bytes).decode('ascii').rstrip("=").lower()
    elif encoding in ("base16", "hex"):
        s_ascii = base64.b16encode(s_bytes).decode('ascii').lower()
    else:
        raise NotImplementedError
    return prefix+s_ascii.encode('ascii')
项目:openarc    作者:kchoudhu    | 项目源码 | 文件源码
def __init__(self, zmqtype, oag):
        self.zmqtype  = zmqtype
        self._ctx     = zmq.Context()
        self._ctxsoc  = self._ctx.socket(zmqtype)
        self._oag     = oag
        self._hash    = base64.b16encode(os.urandom(5))
项目:SublimeAnarchy    作者:AnarchyTools    | 项目源码 | 文件源码
def signature(self):
        try:
            from hashlib import md5
        except ImportError:
            from md5 import md5
        try:
            sig = md5()
            if self.start:
                sig.update(self.start.encode('latin-1'))
            if self.prec:
                sig.update(''.join([''.join(p) for p in self.prec]).encode('latin-1'))
            if self.tokens:
                sig.update(' '.join(self.tokens).encode('latin-1'))
            for f in self.pfuncs:
                if f[3]:
                    sig.update(f[3].encode('latin-1'))
        except (TypeError, ValueError):
            pass

        digest = base64.b16encode(sig.digest())
        if sys.version_info[0] >= 3:
            digest = digest.decode('latin-1')
        return digest

    # -----------------------------------------------------------------------------
    # validate_modules()
    #
    # This method checks to see if there are duplicated p_rulename() functions
    # in the parser module file.  Without this function, it is really easy for
    # users to make mistakes by cutting and pasting code fragments (and it's a real
    # bugger to try and figure out why the resulting parser doesn't work).  Therefore,
    # we just do a little regular expression pattern matching of def statements
    # to try and detect duplicates.
    # -----------------------------------------------------------------------------
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(photo = None, site = wikipedia.getSite(u'commons', u'commons')):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    hashObject = hashlib.sha1()
    hashObject.update(photo.getvalue())
    return site.getFilesFromAnHash(base64.b16encode(hashObject.digest()))
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(photo = None, site = wikipedia.getSite(u'commons', u'commons')):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    hashObject = hashlib.sha1()
    hashObject.update(photo.getvalue())
    return site.getFilesFromAnHash(base64.b16encode(hashObject.digest()))
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(filename, site = wikipedia.getSite(u'commons', u'commons')):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    f = open(filename, 'rb')

    hashObject = hashlib.sha1()
    hashObject.update(f.read(-1))
    return site.getFilesFromAnHash(base64.b16encode(hashObject.digest()))
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(photo = None, site = wikipedia.getSite(u'commons', u'commons')):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    hashObject = hashlib.sha1()
    hashObject.update(photo.getvalue())
    return site.getFilesFromAnHash(base64.b16encode(hashObject.digest()))
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(photo = None, site = wikipedia.getSite(u'commons', u'commons')):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    hashObject = hashlib.sha1()
    hashObject.update(photo.getvalue())
    return site.getFilesFromAnHash(base64.b16encode(hashObject.digest()))
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(photo = None, site = wikipedia.getSite(u'commons', u'commons')):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    hashObject = hashlib.sha1()
    hashObject.update(photo.getvalue())
    return site.getFilesFromAnHash(base64.b16encode(hashObject.digest()))
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(photo = None, site = wikipedia.getSite(u'commons', u'commons')):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    hashObject = hashlib.sha1()
    hashObject.update(photo.getvalue())
    return site.getFilesFromAnHash(base64.b16encode(hashObject.digest()))
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(photo = None, site = wikipedia.getSite(u'commons', u'commons')):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    hashObject = hashlib.sha1()
    hashObject.update(photo.getvalue())
    return site.getFilesFromAnHash(base64.b16encode(hashObject.digest()))
项目:toollabs    作者:multichill    | 项目源码 | 文件源码
def findDuplicateImages(self):
        """
        Find duplicates of the photo.

        Calculates the SHA1 hash and asks the MediaWiki api
        for a list of duplicates.

        TODO: Add exception handling, fix site thing
        """
        hashObject = hashlib.sha1()
        hashObject.update(self.downloadPhoto().getvalue())
        return list(
            page.title(withNamespace=False) for page in
            self.site.allimages(sha1=base64.b16encode(hashObject.digest())))