]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Tools/unicode/comparecodecs.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Tools / unicode / comparecodecs.py
CommitLineData
4710c53d 1#!/usr/bin/env python\r
2\r
3""" Compare the output of two codecs.\r
4\r
5(c) Copyright 2005, Marc-Andre Lemburg (mal@lemburg.com).\r
6\r
7 Licensed to PSF under a Contributor Agreement.\r
8\r
9"""\r
10import sys\r
11\r
12def compare_codecs(encoding1, encoding2):\r
13\r
14 print 'Comparing encoding/decoding of %r and %r' % (encoding1, encoding2)\r
15 mismatch = 0\r
16 # Check encoding\r
17 for i in range(sys.maxunicode):\r
18 u = unichr(i)\r
19 try:\r
20 c1 = u.encode(encoding1)\r
21 except UnicodeError, reason:\r
22 c1 = '<undefined>'\r
23 try:\r
24 c2 = u.encode(encoding2)\r
25 except UnicodeError, reason:\r
26 c2 = '<undefined>'\r
27 if c1 != c2:\r
28 print ' * encoding mismatch for 0x%04X: %-14r != %r' % \\r
29 (i, c1, c2)\r
30 mismatch += 1\r
31 # Check decoding\r
32 for i in range(256):\r
33 c = chr(i)\r
34 try:\r
35 u1 = c.decode(encoding1)\r
36 except UnicodeError:\r
37 u1 = u'<undefined>'\r
38 try:\r
39 u2 = c.decode(encoding2)\r
40 except UnicodeError:\r
41 u2 = u'<undefined>'\r
42 if u1 != u2:\r
43 print ' * decoding mismatch for 0x%04X: %-14r != %r' % \\r
44 (i, u1, u2)\r
45 mismatch += 1\r
46 if mismatch:\r
47 print\r
48 print 'Found %i mismatches' % mismatch\r
49 else:\r
50 print '-> Codecs are identical.'\r
51\r
52if __name__ == '__main__':\r
53 compare_codecs(sys.argv[1], sys.argv[2])\r