我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用unicodedata.unidata_version()。
def get_unicodedata(): """Download the unicodedata version for the given Python version.""" import unicodedata fail = False path = os.path.join(os.path.dirname(__file__), 'tools') fp, pathname, desc = imp.find_module('unidatadownload', [path]) try: unidatadownload = imp.load_module('unidatadownload', fp, pathname, desc) unidatadownload.get_unicodedata(unicodedata.unidata_version, no_zip=True) except Exception: print(traceback.format_exc()) fail = True finally: fp.close() assert not fail, "Failed to obtain unicodedata!"
def test_named_sequences_full(self): # Check all the named sequences url = ("http://www.unicode.org/Public/%s/ucd/NamedSequences.txt" % unicodedata.unidata_version) try: testdata = support.open_urlresource(url, encoding="utf-8", check=check_version) except (IOError, HTTPException): self.skipTest("Could not retrieve " + url) self.addCleanup(testdata.close) for line in testdata: line = line.strip() if not line or line.startswith('#'): continue seqname, codepoints = line.split(';') codepoints = ''.join(chr(int(cp, 16)) for cp in codepoints.split()) self.assertEqual(unicodedata.lookup(seqname), codepoints) with self.assertRaises(SyntaxError): self.checkletter(seqname, None) with self.assertRaises(KeyError): unicodedata.ucd_3_2_0.lookup(seqname)
def test_named_sequences_full(self): # Check all the named sequences url = ("http://www.pythontest.net/unicode/%s/NamedSequences.txt" % unicodedata.unidata_version) try: testdata = support.open_urlresource(url, encoding="utf-8", check=check_version) except (OSError, HTTPException): self.skipTest("Could not retrieve " + url) self.addCleanup(testdata.close) for line in testdata: line = line.strip() if not line or line.startswith('#'): continue seqname, codepoints = line.split(';') codepoints = ''.join(chr(int(cp, 16)) for cp in codepoints.split()) self.assertEqual(unicodedata.lookup(seqname), codepoints) with self.assertRaises(SyntaxError): self.checkletter(seqname, None) with self.assertRaises(KeyError): unicodedata.ucd_3_2_0.lookup(seqname)
def test_named_sequences_full(self): # Check all the named sequences url = ("http://www.unicode.org/Public/%s/ucd/NamedSequences.txt" % unicodedata.unidata_version) try: testdata = support.open_urlresource(url, encoding="utf-8", check=check_version) except (OSError, HTTPException): self.skipTest("Could not retrieve " + url) self.addCleanup(testdata.close) for line in testdata: line = line.strip() if not line or line.startswith('#'): continue seqname, codepoints = line.split(';') codepoints = ''.join(chr(int(cp, 16)) for cp in codepoints.split()) self.assertEqual(unicodedata.lookup(seqname), codepoints) with self.assertRaises(SyntaxError): self.checkletter(seqname, None) with self.assertRaises(KeyError): unicodedata.ucd_3_2_0.lookup(seqname)
def check_version(testfile): hdr = testfile.readline() return unidata_version in hdr