當前位置: 首頁>>代碼示例>>Python>>正文


Python _md5.new方法代碼示例

本文整理匯總了Python中_md5.new方法的典型用法代碼示例。如果您正苦於以下問題:Python _md5.new方法的具體用法?Python _md5.new怎麽用?Python _md5.new使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在_md5的用法示例。


在下文中一共展示了_md5.new方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_large_update

# 需要導入模塊: import _md5 [as 別名]
# 或者: from _md5 import new [as 別名]
def test_large_update(self):
        aas = 'a' * 128
        bees = 'b' * 127
        cees = 'c' * 126
        abcs = aas + bees + cees

        for name in self.supported_hash_names:
            m1 = hashlib.new(name)
            m1.update(aas)
            m1.update(bees)
            m1.update(cees)

            m2 = hashlib.new(name)
            m2.update(abcs)
            self.assertEqual(m1.digest(), m2.digest(), name+' update problem.')

            m3 = hashlib.new(name, abcs)
            self.assertEqual(m1.digest(), m3.digest(), name+' new problem.') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_hashlib.py

示例2: __get_builtin_constructor

# 需要導入模塊: import _md5 [as 別名]
# 或者: from _md5 import new [as 別名]
def __get_builtin_constructor(name):
    if name in ('SHA1', 'sha1'):
        import _sha
        return _sha.new
    elif name in ('MD5', 'md5'):
        import _md5
        return _md5.new
    elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
        import _sha256
        bs = name[3:]
        if bs == '256':
            return _sha256.sha256
        elif bs == '224':
            return _sha256.sha224
    elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
        import _sha512
        bs = name[3:]
        if bs == '512':
            return _sha512.sha512
        elif bs == '384':
            return _sha512.sha384

    raise ValueError('unsupported hash type %s' % name) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:25,代碼來源:hashlib.py

示例3: __get_builtin_constructor

# 需要導入模塊: import _md5 [as 別名]
# 或者: from _md5 import new [as 別名]
def __get_builtin_constructor(name):
    if name in ('SHA1', 'sha1'):
        import _sha
        return _sha.new
    elif name in ('MD5', 'md5'):
        import _md5
        return _md5.new
    elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
        import _sha256
        bs = name[3:]
        if bs == '256':
            return _sha256.sha256
        elif bs == '224':
            return _sha256.sha224
    elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
        import _sha512
        bs = name[3:]
        if bs == '512':
            return _sha512.sha512
        elif bs == '384':
            return _sha512.sha384

    raise ValueError, "unsupported hash type" 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:25,代碼來源:hashlib.py

示例4: __get_builtin_constructor

# 需要導入模塊: import _md5 [as 別名]
# 或者: from _md5 import new [as 別名]
def __get_builtin_constructor(name):
    try:
        if name in ('SHA1', 'sha1'):
            import _sha
            return _sha.new
        elif name in ('MD5', 'md5'):
            import _md5
            return _md5.new
        elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
            import _sha256
            bs = name[3:]
            if bs == '256':
                return _sha256.sha256
            elif bs == '224':
                return _sha256.sha224
        elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
            import _sha512
            bs = name[3:]
            if bs == '512':
                return _sha512.sha512
            elif bs == '384':
                return _sha512.sha384
    except ImportError:
        pass  # no extension module, this hash is unsupported.

    raise ValueError('unsupported hash type %s' % name) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:28,代碼來源:hashlib.py

示例5: __py_new

# 需要導入模塊: import _md5 [as 別名]
# 或者: from _md5 import new [as 別名]
def __py_new(name, string=''):
    """new(name, string='') - Return a new hashing object using the named algorithm;
    optionally initialized with a string.
    """
    return __get_builtin_constructor(name)(string) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:7,代碼來源:hashlib.py

示例6: __hash_new

# 需要導入模塊: import _md5 [as 別名]
# 或者: from _md5 import new [as 別名]
def __hash_new(name, string=''):
    """new(name, string='') - Return a new hashing object using the named algorithm;
    optionally initialized with a string.
    """
    try:
        return _hashlib.new(name, string)
    except ValueError:
        # If the _hashlib module (OpenSSL) doesn't support the named
        # hash, try using our builtin implementations.
        # This allows for SHA224/256 and SHA384/512 support even though
        # the OpenSSL library prior to 0.9.8 doesn't provide them.
        return __get_builtin_constructor(name)(string) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:14,代碼來源:hashlib.py

