def feed(self, string): try: HTMLParser.feed(self, string) except Exception as e: # pragma: no cover import traceback traceback.print_exc() self.out.write(string)
def feed(self, data): data = re.compile(r'<!((?!DOCTYPE|--|\[))', re.IGNORECASE).sub(r'<!\1', data) data = re.sub(r'<([^<>\s]+?)\s*/>', self._shorttag_replace, data) data = data.replace(''', "'") data = data.replace('"', '"') HTMLParser.feed(self, data) HTMLParser.close(self)
def cmd_genpot(config, options): """Generate the gettext pot file""" os.chdir(config.source_dir) po_path = os.path.join(config.source_dir, 'po') if not os.path.isdir(po_path): os.mkdir(po_path) python_files = [] for root, dirs_dummy, files in os.walk(config.source_dir): for file_name in files: if file_name.endswith('.py'): file_path = os.path.relpath(os.path.join(root, file_name), config.source_dir) python_files.append(file_path) python_files.sort() # First write out a stub .pot file containing just the translated # activity name, then have xgettext merge the rest of the # translations into that. (We can't just append the activity name # to the end of the .pot file afterwards, because that might # create a duplicate msgid.) pot_file = os.path.join('po', '%s.pot' % config.bundle_name) escaped_name = _po_escape(config.activity_name) f = open(pot_file, 'w') f.write('#: activity/activity.info:2\n') f.write('msgid "%s"\n' % escaped_name) f.write('msgstr ""\n') if config.summary is not None: escaped_summary = _po_escape(config.summary) f.write('#: activity/activity.info:3\n') f.write('msgid "%s"\n' % escaped_summary) f.write('msgstr ""\n') if config.description is not None: parser = HTMLParser() strings = [] parser.handle_data = strings.append parser.feed(config.description) for s in strings: s = s.strip() if s: f.write('#: activity/activity.info:4\n') f.write('msgid "%s"\n' % _po_escape(s)) f.write('msgstr ""\n') f.close() args = [ 'xgettext', '--join-existing', '--language=Python', '--keyword=_', '--add-comments=TRANS:', '--output=%s' % pot_file ] args += python_files retcode = subprocess.call(args) if retcode: print('ERROR - xgettext failed with return code %i.' % retcode)
def feed(self, *args, **kwargs): try: # With Python 2, super() cannot be used. # See the comment for __init__(). HTMLParser.feed(self, *args, **kwargs) except self.TruncationCompleted as exc: self.truncate_at = exc.truncate_at else: self.truncate_at = None
def cmd_genpot(config, options): """Generate the gettext pot file""" os.chdir(config.source_dir) po_path = os.path.join(config.source_dir, 'po') if not os.path.isdir(po_path): os.mkdir(po_path) python_files = [] for root, dirs_dummy, files in os.walk(config.source_dir): for file_name in files: if file_name.endswith('.py'): file_path = os.path.relpath(os.path.join(root, file_name), config.source_dir) python_files.append(file_path) python_files.sort() # First write out a stub .pot file containing just the translated # activity name, then have xgettext merge the rest of the # translations into that. (We can't just append the activity name # to the end of the .pot file afterwards, because that might # create a duplicate msgid.) pot_file = os.path.join('po', '%s.pot' % config.bundle_name) escaped_name = _po_escape(config.activity_name) f = open(pot_file, 'w') f.write('#: activity/activity.info:2\n') f.write('msgid "%s"\n' % escaped_name) f.write('msgstr ""\n') if config.summary is not None: escaped_summary = _po_escape(config.summary) f.write('#: activity/activity.info:3\n') f.write('msgid "%s"\n' % escaped_summary) f.write('msgstr ""\n') if config.description is not None: parser = HTMLParser() strings = [] parser.handle_data = strings.append parser.feed(config.description) for s in strings: s = s.strip() if s: f.write('#: activity/activity.info:4\n') f.write('msgid "%s"\n' % _po_escape(s)) f.write('msgstr ""\n') f.close() args = ['xgettext', '--join-existing', '--language=Python', '--keyword=_', '--add-comments=TRANS:', '--output=%s' % pot_file] args += python_files retcode = subprocess.call(args) if retcode: print('ERROR - xgettext failed with return code %i.' % retcode)
def feed(self, data): """ This is the entry point of the class. Args: data (str): stringify xml """ HTMLParser.feed(self, data) return self.root
def feed(self, string): try: HTMLParser.feed(self, string) except Exception: # pragma: no cover # only raised in 2.6 self.out.write(string)