ó
šxTc           @   sý   d  d l  Z  d  d l Z d „  Z d e _ e d e j g ƒ e _ d Z e j ƒ  Z d e	 f d „  ƒ  YZ
 d „  Z d	 e	 f d
 „  ƒ  YZ d e	 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d „  Z d e	 f d „  ƒ  YZ d a d „  Z d S(   iÿÿÿÿNc         C   s
   |  j  ƒ  S(   N(   t   read(   t   stream(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyt   simple   s    t   identityt    s2   HTTPInterface/0.0.2 +http://www.phenix-online.org/t   Downloadc           B   s   e  Z i  i  e d  „ Z RS(   c         C   s¨   t  j d | d t j | ƒ d t | j ƒ  d t f d | j f g ƒ ƒ } t j	 | ƒ } | j
 j d d ƒ j ƒ  | j k r’ t d | j ‚ n  | d	 | ƒ |  _ d  S(
   Nt   urlt   datat   headerss
   User-Agents   Accept-encodings   Content-EncodingR   s$   Service does not support encoding %sR   (   t   urllib2t   Requestt   urllibt	   urlencodet   dictt   itemst   AGENTt   ENCODINGt   OPENERt   openR   t   gett   lowert   ACCEPTt   RuntimeErrorR   (   t   selfR   R   R   t   methodt   requestR   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyt   __init__   s    		$(   t   __name__t
   __module__R   R   (    (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyR      s   c         C   s/   y t  j |  ƒ } Wn t j k
 r* t SXt S(   N(   R   R   R	   t   URLErrort   Falset   True(   R   R   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyt	   is_online'   s
    t   RCSBHTTPc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s.   
    Interface to RCSB service using HTTP
    c         C   sD   t  d k r t d t  ‚ n  t d d ƒ s7 t d ‚ n  t  |  _  d  S(   Nt   pdbt   fastas   Unknown format: %sR   s$   http://www.rcsb.org/pdb/home/home.dos   Cannot contact RCSB service(   s   pdbR#   (   t   formatt
   ValueErrorR    R   (   R   t
   identifier(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyR   7   s
    c         C   sa   y7 t  d d d i |  j d 6d d 6| d 6d t ƒ } Wn# t j k
 r\ } t d	 | ‚ n X| S(
   NR   s0   http://www.rcsb.org/pdb/download/downloadFile.doR   t
   fileFormatt   NOt   compressiont   structureIdR   s   Unknown identifier: %s(   R   R$   R   R	   R   R%   (   R   R&   t   resultt   e(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyt   fetch_singleB   s    

c         C   s   d S(   Ns   RCSB HTTP service(    (   R   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyt   __str__U   s    (   R   R   t   __doc__R   R-   R.   (    (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyR!   2   s   		t   DbfetchHTTPc           B   sQ   e  Z d  Z i e d d d d g ƒ d 6Z d „  Z d „  Z d „  Z d „  Z RS(	   s5   
    Interface to EBI Dbfetch service using HTTP
    R"   t   pdbmlt   mmcifR#   c         C   s}   | |  j  k r t d | ‚ n  | |  j  | k rB t d | ‚ n  t d d ƒ sg t d t |  ƒ ‚ n  | |  _ | |  _ d  S(   Ns   Unknown database: %ss   Unknown format: %sR   s$   http://www.ebi.ac.uk/cgi-bin/dbfetchs   Cannot contact %s(   t   FORMATS_FORR%   R    R   t   strt   databaseR$   (   R   R5   R$   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyR   c   s    	c         C   s   |  j  d | g ƒ S(   Nt   identifiers(   t   fetch_multiple(   R   R&   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyR-   r   s    c         C   sh   t  d d d i |  j d 6d j t | ƒ ƒ d 6|  j d 6d d	 6ƒ } | j j d
 ƒ rd d | _ n  | S(   NR   s*   http://www.ebi.ac.uk/Tools/dbfetch/dbfetchR   t   dbt   ,t   idR$   t   rawt   stylet   ERRORR   (   R   R5   t   joint   setR$   R   t
   startswith(   R   R6   R+   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyR7   w   s    

c         C   s   d S(   Ns   EBI DbFetch service(    (   R   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyR.   ‰   s    (	   R   R   R/   R?   R3   R   R-   R7   R.   (    (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyR0   Z   s   			t   SequenceFetchc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s.   
    Uses a proxy to access sequence data
    c         C   s(   | |  _  | |  _ | |  _ i  |  _ d  S(   N(   t   proxyR$   t   headert   cache(   R   RB   R$   RC   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyR   “   s    			c         C   s-   |  j  d g  | D] } | j ƒ  ^ q ƒ d  S(   NR6   (   t   fetch_and_cachet   upper(   R   R6   t   i(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyt   prefetch›   s    c         C   s   |  j  d | ƒ j | ƒ S(   NR&   (   t   fetch_entryR   (   R   R&   t   chain(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyt   fetch_chain    s    c         C   s<   | j  ƒ  } | |  j k r1 |  j d | g ƒ n  |  j | S(   NR6   (   RF   RD   RE   (   R   R&   t   std(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyRI   ¥   s    c   	      C   s)  d d  l  } t g  | D] } | i  f ^ q ƒ } |  j j d | ƒ } y% | j j d | j d |  j ƒ } Wn' t k
 r” } t d | j	 d  ‚ n Xx} | D]u } y | j
 d |  j ƒ Wn# t k
 rÞ } t d | j	 ‚ n X| j j | k s÷ t ‚ | | | j j | j j <qœ W|  j j | ƒ d  S(	   NiÿÿÿÿR6   R   R$   s'   Incorrect format: expected %s, found %si   RC   s.   Incorrect header format: expected %s, found %s(   t   iotbx.bioinformaticsR   RB   R7   t   bioinformaticst   parse_sequence_strR   R$   R%   t   argst   reinterpret_headerRC   R&   t   AssertionErrorRJ   RD   t   update(	   R   R6   t   iotbxRG   t   sequences_forR+   t	   sequencesR,   t   s(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyRE   ¯   s"    %	(   R   R   R/   R   RH   RK   RI   RE   (    (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyRA   Ž   s   				
t   PDBFetchc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s&   
    Uses a proxy to get PDB data
    c         C   s   | |  _  d  S(   N(   RB   (   R   RB   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyR   Ñ   s    c         C   sI   d d  l  } |  j j d | ƒ } | j j d | j d d ƒ } | j ƒ  S(   NiÿÿÿÿR&   t   linest   source_infot   PDB(   t	   iotbx.pdbRB   R-   R"   t   inputR   t   construct_hierarchy(   R   R&   RT   t   responseR]   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyRI   Ö   s    c         C   s;   |  j  d | ƒ } | j ƒ  j d | ƒ } | j | t ƒ S(   NR&   s
   chain '%s'(   RI   t   atom_selection_cachet	   selectiont   selectR   (   R   R&   RJ   t   roott   asc(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyRK   Þ   s    (   R   R   R/   R   RI   RK   (    (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyRX   Ì   s   		c         C   s€   d d  l  } | j d | j | j Bƒ } i  } xK | j |  ƒ D]: } | j ƒ  \ } } | rh | j ƒ  n d  | | j ƒ  <q> W| S(   Niÿÿÿÿsp   
        ^ OBSLTE \s+
        [\w-]+ [ ]+
        ( \w{4} )
        (?: [ ]+ ( \w{4} ) )?
        \s* $
        (   t   ret   compilet   VERBOSEt	   MULTILINEt   finditert   groupsRF   t   None(   R   Re   t   regext   replacement_fort   hitt   oldt   new(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyt   parse_pdb_redirectionså   s    &t   PDBRedirectionsc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s7   
    Downloads a list of redirections from the PDB
    c         C   sL   y( t  d d ƒ } t d | j ƒ |  _ Wn t j k
 rG i  |  _ n Xd  S(   NR   s4   ftp://ftp.wwpdb.org/pub/pdb/data/status/obsolete.datR   (   R   Rq   R   t   redirection_forR	   R   (   R   t   download(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyR     s    	c         C   s&   | j  ƒ  } | |  j k o% |  j | S(   N(   RF   Rs   (   R   R&   RL   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyt	   obsoleted  s    c         C   s   | j  ƒ  } |  j | S(   N(   RF   Rs   (   R   R&   RL   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyRm     s    c         C   s'   | j  ƒ  } | |  j k o& |  j | S(   N(   RF   Rs   (   R   R&   RL   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyt	   retracted  s    c         C   s   t  |  j ƒ S(   N(   t   lenRs   (   R   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyt   count  s    (   R   R   R/   R   Ru   Rm   Rv   Rx   (    (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyRr   ü   s   				c           C   s   t  s t ƒ  a  n  t  S(   N(   t   REDIRECTIONSRr   (    (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyt   get_pdb_redirections&  s    (   R   R	   R   R   R?   R   R   t   build_openerR   t   objectR   R    R!   R0   RA   RX   Rq   Rr   Rk   Ry   Rz   (    (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/proxy.pyt   <module>   s    			(4>	(