home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1088 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.7 KB  |  57 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5.  
  6. class CheckEncoding:
  7.     
  8.     def __init__(self, bug_handler):
  9.         self._CheckEncoding__bug_handler = bug_handler
  10.  
  11.     
  12.     def __get_position_error(self, line, encoding, line_num):
  13.         char_position = 0
  14.         for char in line:
  15.             char_position += 1
  16.             
  17.             try:
  18.                 char.decode(encoding)
  19.             continue
  20.             except UnicodeError:
  21.                 msg = None
  22.                 sys.stderr.write('line: %s char: %s\n' % (line_num, char_position))
  23.                 sys.stderr.write(str(msg) + '\n')
  24.                 continue
  25.             
  26.  
  27.         
  28.  
  29.     
  30.     def check_encoding(self, path, encoding = 'us-ascii'):
  31.         read_obj = open(path, 'r')
  32.         line_to_read = 1
  33.         line_num = 0
  34.         while line_to_read:
  35.             line_num += 1
  36.             line_to_read = read_obj.readline()
  37.             line = line_to_read
  38.             
  39.             try:
  40.                 line.decode(encoding)
  41.             continue
  42.             except UnicodeError:
  43.                 if len(line) < 1000:
  44.                     self._CheckEncoding__get_position_error(line, encoding, line_num)
  45.                 else:
  46.                     sys.stderr.write('line: %d has bad encoding\n' % line_num)
  47.                 len(line) < 1000
  48.             
  49.  
  50.             None<EXCEPTION MATCH>UnicodeError
  51.  
  52.  
  53. if __name__ == '__main__':
  54.     check_encoding_obj = CheckEncoding()
  55.     check_encoding_obj.check_encoding(sys.argv[1])
  56.  
  57.