Your IP : 3.145.88.104


Current Path : /opt/alt/python34/lib64/python3.4/xml/sax/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/xml/sax/__pycache__/expatreader.cpython-34.pyo

�
j fc;�@sAdZdZddlTddlmZmZddlmZddlmZmZddlm	Z	ddlm
Z
mZdd	lZej
d	d
�dkr�edd	��n[ydd
lmZWn!ek
r�edd	��Yn#Xeed�redd	��nddlmZmZmZejZejZydd	lZWnek
rjdd�ZYnXdd	lZejZ[[Gdd�d�ZGdd�dej�ZGdd�dej ej�Z!dd�Z"e#dkr=dd	l$Z%e"�Z&e&j'e%j(jj)��e&j*e%j(j+��e&j,d�nd	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�8/opt/alt/python34/lib64/python3.4/xml/sax/expatreader.py�_mkproxy'src@seZdZdS)�
_ClosedParserN)�__name__�
__module__�__qualname__rrrrr.src@sReZdZdZdd�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|�|_dS)N)r�_ref)�self�parserrrr�__init__9szExpatLocator.__init__cCs&|j}|jdkrdS|jjS)N)r�_parser�ErrorColumnNumber)rrrrr�getColumnNumber<s	zExpatLocator.getColumnNumbercCs&|j}|jdkrdS|jjS)N�)rr�ErrorLineNumber)rrrrr�
getLineNumberBs	zExpatLocator.getLineNumbercCs&|j}|dkrdS|jj�S)N)r�_source�getPublicId)rrrrrr&Hs	zExpatLocator.getPublicIdcCs&|j}|dkrdS|jj�S)N)rr%�getSystemId)rrrrrr'Ns	zExpatLocator.getSystemIdN)	rrr�__doc__rr!r$r&r'rrrrr3src@s�eZdZdZddDdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Z	dd�Z
dd�Zddd�Zdd�Z
dd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>d?�Z d@dA�Z!dBS)E�ExpatParserz$SAX driver for the pyexpat C module.r���cCsetjj||�tj�|_d|_||_d|_d|_g|_	d|_
d|_dS)Nrr")r�IncrementalParserrZInputSourcer%r�_namespaces�_lex_handler_prop�_parsing�
_entity_stack�
_external_ges�
_interning)rZnamespaceHandling�bufsizerrrrZs						zExpatParser.__init__cCsOtj|�}||_|j�|jjt|��tjj	||�dS)z3Parse an XML document from a URL or an InputSource.N)
r�prepare_input_sourcer%�reset�
_cont_handlerZsetDocumentLocatorrrr-�parse)r�sourcerrrr8gs
	
zExpatParser.parsecCs/|j�dk	r+|jj|j��ndS)N)r'rZSetBase)rr9rrr�
prepareParserpszExpatParser.prepareParsercCs-tjj||�|jr)|j�ndS)N)rr-�setContentHandlerr0�_reset_cont_handler)rrrrrr;vs	zExpatParser.setContentHandlercCsl|tkr|jS|tkr,|jdk	S|tttfkrEdS|tkrX|jSt	d|��dS)NrzFeature '%s' not recognized)
rr.rr3rrrrr2�SAXNotRecognizedException)r�namerrr�
getFeature{s
	zExpatParser.getFeaturecCs|jrtd��n|tkr0||_n�|tkrH||_n�|tkr�|rx|jdkr�i|_q�qd|_n||tkr�|rtd��qnX|t	kr�|rtd��qn4|t
kr�|rtd��qntd|��dS)Nz!Cannot set features while parsingz!expat does not support validationz/expat does not read external parameter entitiesz(expat does not report namespace prefixeszFeature '%s' not recognized)r0�SAXNotSupportedExceptionrr.rr2rr3rrrr=)rr>�staterrr�
setFeature�s2	zExpatParser.setFeaturecCs�|tjkr|jS|tkr)|jS|tkr{|jrlt|jd�r]|jj�St	d��q{t
d��nt	d|��dS)N�GetInputContextz=This version of expat does not support getting the XML stringz.XML string cannot be returned when not parsingzProperty '%s' not recognized)r�property_lexical_handlerr/r
r3r	r�hasattrrCr=r@)rr>rrr�getProperty�s	
zExpatParser.getPropertycCs||tjkr1||_|jrx|j�qxnG|tkrI||_n/|tkrhtd|��nt	d|��dS)NzProperty '%s' cannot be setzProperty '%s' not recognized)
rrDr/r0�_reset_lex_handler_propr
r3r	r@r=)rr>�valuerrr�setProperty�s		
zExpatParser.setPropertycCs�|js,|j�d|_|jj�ny|jj||�WnVtjk
r�}z3ttj	|j
�||�}|jj|�WYdd}~XnXdS)Nr")
r0r6r7Z
startDocumentrZParser
�errorZSAXParseExceptionZErrorString�codeZ_err_handlerZ
fatalError)r�data�isFinal�e�excrrr�feed�s	
	zExpatParser.feedcCs�|js*|jdks*t|jt�r.dSz6|jddd�|jj�d|_d|_Wdd|_|jdk	r�t�}|jj|_|jj	|_	||_n|j
j�}|dk	r�|j�nXdS)N�rMr"r)
r1r�
isinstancerrPr7ZendDocumentr0r r#r%Z
getByteStream�close)rrZbsrrrrS�s"
	
		zExpatParser.closecCs(|jj|j_|jj|j_dS)N)r7�processingInstructionrZProcessingInstructionHandler�
