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
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
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
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
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
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)
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)
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()
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())
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)
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)
def reset(self): _ExpatParser.reset(self) parser = self._parser parser.StartDoctypeDeclHandler = self.start_doctype_decl parser.ExternalEntityRefHandler = self.external_entity_ref_handler
def __init__(self): """Initialize the class.""" ExpatParser.__init__(self) self.firsttime = True
def __init__(self): ExpatParser.__init__(self) self.firsttime = True
def reset(self): ExpatParser.reset(self) self._parser.DefaultHandler = self.__default_handler self._parser.EntityDeclHandler = self.__entity_decl_handler
def __init__(self): ExpatParser.__init__(self) self.firsttime = True
def __init__(self, *args, **kwargs): _ExpatParser.__init__(self, *args, **kwargs) self.setFeature(handler.feature_external_ges, False) self.setFeature(handler.feature_external_pes, False)
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
def __init__(self): """Initialize the class.""" ExpatParser.__init__(self) self.firsttime = True
def reset(self): ExpatParser.reset(self) # This line makes the parser think unknown # entities are external. self._parser.UseForeignDTD(True)
"""
def __init__(self, *args, **kwargs): _ExpatParser.__init__(self, *args, **kwargs) self.setFeature(handler.feature_external_ges, False) self.setFeature(handler.feature_external_pes, False)
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
def reset(self): ExpatParser.reset(self) self._parser.UseForeignDTD(1)
def __init__(self, *args, **kwargs): ExpatParser.__init__(self, *args, **kwargs) self.__entities = {}
def __init__(self, *args, **kwargs): ExpatParser.__init__(self, *args, **kwargs) self.__entities = {}
def reset(self): ExpatParser.reset(self) # This line makes the parser think unknown # entities are external. self._parser.UseForeignDTD(True)
def __init__(self): self.parser = ExpatParser() self.parser.setContentHandler( BlobHandler() ) # we need to fake a root element self.parser.feed("<root>")
def reset(self): ExpatParser.reset(self) self._parser.DefaultHandler = self.__default_handler self._parser.EntityDeclHandler = self.__entity_decl_handler