Exemplo n.º 1
0
 def __init__(self, namespaceHandling=0, bufsize=2 ** 16 - 20,
              forbid_dtd=False, forbid_entities=True,
              forbid_external=True):
     _ExpatParser.__init__(self, namespaceHandling, bufsize)
     self.forbid_dtd = forbid_dtd
     self.forbid_entities = forbid_entities
     self.forbid_external = forbid_external
Exemplo n.º 2
0
 def reset(self):
     _ExpatParser.reset(self)
     parser = self._parser
     parser.StartDoctypeDeclHandler = self.start_doctype_decl
     parser.EntityDeclHandler = self.entity_decl
     parser.UnparsedEntityDeclHandler = self.unparsed_entity_decl
     parser.ExternalEntityRefHandler = self.external_entity_ref_handler
Exemplo n.º 3
0
 def reset(self):
     ExpatParser.reset(self)
     if self.forbid_dtd:
         self._parser.StartDoctypeDeclHandler = self.start_doctype_decl
     if self.forbid_entities:
         self._parser.EntityDeclHandler = self.entity_decl
         self._parser.UnparsedEntityDeclHandler = self.unparsed_entity_decl
Exemplo n.º 4
0
 def reset(self):
     _ExpatParser.reset(self)
     parser = self._parser
     if self.forbid_dtd:
         parser.StartDoctypeDeclHandler = self.defused_start_doctype_decl
     if self.forbid_entities:
         parser.EntityDeclHandler = self.defused_entity_decl
         parser.UnparsedEntityDeclHandler = self.defused_unparsed_entity_decl
     if self.forbid_external:
         parser.ExternalEntityRefHandler = self.defused_external_entity_ref_handler
Exemplo n.º 5
0
def parse( file ):
    h = NZBParser()
    p = ExpatParser()
    p.setContentHandler(h)
    p.setFeature(handler.feature_external_ges, False)
    p.parse(file)
    nzb = h.getNzb()
    return nzb
Exemplo n.º 6
0
 def feed(self, data, isFinal = 0):
     # Error messages returned by the ScanProsite server are formatted as
     # as plain text instead of an XML document. To catch such error
     # messages, we override the feed method of the Expat parser.
     # The error message is (hopefully) contained in the data that was just
     # fed to the parser.
     if self.firsttime:
         if data[:5].decode('utf-8') != "<?xml":
             raise ValueError(data)
     self.firsttime = False
     return ExpatParser.feed(self, data, isFinal)
Exemplo n.º 7
0
 def feed(self, data, isFinal=0):
     # Error messages returned by the ScanProsite server are formatted as
     # as plain text instead of an XML document. To catch such error
     # messages, we override the feed method of the Expat parser.
     # The error message is (hopefully) contained in the data that was just
     # fed to the parser.
     if self.firsttime:
         if data[:5] != "<?xml":
             raise ValueError(data)
     self.firsttime = False
     return ExpatParser.feed(self, data, isFinal)
Exemplo n.º 8
0
def thing_from_sax(filehandle=None,paranoia=1):

    if DEBUG == 1:
        print "**** SAX PARSER ****"

    e = ExpatParser()
    m = xmlpickle_handler(paranoia)
    e.setContentHandler(m)
    e.setErrorHandler(m)
    e.setEntityResolver(m)

    if filehandle:
        e.parse(filehandle)
    else:
        raise "Must pass a fileobj"

    return m.getobj()
Exemplo n.º 9
0
 def __init__(self, *args, **kwargs):
     """docstring for __init__"""
     ExpatParser.__init__(self, *args, **kwargs)
     
     class _NiftyEntityResolver(EntityResolver):
         """
         _NiftyEntityResolver makes the entity errors disappear.
         
         It works by the html spec which says that external entities that
         can not resolved, do not have to be reported as an error by a non
         validating parser.
         """
         def resolveEntity(self, publicId, systemId):
             "This will be called with None, None if it is an unknown entity"
             if systemId or publicId:
                  return EntityResolver.resolveEntity(self,publicId,systemId)
             
             # return an empty stringio in which the parser can never find
             # the entities. This will make it skip the entity, which triggers
             # skippedEntity in the contenthandler.
             return StringIO.StringIO(" ") # if you delete that single space you will be sorry.
     
     self.setEntityResolver(_NiftyEntityResolver())
