U e5dß/ã@sªdZddlZddlZddlZddlZddlZddlmZddlm Z dd„Z ifdd „Z ifd d „Z ifd d „Z dd„ZGdd„dejƒZGdd„de jƒZddd„ZdS)znA library of useful helper classes to the SAX classes, for the convenience of application and driver writers. éNé)Úhandler)Ú xmlreadercCs"| ¡D]\}}| ||¡}q|S)z2Replace substrings of a string using a dictionary.)ÚitemsÚreplace)ÚsÚdÚkeyÚvalue©r ú(/usr/lib64/python3.8/xml/sax/saxutils.pyÚ__dict_replace sr cCs6| dd¡}| dd¡}| dd¡}|r2t||ƒ}|S)züEscape &, <, and > in a string of data. You can escape other strings of data by passing a dictionary as the optional entities parameter. The keys and values must all be strings; each key will be replaced with its corresponding value. ú&ú&ú>ú>ú<ú<©rr ©ÚdataZentitiesr r r Úescapes    rcCs2| dd¡}| dd¡}|r&t||ƒ}| dd¡S)a Unescape &, <, and > in a string of data. You can unescape other strings of data by passing a dictionary as the optional entities parameter. The keys and values must all be strings; each key will be replaced with its corresponding value. rrrrrrrrr r r Úunescape"s    rcCsR|ddddœ–}t||ƒ}d|krFd|kr in a string of data, then quote it for use as an attribute value. The " character will be escaped as well, if necessary. You can escape other strings of data by passing a dictionary as the optional entities parameter. The keys and values must all be strings; each key will be replaced with its corresponding value. z z z )Ú ú ú ú"ú'z"%s"z"z'%s')rrrr r r Ú quoteattr0s   rcsĈdkrddl}|jStˆtjƒr&ˆStˆtjtjfƒr<ˆStˆtjƒrlG‡fdd„dƒ}|ƒ}dd„|_ nDt  ¡}dd„|_ ˆj |_ zˆj |_ ˆj|_Wntk r®YnXtj||ddd d S) NrcseZdZ”jZ‡fdd„ZdS)z _gettextwriter.._wrappercs tˆ|ƒS©N)Úgetattr©ÚselfÚname©Úoutr r Ú __getattr__Zsz,_gettextwriter.._wrapper.__getattr__N)Ú__name__Ú __module__Ú __qualname__Ú __class__r&r r$r r Ú_wrapperXsr+cSsdSrr r r r r Ú]óz _gettextwriter..cSsdS)NTr r r r r r,br-ÚxmlcharrefreplacerT)ÚencodingÚerrorsÚnewlineÚ write_through)ÚsysÚstdoutÚ isinstanceÚioÚ TextIOBaseÚcodecsÚ StreamWriterÚStreamReaderWriterÚ RawIOBaseÚcloseÚBufferedIOBaseÚwritableÚwriteÚseekableÚtellÚAttributeErrorÚ TextIOWrapper)r%r/r3r+Úbufferr r$r Ú_gettextwriterGs0     ýrEc@s€eZdZd dd„Zdd„Zd!dd „Zd d „Zd d „Zdd„Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„ZdS)"Ú XMLGeneratorNú iso-8859-1FcCsVtj |¡t||ƒ}|j|_|j|_ig|_|jd|_ g|_ ||_ ||_ d|_ dS)NéÿÿÿÿF)rÚContentHandlerÚ__init__rEr?Ú_writeÚflushÚ_flushÚ _ns_contextsÚ_current_contextÚ_undeclared_ns_mapsÚ _encodingÚ_short_empty_elementsÚ_pending_start_element)r"r%r/Zshort_empty_elementsr r r rJrs   zXMLGenerator.__init__cCsJ|drBd|dkr d|dS|j|d}|rB|d|dS|dS)z7Builds a qualified name from a (ns_url, localname) pairrz$http://www.w3.org/XML/1998/namespacezxml:rú:)rO)r"r#Úprefixr r r Ú_qname~s  zXMLGenerator._qnamecCs|jr| d¡d|_dS)NrF©rSrK)r"Ú endElementr r r Ú_finish_pending_start_elements z*XMLGenerator._finish_pending_start_elementcCs| d|j¡dS)Nz$ )rKrQ©r"r r r Ú startDocument–sÿzXMLGenerator.startDocumentcCs | ¡dSr)rMrZr r r Ú endDocumentšszXMLGenerator.endDocumentcCs0|j |j ¡¡||j|<|j ||f¡dSr)rNÚappendrOÚcopyrP©r"rUÚurir r r ÚstartPrefixMappings zXMLGenerator.startPrefixMappingcCs|jd|_|jd=dS)NrH)rNrO©r"rUr r r ÚendPrefixMapping¢s zXMLGenerator.endPrefixMappingcCsZ| ¡| d|¡| ¡D]\}}| d|t|ƒf¡q|jrLd|_n | d¡dS)Nrú %s=%sTr)rYrKrrrRrS)r"r#Úattrsr r r r Ú startElement¦szXMLGenerator.startElementcCs*|jr| d¡d|_n| d|¡dS©Nz/>FzrWr!r r r rX°s zXMLGenerator.endElementcCs¢| ¡| d| |¡¡|jD].\}}|rB| d||f¡q"| d|¡q"g|_| ¡D]$\}}| d| |¡t|ƒf¡q`|jr”d|_n | d¡dS)Nrz xmlns:%s="%s"z xmlns="%s"rdTr)rYrKrVrPrrrRrS)r"r#ÚqnamererUr`r r r r ÚstartElementNS·szXMLGenerator.startElementNScCs0|jr| d¡d|_n| d| |¡¡dSrg)rSrKrV©r"r#rhr r r Ú endElementNSÉs zXMLGenerator.endElementNScCs4|r0| ¡t|tƒs"t||jƒ}| t|ƒ¡dSr)rYr5ÚstrrQrKr©r"Zcontentr r r Ú charactersÐs   zXMLGenerator.characterscCs0|r,| ¡t|tƒs"t||jƒ}| |¡dSr)rYr5rlrQrKrmr r r ÚignorableWhitespace×s   z XMLGenerator.ignorableWhitespacecCs| ¡| d||f¡dS)Nz )rYrK©r"Útargetrr r r ÚprocessingInstructionÞsz"XMLGenerator.processingInstruction)NrGF)F)r'r(r)rJrVrYr[r\rarcrfrXrirkrnrorrr r r r rFps   rFc@sòeZdZdZd;dd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Zd7d8„Zd9d:„ZdS)<Ú XMLFilterBaseaYThis class is designed to sit between an XMLReader and the client application's event handlers. By default, it does nothing but pass requests up to the reader and events on to the handlers unmodified, but subclasses can override specific methods to modify the event stream or the configuration requests as they pass through.NcCstj |¡||_dSr)rÚ XMLReaderrJÚ_parent©r"Úparentr r r rJës zXMLFilterBase.__init__cCs|j |¡dSr)Ú _err_handlerÚerror©r"Z exceptionr r r ryñszXMLFilterBase.errorcCs|j |¡dSr)rxÚ fatalErrorrzr r r r{ôszXMLFilterBase.fatalErrorcCs|j |¡dSr)rxÚwarningrzr r r r|÷szXMLFilterBase.warningcCs|j |¡dSr)Ú _cont_handlerÚsetDocumentLocator)r"Zlocatorr r r r~üsz XMLFilterBase.setDocumentLocatorcCs|j ¡dSr)r}r[rZr r r r[ÿszXMLFilterBase.startDocumentcCs|j ¡dSr)r}r\rZr r r r\szXMLFilterBase.endDocumentcCs|j ||¡dSr)r}rar_r r r rasz XMLFilterBase.startPrefixMappingcCs|j |¡dSr)r}rcrbr r r rcszXMLFilterBase.endPrefixMappingcCs|j ||¡dSr)r}rf)r"r#rer r r rf szXMLFilterBase.startElementcCs|j |¡dSr)r}rXr!r r r rXszXMLFilterBase.endElementcCs|j |||¡dSr)r}ri)r"r#rhrer r r riszXMLFilterBase.startElementNScCs|j ||¡dSr)r}rkrjr r r rkszXMLFilterBase.endElementNScCs|j |¡dSr)r}rnrmr r r rnszXMLFilterBase.characterscCs|j |¡dSr)r}ro)r"Úcharsr r r rosz!XMLFilterBase.ignorableWhitespacecCs|j ||¡dSr)r}rrrpr r r rrsz#XMLFilterBase.processingInstructioncCs|j |¡dSr)r}Ú skippedEntityr!r r r r€ szXMLFilterBase.skippedEntitycCs|j |||¡dSr)Ú _dtd_handlerÚ notationDecl)r"r#ÚpublicIdÚsystemIdr r r r‚%szXMLFilterBase.notationDeclcCs|j ||||¡dSr)rÚunparsedEntityDecl)r"r#rƒr„Zndatar r r r…(sz XMLFilterBase.unparsedEntityDeclcCs|j ||¡Sr)Z _ent_handlerÚ resolveEntity)r"rƒr„r r r r†-szXMLFilterBase.resolveEntitycCs@|j |¡|j |¡|j |¡|j |¡|j |¡dSr)ruZsetContentHandlerZsetErrorHandlerZsetEntityResolverZ setDTDHandlerÚparse)r"Úsourcer r r r‡2s     zXMLFilterBase.parsecCs|j |¡dSr)ruÚ setLocale)r"Zlocaler r r r‰9szXMLFilterBase.setLocalecCs |j |¡Sr)ruÚ getFeaturer!r r r rŠ<szXMLFilterBase.getFeaturecCs|j ||¡dSr)ruÚ setFeature)r"r#Ústater r r r‹?szXMLFilterBase.setFeaturecCs |j |¡Sr)ruÚ getPropertyr!r r r rBszXMLFilterBase.getPropertycCs|j ||¡dSr)ruÚ setProperty)r"r#r r r r rŽEszXMLFilterBase.setPropertycCs|jSr©rurZr r r Ú getParentJszXMLFilterBase.getParentcCs ||_dSrrrvr r r Ú setParentMszXMLFilterBase.setParent)N) r'r(r)Ú__doc__rJryr{r|r~r[r\rarcrfrXrirkrnrorrr€r‚r…r†r‡r‰rŠr‹rrŽrr‘r r r r rsãs: rsÚcCs$t|tjƒrt |¡}t|tƒr,t |¡}n^t|dƒrŠ|}t ¡}t| d¡tƒr^|  |¡n |  |¡t|dƒrŠt|j tƒrŠ|  |j ¡|  ¡dkr | ¡dkr | ¡}tj tj |¡¡}tj ||¡}tj |¡rò|  |¡t|dƒ}n$|  tj ||¡¡tj | ¡¡}|  |¡|S)z‚This function takes an InputSource and an optional base URL and returns a fully resolved InputSource object ready for reading.Úreadrr#NÚrb)r5ÚosÚPathLikeÚfspathrlrZ InputSourceÚhasattrr”ZsetCharacterStreamZ setByteStreamr#Z setSystemIdZgetCharacterStreamZ getByteStreamZ getSystemIdÚpathÚdirnameÚnormpathÚjoinÚisfileÚopenÚurllibr‡ZurljoinZrequestZurlopen)rˆÚbaseÚfZsysidZbaseheadZ sysidfilenamer r r Úprepare_input_sourceRs.            r£)r“)r’r–Z urllib.parser Zurllib.requestr6r8r“rrr rrrrErIrFrtrsr£r r r r Ús     )so