home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import os
- import tempfile
- import re
- from calibre.ebooks.rtf2xml import copy
-
- class FixLineEndings:
-
- def __init__(self, bug_handler, in_file = None, copy = None, run_level = 1, replace_illegals = 1):
- self._FixLineEndings__file = in_file
- self._FixLineEndings__bug_handler = bug_handler
- self._FixLineEndings__copy = copy
- self._FixLineEndings__run_level = run_level
- self._FixLineEndings__write_to = tempfile.mktemp()
- self._FixLineEndings__replace_illegals = replace_illegals
-
-
- def fix_endings(self):
- illegal_regx = re.compile('\x00|\x01|\x02|\x03|\x04|\x05|\x06|\x07|\x08|\x0b|\x0e|\x0f|\x10|\x11|\x12|\x13')
- macintosh = 1
- if macintosh:
- line = 1
- read_obj = open(self._FixLineEndings__file, 'r')
- write_obj = open(self._FixLineEndings__write_to, 'w')
- while line:
- line = read_obj.read(1000)
- line = line.replace('\r', '\n')
- if self._FixLineEndings__replace_illegals:
- line = re.sub(illegal_regx, '', line)
-
- write_obj.write(line)
- read_obj.close()
- write_obj.close()
- copy_obj = copy.Copy(bug_handler = self._FixLineEndings__bug_handler)
- if self._FixLineEndings__copy:
- copy_obj.copy_file(self._FixLineEndings__write_to, 'line_endings.data')
-
- copy_obj.rename(self._FixLineEndings__write_to, self._FixLineEndings__file)
- os.remove(self._FixLineEndings__write_to)
-
-
-
-