Esempio n. 1
0
 def __init__(self,
              xpatterns=None,
              prefixes=None,
              chunk_consumer=None,
              rules=None,
              ):
     bindery.binder.__init__(self, prefixes)
     #Add patterns form the push match specs
     if isinstance(xpatterns, str) or isinstance(xpatterns, unicode) :
         xpatterns = [xpatterns]
     self.xpatterns.extend(xpatterns)
     rules = rules or []
     for rule in rules:
         self.add_rule(rule)
     prefixes = prefixes or {}
     #print self.xpatterns
     self.state_machine = saxtools.xpattern_state_manager(self.xpatterns, prefixes)
     self._chunk_consumer = chunk_consumer
     return
Esempio n. 2
0
 def __init__(
     self,
     xpatterns=None,
     prefixes=None,
     chunk_consumer=None,
     rules=None,
 ):
     bindery.binder.__init__(self, prefixes)
     #Add patterns form the push match specs
     if isinstance(xpatterns, str) or isinstance(xpatterns, unicode):
         xpatterns = [xpatterns]
     self.xpatterns.extend(xpatterns)
     rules = rules or []
     for rule in rules:
         self.add_rule(rule)
     prefixes = prefixes or {}
     #print self.xpatterns
     self.state_machine = saxtools.xpattern_state_manager(
         self.xpatterns, prefixes)
     self._chunk_consumer = chunk_consumer
     return
Esempio n. 3
0
File: bindery.py Progetto: tvi/Harpy
 def read_xml(self, input_source):
     if self.xpatterns:
         self.state_machine = saxtools.xpattern_state_manager(
             self.xpatterns, self.prefixes)
     parser = sax.make_parser()
     normal_parser = saxtools.normalize_text_filter(parser)
     if self.preserve_comments:
         #Comments are the only thing we care about that requires
         #the special handler
         normal_parser.setProperty(
             #parser.setProperty(
             "http://xml.org/sax/properties/lexical-handler",
             self)
     normal_parser.setContentHandler(self)
     normal_parser.setFeature(sax.handler.feature_namespaces, 1)
     #parser.setContentHandler(self)
     #parser.setFeature(sax.handler.feature_namespaces, 1)
     normal_parser.parse(input_source)
     root = self.binding_stack[0]
     root.xmlns_prefixes = self.prefixes
     root.xml_namespaces = g_namespaces
     return root
Esempio n. 4
0
 def read_xml(self, input_source):
     if self.xpatterns:
         self.state_machine = saxtools.xpattern_state_manager(self.xpatterns, self.prefixes)
     parser = sax.make_parser()
     normal_parser = saxtools.normalize_text_filter(parser)
     if self.preserve_comments:
         # Comments are the only thing we care about that requires
         # the special handler
         normal_parser.setProperty(
             # parser.setProperty(
             "http://xml.org/sax/properties/lexical-handler",
             self,
         )
     normal_parser.setContentHandler(self)
     normal_parser.setFeature(sax.handler.feature_namespaces, 1)
     # parser.setContentHandler(self)
     # parser.setFeature(sax.handler.feature_namespaces, 1)
     normal_parser.parse(input_source)
     root = self.binding_stack[0]
     root.xmlns_prefixes = self.prefixes
     root.xml_namespaces = g_namespaces
     return root