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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import tempfile
  6. import re
  7. from calibre.ebooks.rtf2xml import copy
  8.  
  9. class FixLineEndings:
  10.     
  11.     def __init__(self, bug_handler, in_file = None, copy = None, run_level = 1, replace_illegals = 1):
  12.         self._FixLineEndings__file = in_file
  13.         self._FixLineEndings__bug_handler = bug_handler
  14.         self._FixLineEndings__copy = copy
  15.         self._FixLineEndings__run_level = run_level
  16.         self._FixLineEndings__write_to = tempfile.mktemp()
  17.         self._FixLineEndings__replace_illegals = replace_illegals
  18.  
  19.     
  20.     def fix_endings(self):
  21.         illegal_regx = re.compile('\x00|\x01|\x02|\x03|\x04|\x05|\x06|\x07|\x08|\x0b|\x0e|\x0f|\x10|\x11|\x12|\x13')
  22.         macintosh = 1
  23.         if macintosh:
  24.             line = 1
  25.             read_obj = open(self._FixLineEndings__file, 'r')
  26.             write_obj = open(self._FixLineEndings__write_to, 'w')
  27.             while line:
  28.                 line = read_obj.read(1000)
  29.                 line = line.replace('\r', '\n')
  30.                 if self._FixLineEndings__replace_illegals:
  31.                     line = re.sub(illegal_regx, '', line)
  32.                 
  33.                 write_obj.write(line)
  34.             read_obj.close()
  35.             write_obj.close()
  36.             copy_obj = copy.Copy(bug_handler = self._FixLineEndings__bug_handler)
  37.             if self._FixLineEndings__copy:
  38.                 copy_obj.copy_file(self._FixLineEndings__write_to, 'line_endings.data')
  39.             
  40.             copy_obj.rename(self._FixLineEndings__write_to, self._FixLineEndings__file)
  41.             os.remove(self._FixLineEndings__write_to)
  42.         
  43.  
  44.  
  45.