a
    ö£Be”  ã                   @   s~   d Z ddlmZmZ ddlmZ ddlmZ ddl	m
Z
mZmZ dZG dd	„ d	eƒZG d
d„ deeƒZddd„Zddd„ZdS )zDefused xml.dom.expatbuilder
é    )Úprint_functionÚabsolute_import)ÚExpatBuilder)Ú
Namespacesé   )ÚDTDForbiddenÚEntitiesForbiddenÚExternalReferenceForbiddenzxml.dom.expatbuilderc                   @   sB   e Zd ZdZddd„Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Z	dS )ÚDefusedExpatBuilderzDefused document builderNFTc                 C   s"   t  | |¡ || _|| _|| _d S ©N)Ú_ExpatBuilderÚ__init__Ú
forbid_dtdÚforbid_entitiesÚforbid_external)ÚselfÚoptionsr   r   r   © r   úZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/defusedxml/expatbuilder.pyr      s    zDefusedExpatBuilder.__init__c                 C   s   t |||ƒ‚d S r   )r   )r   ÚnameÚsysidÚpubidZhas_internal_subsetr   r   r   Údefused_start_doctype_decl   s    z.DefusedExpatBuilder.defused_start_doctype_declc                 C   s   t ||||||ƒ‚d S r   ©r   )r   r   Zis_parameter_entityÚvalueÚbaser   r   Únotation_namer   r   r   Údefused_entity_decl    s    z'DefusedExpatBuilder.defused_entity_declc                 C   s   t |d ||||ƒ‚d S r   r   )r   r   r   r   r   r   r   r   r   Údefused_unparsed_entity_decl%   s    z0DefusedExpatBuilder.defused_unparsed_entity_declc                 C   s   t ||||ƒ‚d S r   )r	   )r   Úcontextr   r   r   r   r   r   Ú#defused_external_entity_ref_handler)   s    z7DefusedExpatBuilder.defused_external_entity_ref_handlerc                 C   sB   t  | |¡ | jr| j|_| jr0| j|_| j|_	| j
r>| j|_d S r   )r   Úinstallr   r   ÚStartDoctypeDeclHandlerr   r   ÚEntityDeclHandlerr   ÚUnparsedEntityDeclHandlerr   r    ÚExternalEntityRefHandler©r   Úparserr   r   r   r!   ,   s    zDefusedExpatBuilder.install)NFTT)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r    r!   r   r   r   r   r
      s    ÿ
r
   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚDefusedExpatBuilderNSz2Defused document builder that supports namespaces.c                 C   s    t  | |¡ | jjr| j|_d S r   )r
   r!   Ú_optionsZnamespace_declarationsZstart_namespace_decl_handlerÚStartNamespaceDeclHandlerr&   r   r   r   r!   <   s    zDefusedExpatBuilderNS.installc                 C   s   t  | ¡ |  ¡  d S r   )r
   ÚresetZ_initNamespaces)r   r   r   r   r/   A   s    
zDefusedExpatBuilderNS.resetN)r(   r)   r*   r+   r!   r/   r   r   r   r   r,   9   s   r,   TFc           	      C   sb   |r
t }nt}||||d�}t| tƒrTt| dƒ}z| |¡}W | ¡  q^| ¡  0 n
| | ¡}|S )z{Parse a document, returning the resulting Document node.

    'file' may be either a file name or an open file object.
    ©r   r   r   Úrb)r,   r
   Ú
isinstanceÚstrÚopenÚ	parseFileÚclose)	ÚfileÚ
namespacesr   r   r   Úbuild_builderÚbuilderÚfpÚresultr   r   r   ÚparseF   s    ÿ


r=   c                 C   s&   |r
t }nt}||||d�}| | ¡S )zOParse a document from a string, returning the resulting
    Document node.
    r0   )r,   r
   ÚparseString)Ústringr8   r   r   r   r9   r:   r   r   r   r>   ^   s    ÿr>   N)TFTT)TFTT)r+   Ú
__future__r   r   Zxml.dom.expatbuilderr   r   r   Z_NamespacesÚcommonr   r   r	   Ú
__origin__r
   r,   r=   r>   r   r   r   r   Ú<module>   s   '
 ÿ