Back to index

python3.2  3.2.2
Functions
comparecodecs Namespace Reference

Functions

def compare_codecs

Function Documentation

def comparecodecs.compare_codecs (   encoding1,
  encoding2 
)

Definition at line 12 of file comparecodecs.py.

00012 
00013 def compare_codecs(encoding1, encoding2):
00014 
00015     print('Comparing encoding/decoding of   %r and   %r' % (encoding1, encoding2))
00016     mismatch = 0
00017     # Check encoding
00018     for i in range(sys.maxunicode):
00019         u = chr(i)
00020         try:
00021             c1 = u.encode(encoding1)
00022         except UnicodeError as reason:
00023             c1 = '<undefined>'
00024         try:
00025             c2 = u.encode(encoding2)
00026         except UnicodeError as reason:
00027             c2 = '<undefined>'
00028         if c1 != c2:
00029             print(' * encoding mismatch for 0x%04X: %-14r != %r' % \
00030                   (i, c1, c2))
00031             mismatch += 1
00032     # Check decoding
00033     for i in range(256):
00034         c = chr(i)
00035         try:
00036             u1 = c.decode(encoding1)
00037         except UnicodeError:
00038             u1 = '<undefined>'
00039         try:
00040             u2 = c.decode(encoding2)
00041         except UnicodeError:
00042             u2 = '<undefined>'
00043         if u1 != u2:
00044             print(' * decoding mismatch for 0x%04X: %-14r != %r' % \
00045                   (i, u1, u2))
00046             mismatch += 1
00047     if mismatch:
00048         print()
00049         print('Found %i mismatches' % mismatch)
00050     else:
00051         print('-> Codecs are identical.')

Here is the call graph for this function: