Your IP : 18.118.151.211


Current Path : /opt/alt/python310/lib64/python3.10/xml/sax/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/xml/sax/__pycache__/expatreader.cpython-310.pyc

o

6��fS?�@s�dZdZddlTddlmZmZddlmZddlmZmZddlm	Z	ddlm
Z
mZdd	lZej
d	d
�dkr>edd	��[zdd
lmZWneySedd	��weed�s^edd	��ddlmZmZmZejZejZzdd	lZWn
ey�dd�ZYn
wdd	lZejZ[[Gdd�d�ZGdd�dej�ZGdd�dej ej�Z!dd�Z"e#dkr�dd	l$Z%e"�Z&e&�'e%j(j�)��e&�*e%j(�+��e&�,d�d	Sd	S)z]
SAX driver for the pyexpat C module.  This driver works with
pyexpat.__version__ == '2.22'.
z0.20�)�*)�feature_validation�feature_namespaces)�feature_namespace_prefixes)�feature_external_ges�feature_external_pes)�feature_string_interning)�property_xml_string�property_interning_dictN��javazexpat not available in Java)�expatzexpat not supported�ParserCreate)�	xmlreader�saxutils�handlercCs|S�N�)�orr�:/opt/alt/python310/lib64/python3.10/xml/sax/expatreader.py�_mkproxy'src@seZdZdS)�
_ClosedParserN)�__name__�
__module__�__qualname__rrrrr.src@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�ExpatLocatorz�Locator for use with the ExpatParser class.

    This uses a weak reference to the parser object to avoid creating
    a circular reference between the parser and the content handler.
    cCst|�|_dSr)r�_ref��self�parserrrr�__init__9�zExpatLocator.__init__cCs|j}|jdur
dS|jjSr)r�_parser�ErrorColumnNumberrrrr�getColumnNumber<�
zExpatLocator.getColumnNumbercCs|j}|jdur
dS|jjS�N�)rr"�ErrorLineNumberrrrr�
getLineNumberBr%zExpatLocator.getLineNumbercC�|j}|dur	dS|j��Sr)r�_source�getPublicIdrrrrr,H�
zExpatLocator.getPublicIdcCr*r)rr+�getSystemIdrrrrr.Nr-zExpatLocator.getSystemIdN)	rrr�__doc__r r$r)r,r.rrrrr3src@seZdZdZdFdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdGdd�Zdd�Z
dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Zd=d>�Z d?d@�Z!dAdB�Z"dCdD�Z#dES)H�ExpatParserz$SAX driver for the pyexpat C module.r��cCsFtj�||�t��|_d|_||_d|_d|_g|_	d|_
d|_dS)NFr)r�IncrementalParserr ZInputSourcer+r"�_namespaces�_lex_handler_prop�_parsing�
_entity_stack�
_external_ges�
_interning)rZnamespaceHandling�bufsizerrrr Zs

zExpatParser.__init__cCsNt�|�}||_z|��|j�t|��tj�	||�WdS|�
��)z3Parse an XML document from a URL or an InputSource.N)r�prepare_input_sourcer+�reset�
_cont_handlerZsetDocumentLocatorrrr2�parse�
_close_source�r�sourcerrrr=gs
zExpatParser.parsecCs$|��dur|j�|���dSdSr)r.r"ZSetBaser?rrr�
prepareParserws�zExpatParser.prepareParsercCs$tj�||�|jr|��dSdSr)rr2�setContentHandlerr5�_reset_cont_handler)rrrrrrB}s�zExpatParser.setContentHandlercCsL|tkr|jS|tkr|jduS|tttfvrdS|tkr |jSt	d|��)Nr�Feature '%s' not recognized)
rr3rr8rrrrr7�SAXNotRecognizedException�r�namerrr�
getFeature�s
�zExpatParser.getFeaturecCs�|jrtd��|tkr||_dS|tkr||_dS|tkr0|r+|jdur)i|_dSdSd|_dS|tkr<|r:td��dS|t	krH|rFtd��dS|t
krT|rRtd��dStd|��)Nz!Cannot set features while parsingz!expat does not support validationz/expat does not read external parameter entitiesz(expat does not report namespace prefixesrD)r5�SAXNotSupportedExceptionrr3rr7rr8rrrrE)rrG�staterrr�
setFeature�sB