charactersZCharacterDataHandler)rrrrr<�szExpatParser._reset_cont_handlercCs�|j}|j}|dkrNd|_d|_d|_d|_d|_n<|j|_|j|_|j	|_|j
|_|j|_dS)N)r/rZCommentHandlerZStartCdataSectionHandlerZEndCdataSectionHandlerZStartDoctypeDeclHandlerZEndDoctypeDeclHandlerZcommentZ
startCDATAZendCDATA�start_doctype_declZendDTD)rZlexrrrrrG�s						z#ExpatParser._reset_lex_handler_propcCsd|jr]tj|jj�dd|j�|_d|j_|j|j_	|j
|j_nBtj|jj�d|j�|_|j|j_	|j
|j_|j�|j|j_|j|j_|j|j_|j|j_d|_|jr|j�n|j|j_y|j|j_Wntk
r:YnX|jjtj �d|_!g|_"dS)N� �internr"r)#r.r
rr%ZgetEncodingr3rZnamespace_prefixes�start_element_nsZStartElementHandler�end_element_nsZEndElementHandler�
start_element�end_elementr<�unparsed_entity_declZUnparsedEntityDeclHandler�
notation_declZNotationDeclHandler�start_namespace_declZStartNamespaceDeclHandler�end_namespace_declZEndNamespaceDeclHandlerZ_decl_handler_propr/rG�external_entity_refZExternalEntityRefHandler�skipped_entity_handlerZSkippedEntityHandler�AttributeErrorZSetParamEntityParsingZ*XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONEr0r1)rrrrr6s6	
		

	
	zExpatParser.resetcCs|jdkrdS|jjS)N)rr )rrrrr!+szExpatParser.getColumnNumbercCs|jdkrdS|jjS)Nr")rr#)rrrrr$0szExpatParser.getLineNumbercCs
|jj�S)N)r%r&)rrrrr&5szExpatParser.getPublicIdcCs
|jj�S)N)r%r')rrrrr'8szExpatParser.getSystemIdcCs|jj|t|��dS)N)r7ZstartElement�AttributesImpl)rr>�attrsrrrr[<szExpatParser.start_elementcCs|jj|�dS)N)r7Z
endElement)rr>rrrr\?szExpatParser.end_elementcCsL|j�}t|�dkr-d|f}n5t|�dkrV|d|df}nt|�}i}i}x�|j�D]�\}}|j�}t|�}	|	dkr�|}
d|f}nQ|	dkr�d|d|df}
|d|df}n|d}
t|�}|||<|
||<q{W|jj|dt||��dS)Nr"�rz%s:%sr*)�split�len�tuple�itemsr7ZstartElementNS�AttributesNSImpl)rr>re�pairZnewattrsZqnamesZanamerH�partsZlengthZqnameZapairrrrrYBs.

zExpatParser.start_element_nscCsy|j�}t|�dkr-d|f}n5t|�dkrV|d|df}nt|�}|jj|d�dS)Nr"rfr)rgrhrir7ZendElementNS)rr>rlrrrrZdszExpatParser.end_element_nscCs|jj||�dS)N)r7rT)r�targetrLrrr�processing_instructionpsz"ExpatParser.processing_instructioncCs|jj|�dS)N)r7rU)rrLrrr�character_datatszExpatParser.character_datacCs|jj||�dS)N)r7ZstartPrefixMapping)r�prefixZurirrrr_wsz ExpatParser.start_namespace_declcCs|jj|�dS)N)r7ZendPrefixMapping)rrqrrrr`zszExpatParser.end_namespace_declcCs|jj|||�dS)N)r/ZstartDTD)rr>�sysid�pubidZhas_internal_subsetrrrrV}szExpatParser.start_doctype_declcCs|jj||||�dS)N)�_dtd_handlerZunparsedEntityDecl)rr>�baserrrsZ
notation_namerrrr]�sz ExpatParser.unparsed_entity_declcCs|jj|||�dS)N)rtZnotationDecl)rr>rurrrsrrrr^�szExpatParser.notation_declc	Cs�|js
dS|jj||�}tj||jj�p=d�}|jj|j	|jf�|j	j
|�|_	||_ytjj
||�WndSYnX|jd\|_	|_|jd=dS)Nr"rQr���rv)r2Z_ent_handlerZ
resolveEntityrr5r%r'r1�appendrZExternalEntityParserCreaterr-r8)r�contextrurrrsr9rrrra�s 					
zExpatParser.external_entity_refcCs'|rd|}n|jj|�dS)N�%)r7Z
skippedEntity)rr>Zis_perrrrb�s
z"ExpatParser.skipped_entity_handlerNii�)"rrrr(rr8r:r;r?rBrFrIrPrSr<rGr6r!r$r&r'r[r\rYrZrorpr_r`rVr]r^rarbrrrrr)Ws>
	'"r)cOs
t||�S)N)r))�args�kwargsrrr�
create_parser�sr|�__main__z:http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml)-r(�versionZxml.sax._exceptionsZxml.sax.handlerrrrrrrr	r
�sys�platformZSAXReaderNotAvailableZxml.parsersr
�ImportErrorrEZxml.saxrrrrdrk�_weakrefr�weakref�proxyrZLocatorrr-r)r|rZxml.sax.saxutilsZxml�pr;ZsaxZXMLGeneratorZsetErrorHandlerZErrorHandlerr8rrrr�<module>sL

		
	$�N	

?>