home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import sys
- import os
- import tempfile
- from calibre.ebooks.rtf2xml import copy
-
- class Info:
-
- def __init__(self, in_file, bug_handler, copy = None, run_level = 1):
- self._Info__file = in_file
- self._Info__bug_handler = bug_handler
- self._Info__copy = copy
- self._Info__run_level = run_level
- self._Info__write_to = tempfile.mktemp()
-
-
- def __initiate_values(self):
- self._Info__text_string = ''
- self._Info__state = 'before_info_table'
- self._Info__state_dict = {
- 'before_info_table': self._Info__before_info_table_func,
- 'after_info_table': self._Info__after_info_table_func,
- 'in_info_table': self._Info__in_info_table_func,
- 'collect_text': self._Info__collect_text_func,
- 'collect_tokens': self._Info__collect_tokens_func }
- self._Info__info_table_dict = {
- 'cw<di<title_____': (self._Info__found_tag_with_text_func, 'title'),
- 'cw<di<author____': (self._Info__found_tag_with_text_func, 'author'),
- 'cw<di<keywords__': (self._Info__found_tag_with_text_func, 'keywords'),
- 'cw<di<doc-notes_': (self._Info__found_tag_with_text_func, 'doc-notes'),
- 'cw<di<subject___': (self._Info__found_tag_with_text_func, 'subject'),
- 'cw<di<operator__': (self._Info__found_tag_with_text_func, 'operator'),
- 'cw<di<create-tim': (self._Info__found_tag_with_tokens_func, 'creation-time'),
- 'cw<di<revis-time': (self._Info__found_tag_with_tokens_func, 'revision-time'),
- 'cw<di<edit-time_': (self._Info__single_field_func, 'editing-time'),
- 'cw<di<num-of-wor': (self._Info__single_field_func, 'number-of-words'),
- 'cw<di<num-of-chr': (self._Info__single_field_func, 'number-of-characters'),
- 'cw<di<num-of-pag': (self._Info__single_field_func, 'number-of-pages') }
- self._Info__token_dict = {
- 'year______': 'year',
- 'month_____': 'month',
- 'day_______': 'day',
- 'minute____': 'minute',
- 'revis-time': 'revision-time',
- 'num-of-wor': 'number-of-words',
- 'num-of-chr': 'number-of-characters',
- 'num-of-pag': 'number-of-pages' }
-
-
- def __before_info_table_func(self, line):
- if self._Info__token_info == 'mi<mk<doc-in-beg':
- self._Info__state = 'in_info_table'
-
- self._Info__write_obj.write(line)
-
-
- def __in_info_table_func(self, line):
- if self._Info__token_info == 'mi<mk<doc-in-end':
- self._Info__state = 'after_info_table'
- else:
- (action, tag) = self._Info__info_table_dict.get(self._Info__token_info, (None, None))
- if action:
- action(line, tag)
- else:
- self._Info__write_obj.write(line)
-
-
- def __found_tag_with_text_func(self, line, tag):
- self._Info__tag = tag
- self._Info__state = 'collect_text'
-
-
- def __collect_text_func(self, line):
- if self._Info__token_info == 'mi<mk<docinf-end':
- self._Info__state = 'in_info_table'
- self._Info__write_obj.write('mi<tg<open______<%s\ntx<nu<__________<%s\nmi<tg<close_____<%s\n' % (self._Info__tag, self._Info__text_string, self._Info__tag))
- self._Info__text_string = ''
- elif line[0:2] == 'tx':
- self._Info__text_string += line[17:-1]
-
-
-
- def __found_tag_with_tokens_func(self, line, tag):
- self._Info__state = 'collect_tokens'
- self._Info__text_string = 'mi<tg<empty-att_<%s' % tag
-
-
- def __collect_tokens_func(self, line):
- pass
-
-
- def __single_field_func(self, line, tag):
- value = line[20:-1]
- self._Info__write_obj.write('mi<tg<empty-att_<%s<%s>%s\n' % (tag, tag, value))
-
-
- def __after_info_table_func(self, line):
- self._Info__write_obj.write(line)
-
-
- def fix_info(self):
- self._Info__initiate_values()
- read_obj = open(self._Info__file, 'r')
- self._Info__write_obj = open(self._Info__write_to, 'w')
- line_to_read = 1
- while line_to_read:
- line_to_read = read_obj.readline()
- line = line_to_read
- self._Info__token_info = line[:16]
- action = self._Info__state_dict.get(self._Info__state)
- if action == None:
- sys.stderr.write('no no matching state in module styles.py\n')
- sys.stderr.write(self._Info__state + '\n')
-
- action(line)
- read_obj.close()
- self._Info__write_obj.close()
- copy_obj = copy.Copy(bug_handler = self._Info__bug_handler)
- if self._Info__copy:
- copy_obj.copy_file(self._Info__write_to, 'info.data')
-
- copy_obj.rename(self._Info__write_to, self._Info__file)
- os.remove(self._Info__write_to)
-
-
-