�
�������zExpatParser.setFeaturecCs^|tjkr|jS|tkr|jS|tkr)|jr%t|jd�r!|j��St	d��t
d��t	d|��)N�GetInputContextz=This version of expat does not support getting the XML stringz.XML string cannot be returned when not parsing�Property '%s' not recognized)r�property_lexical_handlerr4r
r8r	r"�hasattrrLrErIrFrrr�getProperty�s

��zExpatParser.getPropertycCsX|tjkr||_|jr|��dSdS|tkr||_dS|tkr&td|��t	d|��)NzProperty '%s' cannot be setrM)
rrNr4r5�_reset_lex_handler_propr
r8r	rIrE)rrG�valuerrr�setProperty�s
�
��zExpatParser.setPropertyFc
Cs||js|��d|_|j��z
|j�||�WdStjy=}ztt�	|j
�||�}|j�|�WYd}~dSd}~ww)NT)
r5r;r<Z
startDocumentr"�Parser
�error�SAXParseException�ErrorString�code�_err_handler�
fatalError)r�data�isFinal�e�excrrr�feed�s
��zExpatParser.feedc
Cs�|jdurdS|j��}zEz|j�d�|j�dd�Wn#tjy?}ztt�|j�||�}|j	�
|�WYd}~nd}~wwW|j�|�dSW|j�|�dS|j�|�w)NF�)r"ZGetReparseDeferralEnabledZSetReparseDeferralEnabledrTr
rUrVrWrXrYrZ)rZwas_enabledr]r^rrr�flush�s

����zExpatParser.flushcCs^|j}z|��}|dur|��W|��}|dur|��dSdS|��}|dur.|��wwr)r+ZgetCharacterStream�closeZ
getByteStream)rr@�filerrrr>�s���
�zExpatParser._close_sourcecCs�|js|jdust|jt�rdSz1|jddd�|j��d|_d|_Wd|_|jdur<t�}|jj|_|jj	|_	||_|�
�dSd|_|jdurZt�}|jj|_|jj	|_	||_|�
�w)Nr`T)r\F)r6r"�
isinstancerr_r<ZendDocumentr5r#r(r>rrrrrb�s.
�



�



zExpatParser.closecCs|jj|j_|jj|j_dSr)r<�processingInstructionr"ZProcessingInstructionHandler�
charactersZCharacterDataHandler�rrrrrC
s�zExpatParser._reset_cont_handlercCsb|j}|j}|durd|_d|_d|_d|_d|_dS|j|_|j|_|j	|_|j
|_|j|_dSr)r4r"ZCommentHandlerZStartCdataSectionHandlerZEndCdataSectionHandlerZStartDoctypeDeclHandlerZEndDoctypeDeclHandlerZcommentZ
startCDATAZendCDATA�start_doctype_declZendDTD)rZlexrrrrrQs
z#ExpatParser._reset_lex_handler_propcCs�|jrtj|j��d|jd�|_d|j_|j|j_	|j
|j_ntj|j��|jd�|_|j|j_	|j
|j_|��|j|j_|j|j_|j|j_|j|j_d|_|jrW|��|j|j_z|j|j_Wn	tylYnw|j�tj �d|_!g|_"dS)N� )�internr'F)#r3r
rr+ZgetEncodingr8r"Znamespace_prefixes�start_element_nsZStartElementHandler�end_element_nsZEndElementHandler�
start_element�end_elementrC�unparsed_entity_declZUnparsedEntityDeclHandler�
notation_declZNotationDeclHandler�start_namespace_declZStartNamespaceDeclHandler�end_namespace_declZEndNamespaceDeclHandlerZ_decl_handler_propr4rQ�external_entity_refZExternalEntityRefHandler�skipped_entity_handlerZSkippedEntityHandler�AttributeErrorZSetParamEntityParsingZ*XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONEr5r6rgrrrr;"s>�
�






��
zExpatParser.resetcCs|jdurdS|jjSr)r"r#rgrrrr$I�
zExpatParser.getColumnNumbercCs|jdurdS|jjSr&)r"r(rgrrrr)NrvzExpatParser.getLineNumbercC�
|j��Sr)r+r,rgrrrr,S�
zExpatParser.getPublicIdcCrwr)r+r.rgrrrr.VrxzExpatParser.getSystemIdcCs|j�|t|��dSr)r<ZstartElement�AttributesImpl)rrG�attrsrrrrmZ�zExpatParser.start_elementcC�|j�|�dSr)r<Z
endElementrFrrrrn]�zExpatParser.end_elementcCs�|��}t|�dkrd|f}nt|�dkr|d|df}nt|�}i}i}|��D]>\}}|��}t|�}	|	dkrA|}
d|f}n|	dkrXd|d|df}
|d|df}n|d}
t|�}|||<|
||<q*|j�|dt||��dS)Nr'�rz%s:%s�)�split�len�tuple�itemsr<ZstartElementNS�AttributesNSImpl)rrGrz�pairZnewattrsZqnamesZanamerR�partsZlengthZqnameZapairrrrrk`s0