示例7: __get_builtin_constructor

# 需要導入模塊: import _md5 [as 別名]
# 或者: from _md5 import new [as 別名]
def __get_builtin_constructor(name):
    try:
        if name in ('SHA1', 'sha1'):
            import _sha
            return _sha.new
        elif name in ('MD5', 'md5'):
            import _md5
            return _md5.new
        elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
            import _sha256
            bs = name[3:]
            if bs == '256':
                return _sha256.sha256
            elif bs == '224':
                return _sha256.sha224
        elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
            import _sha512
            bs = name[3:]
            if bs == '512':
                return _sha512.sha512
            elif bs == '384':
                return _sha512.sha384
    except ImportError:
        pass  # no extension module, this hash is unsupported.

    raise ValueError('unsupported hash type ' + name) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:28,代碼來源:hashlib.py

示例8: test_hexdigest

# 需要導入模塊: import _md5 [as 別名]
# 或者: from _md5 import new [as 別名]
def test_hexdigest(self):
        for name in self.supported_hash_names:
            h = hashlib.new(name)
            self.assertTrue(hexstr(h.digest()) == h.hexdigest()) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_hashlib.py

示例9: check

# 需要導入模塊: import _md5 [as 別名]
# 或者: from _md5 import new [as 別名]
def check(self, name, data, digest):
        constructors = self.constructors_to_test[name]
        # 2 is for hashlib.name(...) and hashlib.new(name, ...)
        self.assertGreaterEqual(len(constructors), 2)
        for hash_object_constructor in constructors:
            computed = hash_object_constructor(data).hexdigest()
            self.assertEqual(
                    computed, digest,
                    "Hash algorithm %s constructed using %s returned hexdigest"
                    " %r for %d byte input data that should have hashed to %r."
                    % (name, hash_object_constructor,
                       computed, len(data), digest)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:test_hashlib.py

示例10: check_update

# 需要導入模塊: import _md5 [as 別名]
# 或者: from _md5 import new [as 別名]
def check_update(self, name, data, digest):
        constructors = self.constructors_to_test[name]
        # 2 is for hashlib.name(...) and hashlib.new(name, ...)
        self.assertGreaterEqual(len(constructors), 2)
        for hash_object_constructor in constructors:
            h = hash_object_constructor()
            h.update(data)
            computed = h.hexdigest()
            self.assertEqual(
                    computed, digest,
                    "Hash algorithm %s using %s when updated returned hexdigest"
                    " %r for %d byte input data that should have hashed to %r."
                    % (name, hash_object_constructor,
                       computed, len(data), digest)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:16,代碼來源:test_hashlib.py

示例11: check_unicode

# 需要導入模塊: import _md5 [as 別名]
# 或者: from _md5 import new [as 別名]
def check_unicode(self, algorithm_name):
        # Unicode objects are not allowed as input.
        expected = hashlib.new(algorithm_name, str(u'spam')).hexdigest()
        self.check(algorithm_name, u'spam', expected) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_hashlib.py

示例12: test_bytes_hashing

# 需要導入模塊: import _md5 [as 別名]
# 或者: from _md5 import new [as 別名]
def test_bytes_hashing(self):
        """test interaction of bytes w/ hashing modules"""
        import _sha, _sha256, _sha512, _md5
        
        for hashLib in (_sha.new, _sha256.sha256, _sha512.sha512, _sha512.sha384, _md5.new):
            x = hashLib(b'abc')
            x.update(b'abc')
            
            #For now just make sure this doesn't throw
            temp = hashLib(bytearray(b'abc'))
            x.update(bytearray(b'abc')) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_bytes.py

示例13: test_unknown_hash

# 需要導入模塊: import _md5 [as 別名]
# 或者: from _md5 import new [as 別名]
def test_unknown_hash(self):
        self.assertRaises(ValueError, hashlib.new, 'spam spam spam spam spam')
        self.assertRaises(TypeError, hashlib.new, 1) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:5,代碼來源:test_hashlib.py


注:本文中的_md5.new方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。