ó
´ZÄIc           @   s˝   d  Z  d d l Z d d l m Z d e f d     YZ d e f d     YZ d e	 f d	     YZ
 d
 e f d     YZ d e f d     YZ d e f d     YZ d d d     YZ d S(   s   Parser for XML results returned by NCBI's Entrez Utilities. This
parser is used by the read() function in Bio.Entrez, and is not intended
be used directly.
i˙˙˙˙N(   t   expatt   IntegerElementc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyR   ,   s    t   StringElementc           B   s   e  Z RS(    (   R   R   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyR   .   s    t   UnicodeElementc           B   s   e  Z RS(    (   R   R   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyR   0   s    t   ListElementc           B   s   e  Z RS(    (   R   R   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyR   2   s    t   DictionaryElementc           B   s   e  Z RS(    (   R   R   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyR   4   s    t   StructureElementc           B   s   e  Z d    Z d   Z RS(   c         C   s>   t  j |   x! | D] } t  j |  | g   q W| |  _ d  S(   N(   t   dictt   __init__t   __setitem__t   listkeys(   t   selft   keyst   key(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyR
   :   s    c         C   s:   | |  j  k r# |  | j |  n t j |  | |  d  S(   N(   R   t   appendR	   R   (   R   R   t   value(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyR   ?   s    (   R   R   R
   R   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyR   9   s   	t   DataHandlerc           B   sG   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   sU   g  |  _  g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ i  |  _ g  |  _ | |  _ d  S(   N(	   t   stackt   errorst   integerst   stringst   listst   dictionariest
   structurest   itemst   dtd_dir(   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyR
   G   s    								c         C   s~   t  j   |  _ |  j j t  j  |  j |  j _ |  j |  j _ |  j	 |  j _
 |  j |  j _ |  j j |  d |  _ |  j S(   s2   Set up the parser and let it parse the XML resultsN(   R    t   ParserCreatet   parsert   SetParamEntityParsingt   XML_PARAM_ENTITY_PARSING_ALWAYSt   startElementt   StartElementHandlert
   endElementt   EndElementHandlert
   characterst   CharacterDataHandlert   external_entity_ref_handlert   ExternalEntityRefHandlert	   ParseFilet   Nonet   object(   R   t   handle(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyt   runR   s    	c         C   sŘ  d |  _  | |  j k r$ t   } n| |  j k r? t   } n| |  j k rd t |  j |  } nÜ | |  j k rt | d  } | d =t | d  } | d =| d k rš t   } nB | d k rÚ t d d g  } n! | d	 k rň t   } n	 t	   } | | _
 | | _ n0 | |  j |  j |  j k r:| |  _ d  Sd } | d k rÄ| | _ | rmt |  | _ n  t |  j  d
 k rÄ|  j d } y | j |  WqÁt k
 r˝| | | <qÁXqÄn  |  j j |  d  S(   Nt    t   Namet   Typet	   Structuret
   ArticleIdst   Historyt   pubmedt   medlinet   Listi    i˙˙˙˙(   R1   R2   (   t   contentR   R   R   R   R   R   R   t   strR   t   itemnamet   itemtypeR   R   R   t
   attributest   tagR	   t   lenR   R   t   AttributeError(   R   t   namet   attrsR*   R9   t   current(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyR    ^   sH    					c         C   są  |  j  } | |  j k r7 | d k r( d  St |   n| |  j k rU t |  } nď | |  j k r y t |  } WqDt k
 r t |  } qDXn­ | |  j	 k r.|  j
 j   |  _ |  j j d k rÎ d  S|  j j d k rď t |  } n0 y t |  } Wn t k
 rt |  } n X|  j j } n |  j
 j   |  _ d  S| | _ |  j rqt |  j  | _ |  ` n  |  j
 d } y | j |  Wn t k
 rŹ| | | <n Xd  S(   NR-   R5   R0   t   Integeri˙˙˙˙(   R5   R0   (   R6   R   t   RuntimeErrorR   R   R   R   t   UnicodeEncodeErrorR   R   R   t   popR*   R9   R8   R;   R:   R	   R   R=   (   R   R>   R   R@   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyR"      sD    				c         C   s   |  j  | 7_  d  S(   N(   R6   (   R   R6   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyR$   °   s    c            s$  | j    d k r& |  j j |  d S| d k r | t j j t j j d t j j t j j	 d d f f f k r |  j
 j |  d Sxl | d t j j t j j f k ró | d t j j	 t j j f k ró t | d  d k ró | d d } q W| d t j j t j j f k r*|  j j |  d S| d t j j t j j f k r| d t j j t j j f k r|  j j |  d Sg   g       f d       |  t   d k rät   d k rä|  j j |  n< t   d k r	|  j j |  n |  j j i  | 6 d S(	   s*  This callback function is called for each element declaration:
        <!ELEMENT       name          (...)>
        encountered in a DTD. The purpose of this function is to determine
        whether this element should be regarded as a string, integer, list
        dictionary, structure, or error.t   ERRORNt   Itemi    i   i   c            ső   |  d \ } } } | d  k r | t j j t j j f k rb x= | D] }  j | d  qD Wqń x | D] }   |  qi Wnq | j   d k rń | t j j t j j f k rŔ  j |  qń | t j j t j j f k rń  j |  qń n  d  S(   Ni   i   RE   (	   R)   R    t   modelt   XML_CQUANT_PLUSt   XML_CQUANT_REPR   t   uppert   XML_CQUANT_NONEt   XML_CQUANT_OPT(   RG   t
   quantifierR>   t   childrent   child(   t   countt   multiplet   single(    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyRP   č   s    (    (   RJ   R   R   R    RG   t   XML_CTYPE_MIXEDRI   R)   t   XML_CTYPE_NAMERK   R   t   XML_CTYPE_SEQt   XML_CTYPE_CHOICERL   R<   t   XML_CTYPE_EMPTYR   RH   R   R   R   t   update(   R   R>   RG   (    (   RP   RQ   RR   s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyt   elementDeclł   sH    		
$c         C   sŤ   t  j j |  \ } } t  j j |  j |  } y t |  } Wn9 t k
 r{ d | | | |  j | f }	 t |	   n X|  j j	 |  }
 |  j
 |
 _ |
 j |  d S(   s°  The purpose of this function is to load the DTD locally, instead
        of downloading it from the URL specified in the XML. Using the local
        DTD results in much faster parsing. If the DTD is not found locally,
        we try to download it. In practice, this may fail though, if the XML
        relies on many interrelated DTDs. If new DTDs appear, putting them in
        Bio/Entrez/DTDs will allow the parser to see them.sź  Unable to load DTD file %s.

Bio.Entrez uses NCBI's DTD files to parse XML files returned by NCBI Entrez.
Though most of NCBI's DTD files are included in the Biopython distribution,
sometimes you may find that a particular DTD file is missing. In such a
case, you can download the DTD file from NCBI and install it manually.

Usually, you can find missing DTD files at either
    http://www.ncbi.nlm.nih.gov/dtd/
or
    http://eutils.ncbi.nlm.nih.gov/entrez/query/DTD/
If you cannot find %s there, you may also try to search
for it with a search engine such as Google.

Please save %s in the directory
%s
in order for Bio.Entrez to find it.
Alternatively, you can save %s in the directory
Bio/Entrez/DTDs in the Biopython distribution, and reinstall Biopython.

Please also inform the Biopython developers by sending an email to
biopython-dev@biopython.org to inform us about this missing DTD, so that we
can include it with the next release of Biopython.
i   (   t   ost   patht   splitt   joinR   t   opent   IOErrorRB   R   t   ExternalEntityParserCreateRY   t   ElementDeclHandlerR(   (   R   t   contextt   baset   systemIdt   publicIdt   locationt   filenameR[   R+   t   messageR   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyR&     s    (	   R   R   R
   R,   R    R"   R$   RY   R&   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyR   E   s   			)	)		N(    (   t   __doc__t   os.pathRZ   t   xml.parsersR    t   intR   R7   R   t   unicodeR   t   listR   R	   R   R   R   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Entrez/Parser.pyt   <module>	   s   