home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import sys
- import os
- import codecs
-
- class Output:
-
- def __init__(self, file, orig_file, output_dir = None, out_file = None):
- self._Output__file = file
- self._Output__orig_file = orig_file
- self._Output__output_dir = output_dir
- self._Output__no_ask = 1
- self._Output__out_file = out_file
-
-
- def output(self):
- if self._Output__output_dir:
- self._Output__output_to_dir_func()
- elif self._Output__out_file:
- self._Output__output_xml(self._Output__file, self._Output__out_file)
- else:
- self._Output__output_to_standard_func()
-
-
- def __output_to_dir_func(self):
- base_name = os.path.basename(self._Output__orig_file)
- (base_name, ext) = os.path.splitext(base_name)
- output_file = '%s.xml' % base_name
- output_file = os.path.join(self._Output__output_dir, output_file)
- if self._Output__out_file:
- output_file = os.path.join(self._Output__output_dir, self._Output__out_file)
-
- user_response = 'o'
- if os.path.isfile(output_file):
- if self._Output__no_ask:
- user_response = 'o'
- else:
- msg = 'Do you want to over-write %s?\n' % output_file
- msg += 'Type "o" to over-write.\n'
- msg += 'Type any other key to print to standard output.\n'
- sys.stderr.write(msg)
- user_response = raw_input()
-
- if user_response == 'o':
- read_obj = open(self._Output__file, 'r')
- write_obj = open(output_file, 'w')
- line = 1
- while line:
- line = read_obj.readline()
- write_obj.write(line)
- read_obj.close()
- write_obj.close()
- else:
- self._Output__output_to_standard_func()
-
-
- def __output_to_file_func(self):
- read_obj = open(self._Output__file, 'r')
- write_obj = open(self._Output__out_file, 'w')
- line = 1
- while line:
- line = read_obj.readline()
- write_obj.write(line)
- read_obj.close()
- write_obj.close()
-
-
- def __output_to_standard_func(self):
- read_obj = open(self._Output__file, 'r')
- line = 1
- while line:
- line = read_obj.readline()
- sys.stdout.write(line)
- read_obj.close()
-
-
- def __output_xml(self, in_file, out_file):
- (utf8_encode, utf8_decode, utf8_reader, utf8_writer) = codecs.lookup('utf-8')
- write_obj = utf8_writer(open(out_file, 'w'))
- write_obj = open(out_file, 'w')
- read_obj = utf8_writer(open(in_file, 'r'))
- read_obj = open(in_file, 'r')
- line = 1
- while line:
- line = read_obj.readline()
- if isinstance(line, type(u'')):
- line = line.encode('utf-8')
-
- write_obj.write(line)
- read_obj.close()
- write_obj.close()
-
-
-