Exemplo n.º 10
0
class XMLFeeder:
    def __init__(self, handler=None):
        if handler is None:
            handler = XMLHandler()

        self.parser = ExpatParser()
        self.parser.setContentHandler(handler)

        # we need to fake a root element
        self.parser.feed("<root>")

    def write_message(self, data):
        self.parser.feed(data)
Exemplo n.º 11
0
class BlobClient:
    """Sometimes it is necessary to understand the 
    incoming INDI information on the serverside as 
    opposed to sending the raw information to the
    httpclient. 
    
    
    Here we would like to extract BLOB data so that
    it can be saved to disk. To do this we feed the
    xml to the ExpatParser which uses BlobHandler to
    pull out the base64 data and convert it to binary.
    """
    def __init__(self):
        self.parser = ExpatParser()
        self.parser.setContentHandler(BlobHandler())

        # we need to fake a root element
        self.parser.feed("<root>")

    def write_message(self, data):
        self.parser.feed(data)
Exemplo n.º 12
0
 def reset(self):
     _ExpatParser.reset(self)
     parser = self._parser
     parser.StartDoctypeDeclHandler = self.start_doctype_decl
     parser.ExternalEntityRefHandler = self.external_entity_ref_handler
Exemplo n.º 13
0
 def __init__(self):
     """Initialize the class."""
     ExpatParser.__init__(self)
     self.firsttime = True
Exemplo n.º 14
0
 def __init__(self):
     ExpatParser.__init__(self)
     self.firsttime = True
Exemplo n.º 15
0
 def reset(self):
     ExpatParser.reset(self)
     self._parser.DefaultHandler = self.__default_handler
     self._parser.EntityDeclHandler = self.__entity_decl_handler
Exemplo n.º 16
0
 def __init__(self):
     ExpatParser.__init__(self)
     self.firsttime = True
Exemplo n.º 17
0
 def __init__(self, *args, **kwargs):
     _ExpatParser.__init__(self, *args, **kwargs)
     self.setFeature(handler.feature_external_ges, False)
     self.setFeature(handler.feature_external_pes, False)
Exemplo n.º 18
0
 def __init__(self, forbid_dtd=True, forbid_entities=True,
              *args, **kwargs):
     # Python 2.x old style class
     ExpatParser.__init__(self, *args, **kwargs)
     self.forbid_dtd = forbid_dtd
     self.forbid_entities = forbid_entities
Exemplo n.º 19
0
 def __init__(self):
     """Initialize the class."""
     ExpatParser.__init__(self)
     self.firsttime = True
Exemplo n.º 20
0
 def reset(self):
     ExpatParser.reset(self)
     # This line makes the parser think unknown
     # entities are external.
     self._parser.UseForeignDTD(True)
Exemplo n.º 21
0
"""
Exemplo n.º 22
0
 def __init__(self, *args, **kwargs):
     _ExpatParser.__init__(self, *args, **kwargs)
     self.setFeature(handler.feature_external_ges, False)
     self.setFeature(handler.feature_external_pes, False)
Exemplo n.º 23
0
 def __init__(self, forbid_dtd=True, forbid_entities=True,
              *args, **kwargs):
     # Python 2.x old style class
     ExpatParser.__init__(self, *args, **kwargs)
     self.forbid_dtd = forbid_dtd
     self.forbid_entities = forbid_entities
Exemplo n.º 24
0
 def reset(self):
   ExpatParser.reset(self)
   self._parser.UseForeignDTD(1)
Exemplo n.º 25
0
 def __init__(self, *args, **kwargs):
     ExpatParser.__init__(self, *args, **kwargs)
     self.__entities = {}
Exemplo n.º 26
0
 def __init__(self, *args, **kwargs):
     ExpatParser.__init__(self, *args, **kwargs)
     self.__entities = {}
Exemplo n.º 27
0
 def reset(self):
     ExpatParser.reset(self)
     # This line makes the parser think unknown
     # entities are external.
     self._parser.UseForeignDTD(True)
Exemplo n.º 28
0
    def __init__(self):
        self.parser = ExpatParser()
        self.parser.setContentHandler( BlobHandler() )

        # we need to fake a root element
        self.parser.feed("<root>")
Exemplo n.º 29
0
 def reset(self):
     ExpatParser.reset(self)
     self._parser.DefaultHandler = self.__default_handler
     self._parser.EntityDeclHandler = self.__entity_decl_handler