当前位置: 首页>>代码示例>>Python>>正文


Python Mnemonic.list_languages方法代码示例

本文整理汇总了Python中mnemonic.Mnemonic.list_languages方法的典型用法代码示例。如果您正苦于以下问题:Python Mnemonic.list_languages方法的具体用法?Python Mnemonic.list_languages怎么用?Python Mnemonic.list_languages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mnemonic.Mnemonic的用法示例。


在下文中一共展示了Mnemonic.list_languages方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_similarity

# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import list_languages [as 别名]
    def test_similarity(self):
        similar = (
            ('a', 'c'), ('a', 'e'), ('a', 'o'),
            ('b', 'd'), ('b', 'h'), ('b', 'p'), ('b', 'q'), ('b', 'r'),
            ('c', 'e'), ('c', 'g'), ('c', 'n'), ('c', 'o'), ('c', 'q'), ('c', 'u'),
            ('d', 'g'), ('d', 'h'), ('d', 'o'), ('d', 'p'), ('d', 'q'),
            ('e', 'f'), ('e', 'o'),
            ('f', 'i'), ('f', 'j'), ('f', 'l'), ('f', 'p'), ('f', 't'),
            ('g', 'j'), ('g', 'o'), ('g', 'p'), ('g', 'q'), ('g', 'y'),
            ('h', 'k'), ('h', 'l'), ('h', 'm'), ('h', 'n'), ('h', 'r'),
            ('i', 'j'), ('i', 'l'), ('i', 't'), ('i', 'y'),
            ('j', 'l'), ('j', 'p'), ('j', 'q'), ('j', 'y'),
            ('k', 'x'),
            ('l', 't'),
            ('m', 'n'), ('m', 'w'),
            ('n', 'u'), ('n', 'z'),
            ('o', 'p'), ('o', 'q'), ('o', 'u'), ('o', 'v'),
            ('p', 'q'), ('p', 'r'),
            ('q', 'y'),
            ('s', 'z'),
            ('u', 'v'), ('u', 'w'), ('u', 'y'),
            ('v', 'w'), ('v', 'y')
        )

        languages = Mnemonic.list_languages()

        fail = False
        for lang in languages:
            mnemo = Mnemonic(lang)

            for w1 in mnemo.wordlist:
                for w2 in mnemo.wordlist:
                    if len(w1) != len(w2):
                        continue

                    if w1 == w2:
                        continue

                    if w1 > w2:
                        # No need to print warning twice
                        continue

                    diff = []
                    for i in range(len(w1)):
                        if w1[i] != w2[i]:
                            if w1[i] < w2[i]:
                                pair = (w1[i], w2[i])
                            else:
                                pair = (w2[i], w1[i])

                            diff.append(pair)
                            # pairs.update((pair,))

                    if len(diff) == 1:
                        if list(diff)[0] in similar:
                            fail = True
                            print("Similar words (%s): %s, %s" % (lang, w1, w2))

        if fail:
            self.assert_(False, "Similar words found")
开发者ID:STRML,项目名称:python-mnemonic,代码行数:62,代码来源:test_mnemonic.py

示例2: test_lengths

# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import list_languages [as 别名]
 def test_lengths(self):
     # check if wordlists contain words between 3 and 8 characters
     languages = Mnemonic.list_languages()
     for lang in languages:
         mnemo = Mnemonic(lang)
         words = [w for w in mnemo.wordlist if len(w) < 3 or len(w) > 8]
         print("Language '{}'".format(lang))
         self.assertListEqual(words, [])
开发者ID:STRML,项目名称:python-mnemonic,代码行数:10,代码来源:test_mnemonic.py

示例3: test_validchars

# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import list_languages [as 别名]
 def test_validchars(self):
     # check if wordlists contain valid characters
     languages = Mnemonic.list_languages()
     for lang in languages:
         mnemo = Mnemonic(lang)
         letters = set(sum([list(w) for w in mnemo.wordlist] ,[]))
         print("Language '{}'".format(lang))
         for l in letters:
             self.assertIn(l, 'abcdefghijklmnopqrstuvwxyz')
开发者ID:STRML,项目名称:python-mnemonic,代码行数:11,代码来源:test_mnemonic.py

示例4: test_collision

# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import list_languages [as 别名]
    def test_collision(self):
        # Check for the same words across wordlists.
        # This is prohibited because of auto-detection feature of language.

        words = []
        languages = Mnemonic.list_languages()
        for lang in languages:
            mnemo = Mnemonic(lang)
            words += mnemo.wordlist

        words_unique = list(set(words[:]))
        self.assertEqual(len(words), len(words_unique))