�zExpatParser.start_element_nscCsV|��}t|�dkrd|f}nt|�dkr|d|df}nt|�}|j�|d�dS)Nr'r~r)r�r�r�r<ZendElementNS)rrGr�rrrrl�s
zExpatParser.end_element_nscC�|j�||�dSr)r<re)r�targetr[rrr�processing_instruction��z"ExpatParser.processing_instructioncCr|r)r<rf)rr[rrr�character_data�r}zExpatParser.character_datacCr�r)r<ZstartPrefixMapping)r�prefixZurirrrrq�r�z ExpatParser.start_namespace_declcCr|r)r<ZendPrefixMapping)rr�rrrrr�r}zExpatParser.end_namespace_declcCs|j�|||�dSr)r4ZstartDTD)rrG�sysid�pubidZhas_internal_subsetrrrrh��zExpatParser.start_doctype_declcCs|j�||||�dSr)�_dtd_handlerZunparsedEntityDecl)rrG�baser�r�Z
notation_namerrrro�r{z ExpatParser.unparsed_entity_declcCs|j�|||�dSr)r�ZnotationDecl)rrGr�r�r�rrrrp�r�zExpatParser.notation_declcCs�|jsdS|j�||�}t�||j��pd�}|j�|j	|jf�|j	�
|�|_	||_z	tj�
||�WnYdS|jd\|_	|_|jd=dS)Nr'�r���)r7Z_ent_handlerZ
resolveEntityrr:r+r.r6�appendr"ZExternalEntityParserCreaterr2r=)r�contextr�r�r�r@rrrrs�s"
�zExpatParser.external_entity_refcCs|rd|}|j�|�dS)N�%)r<Z
skippedEntity)rrGZis_perrrrt�sz"ExpatParser.skipped_entity_handlerN)rr1)F)$rrrr/r r=rArBrHrKrPrSr_rar>rbrCrQr;r$r)r,r.rmrnrkrlr�r�rqrrrhrorprsrtrrrrr0WsD


'"r0cOst|i|��Sr)r0)�args�kwargsrrr�
create_parser�r!r��__main__z:http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml)-r/�versionZxml.sax._exceptionsZxml.sax.handlerrrrrrrr	r
�sys�platformZSAXReaderNotAvailableZxml.parsersr
�ImportErrorrOZxml.saxrrrryr��_weakrefr�weakref�proxyrZLocatorrr2r0r�rZxml.sax.saxutilsZxml�prBZsaxZXMLGeneratorZsetErrorHandlerZErrorHandlerr=rrrr�<module>sV

�

�$m�

?>