开发者ID:ghtdak,项目名称:python-mnemonic,代码行数:14,代码来源:test_mnemonic.py

示例5: test_sorted_unique

# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import list_languages [as 别名]
    def test_sorted_unique(self):
        # Check for duplicated words in wordlist

        print "------------------------------------"
        print "Test of sorted and unique wordlists:"

        languages = Mnemonic.list_languages()
        for lang in languages:
            mnemo = Mnemonic(lang)
            unique = list(set(mnemo.wordlist))
            unique.sort()

            print "Language '%s'" % lang
            self.assertListEqual(unique, mnemo.wordlist)
开发者ID:MatthewLM,项目名称:python-mnemonic,代码行数:16,代码来源:test.py

示例6: test_sorted_unique

# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import list_languages [as 别名]
    def test_sorted_unique(self):
        # Check for duplicated words in wordlist

        print("------------------------------------")
        print("Test of sorted and unique wordlists:")

        languages = Mnemonic.list_languages()
        languages.remove('japanese')  # remove japanese for now
        for lang in languages:
            mnemo = Mnemonic(lang)
            unique = list(set(mnemo.wordlist))
            unique.sort()

            print("Language '{}'".format(lang))
            self.assertListEqual(unique, mnemo.wordlist)
开发者ID:ghtdak,项目名称:python-mnemonic,代码行数:17,代码来源:test_mnemonic.py

示例7: test_root_len

# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import list_languages [as 别名]
    def test_root_len(self):
        print "------------------------------------"
        print "Test of word prefixes:"

        languages = Mnemonic.list_languages()
        problems_found = 0

        for lang in languages:
            mnemo = Mnemonic(lang)
            prefixes = []
            for w in mnemo.wordlist:
                pref = w[:5]
                if pref in prefixes:
                    words = [ w2 for w2 in mnemo.wordlist if w2[:5] == pref ]
                    print "Duplicate prefix", pref, "for words", words
                    problems_found += 1

                prefixes.append(pref)

        self.assertEqual(problems_found, 0)
开发者ID:MatthewLM,项目名称:python-mnemonic,代码行数:22,代码来源:test.py

示例8: test_root_len

# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import list_languages [as 别名]
    def test_root_len(self):
        print("------------------------------------")
        print("Test of word prefixes:")

        languages = Mnemonic.list_languages()
        languages.remove('japanese')  # remove japanese for now
        problems_found = 0

        for lang in languages:
            mnemo = Mnemonic(lang)
            prefixes = []
            for w in mnemo.wordlist:
                pref = w[:4]
                if pref in prefixes:
                    words = [w2 for w2 in mnemo.wordlist if w2[:4] == pref]
                    print("Duplicate prefix", pref, "for words", words)
                    problems_found += 1

                prefixes.append(pref)

        self.assertEqual(problems_found, 0)
开发者ID:ghtdak,项目名称:python-mnemonic,代码行数:23,代码来源:test_mnemonic.py

示例9: hexlify

# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import list_languages [as 别名]
    h = hexlify(b)
    return h if sys.version < '3' else h.decode('utf8')

def process(data, lst):
    code = mnemo.to_mnemonic(unhexlify(data))
    seed = b2h(Mnemonic.to_seed(code, passphrase = 'TREZOR'))
    print('input    : %s (%d bits)' % (data, len(data) * 4))
    print('mnemonic : %s (%d words)' % (code, len(code.split(' '))))
    print('seed     : %s (%d bits)' % (seed, len(seed) * 4))
    print()
    lst.append((data, code, seed))

if __name__ == '__main__':
    out = {}

    for lang in Mnemonic.list_languages():
        mnemo = Mnemonic(lang)
        out[lang] = []

        # Generate corner cases
        data = []
        for l in range(16, 32 + 1, 8):
            for b in ['00', '7f', '80', 'ff']:
                process(b * l, out[lang])

        # Generate random seeds
        for i in range(12):
            data = ''.join(chr(choice(range(0, 256))) for _ in range(8 * (i % 3 + 2)))
            if sys.version >= '3':
                data = data.encode('latin1')
            process(b2h(data), out[lang])
开发者ID:STRML,项目名称:python-mnemonic,代码行数:33,代码来源:generate_vectors.py


注:本文中的mnemonic.Mnemonic.list_languages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。