ó
Ý™xTc           @   s‘  d  d l  m Z d  d l  m Z d  d l Z d  d l Z d „  Z e e j d ƒ s€ e j d k rq d e j _	 q€ d e j _	 n  d	 e
 k r« d d e d
 „ Z e e
 d	 <n  d e
 k rÍ d „  Z e e
 d <n  e j d  Z e d' k  rBd  d l Z e d ƒ Z d „  e _ d „  e _ d „  e _ d  d l Z d e f d „  ƒ  YZ e e _ e d( k rzd  d l Z d „  Z e e _ n  e d) k r»d e
 k r»d  d l Z e j e
 d <e j e
 d <n  e d* d+ d, g k rBe e d ƒ rBd e f d „  ƒ  YZ d e e f d „  ƒ  YZ  d  e e! f d! „  ƒ  YZ" e  e
 d <e" e
 d <qBn  [ d" e
 k rgd# „  Z# e# e
 d" <n  d$ e f d% „  ƒ  YZ$ d& „  Z% e% ƒ  d S(-   iÿÿÿÿ(   t   division(   t
   generatorsNc         C   s  y t  j |  SWn t k
 r" n Xd d l } | j |  ƒ rf y | j |  ƒ SWqf t k
 rb qf Xn  t  j } | j ƒ  x{ | D]s } y" | j	 |  | g ƒ \ } } } Wn t
 k
 r¼ q� Xz | j |  | | | ƒ SWd | d k	 ró | j ƒ  n  Xq� Wt d |  ƒ ‚ d S(   sC   Work around undesired behavior of Python's relative import feature.iÿÿÿÿNs   Cannot import %s module.(   t   syst   modulest   KeyErrort   impt
   is_builtint   init_builtint	   Exceptiont   patht   reverset   find_modulet   ImportErrort   load_modulet   Nonet   closet   RuntimeError(   t   nameR   t   sys_pathR	   t   fpt   pathnamet   description(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyt   stdlib_import   s,      

" t   devnullt   ntt   nuls	   /dev/nullt   sortedc         C   s«   | d k	 r4 g  |  D] } | | ƒ | f ^ q } n t |  ƒ } | d k rY | j ƒ  n | j | ƒ | d k	 r” g  | D] \ } } | ^ qy } n  | r§ | j ƒ  n  | S(   sG   sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted listN(   R   t   listt   sortR
   (   t   iterablet   cmpt   keyR
   t   xt   resultt   t0t   t1(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyR   &   s    ("t   reversedc         c   sT   t  |  d ƒ s t |  ƒ }  n  t |  ƒ } x# | d k rO | d 8} |  | Vq- Wd S(   sÍ    Return a reverse iterator. seq must be an object which supports
    the sequence protocol (the __len__() method and the __getitem__() method
    with integer arguments starting at 0). New in version 2.4. t   __getitem__i    i   N(   t   hasattrR   t   len(   t   seqt   i(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyR$   <   s    
i   i   t   mathc         C   s   t  j |  j |  j ƒ S(   N(   R*   t   atan2t   imagt   real(   t   z(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyt   <lambda>M   s    c         C   s   t  |  ƒ t j |  ƒ f S(   N(   t   abst   cmatht   phase(   R.   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyR/   N   s    c         C   s$   |  t  j | ƒ |  t  j | ƒ f S(   N(   R*   t   cost   sin(   t   rt   phi(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyR/   O   s    t   catch_warningsc           B   s8   e  Z d  Z e d d „ Z d „  Z d „  Z d „  Z RS(   s£  A context manager that copies and restores the warnings filter upon
      exiting the context.

      The 'record' argument specifies whether warnings should be captured by a
      custom implementation of warnings.showwarning() and be appended to a list
      returned by the context manager. Otherwise None is returned by the context
      manager. The objects appended to the list are arguments whose attributes
      mirror the arguments to showwarning().

      The 'module' argument is to specify an alternative module to the module
      named 'warnings' and imported under that name. This argument is only useful
      when testing the warnings module itself.

      c         C   s>   | |  _  | d k r( t j d |  _ n	 | |  _ t |  _ d S(   sò   Specify whether to record warnings and if an alternative module
          should be used other than sys.modules['warnings'].

          For compatibility with Python 3.0, please consider all arguments to be
          keyword-only.

          t   warningsN(   t   _recordR   R   R   t   _modulet   Falset   _entered(   t   selft   recordt   module(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyt   __init__d   s
    		c         C   sr   g  } |  j  r | j d ƒ n  |  j t j d k	 rL | j d |  j ƒ n  t |  ƒ j } d | d j | ƒ f S(   Ns   record=TrueR8   s	   module=%rs   %s(%s)s   , (   R9   t   appendR:   R   R   t   typet   __name__t   join(   R=   t   argsR   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyt   __repr__s   s    	c            s‰   |  j  r t d |  ƒ ‚ n  t |  _  |  j j |  _ |  j |  j _ |  j j |  _ |  j r� g  ‰  ‡  f d †  } | |  j _ ˆ  Sd  Sd  S(   Ns   Cannot enter %r twicec             s   ˆ  j  t |  | Ž  ƒ d  S(   N(   RA   t   WarningMessage(   RE   t   kwargs(   t   log(    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyt   showwarning…   s    (
   R<   R   t   TrueR:   t   filterst   _filtersRJ   t   _showwarningR9   R   (   R=   RJ   (    (   RI   sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyt	   __enter__|   s    			c         G   s>   |  j  s t d |  ƒ ‚ n  |  j |  j _ |  j |  j _ d  S(   Ns%   Cannot exit %r without entering first(   R<   R   RM   R:   RL   RN   RJ   (   R=   t   exc_info(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyt   __exit__Œ   s    	N(	   RC   t
   __module__t   __doc__R;   R   R@   RF   RO   RQ   (    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyR7   S   s
   			c          o   s¤   | j  d ƒ } | g t |  ƒ d j d „ } t j | ƒ } g  |  D] } t j | | ƒ  | ƒ ^ qE } y# x t j | Œ  D] } | Vq| WWn t k
 rŸ n Xd S(   s4   Make an iterator that aggregates elements from each of the iterables.
      If the iterables are of uneven length, missing values are filled-in with
      fillvalue. Iteration continues until the longest iterable is exhausted.
      Synopsis: izip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
      t	   fillvaluei   c         s   s   |  ƒ  Vd  S(   N(    (   t   counter(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyt   sentinel�   s    N(   t   getR'   t   popt	   itertoolst   repeatt   chaint   izipt
   IndexError(   RE   t   kwdsRT   RV   t   fillerst   itt   iterst   tup(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyt   izip_longest–   s     +i   t   sett	   frozenseti   i   t
   isdisjointt   forward_compatibility_set_mixinc           B   s   e  Z d  „  Z RS(   c         C   s%   x | D] } | |  k r t  Sq Wt S(   N(   R;   RK   (   R=   t   othert   value(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyRf   ²   s    (   RC   RR   Rf   (    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyRg   ±   s   t   forward_compatibility_frozensetc           B   s   e  Z RS(    (   RC   RR   (    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyRj   ·   s   t   forward_compatibility_setc           B   s   e  Z RS(    (   RC   RR   (    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyRk   ¹   s   t   allc         C   s   x |  D] } | s t  Sq Wt S(   N(   R;   RK   (   R   t   element(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyRl   Â   s    t   _advertise_subprocessc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   t   function_idt   target(   R=   Ro   Rp   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyR@   Í   s    	c         O   sŽ   t  j j d ƒ r~ d d  l } | j j s9 | j j ƒ  r~ d „  } | ƒ  s{ d d l m } | d d |  j	 d d ƒ q{ q~ n  |  j
 | | Ž  S(	   Nt   LIBTBX_BUILDiÿÿÿÿc          S   sv  d d l  m }  d } xYt rqy |  | ƒ } Wn t k
 rC Pq X| j j } xt rct j j | ƒ \ } } t	 | ƒ d k s• t	 | ƒ d k r™ Pn  | j
 ƒ  } | j d ƒ sÀ | d k r&t j j | ƒ sÖ t Sx� d d d	 d
 d g D]/ } t j j t j j | | d ƒ ƒ sì Pqì qì Wt Sn4 | d k rZt j j t j j | d ƒ ƒ rZt Sn  | } qS W| d 7} q Wt S(   Niÿÿÿÿ(   t	   _getframei   i    t   pythont   libt   ost   StringIOt   UserDictt   UserListt
   UserStrings   .pyt   sconss   SConsign.py(   R   Rr   RK   t
   ValueErrort   f_codet   co_filenameRu   R	   t   splitR'   t   lowert
   startswitht   isdirt   isfileRD   R;   (   Rr   t   frames_backt   ft   pt   dt   bt   n(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyt   is_exceptionÖ   s6    	  	$ %!
(   t   warnt   messagesL   %s is not safe: please use the subprocess module or libtbx.easy_run instead.t
   stackleveli   (   Ru   t   environt   has_keyt   libtbx.load_envt   envt   full_testingt   is_development_environmentR8   RŠ   Ro   Rp   (   R=   RE   RH   t   libtbxR‰   RŠ   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyt   __call__Ñ   s    		
(   RC   RR   R@   R”   (    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyRn   Ë   s   	c          C   sŠ   xƒ d d d d d d d d d	 d
 d d d g D]T }  t  t |  d  ƒ } | d  k	 r. t d d |  d d | ƒ } t t |  | ƒ q. q. Wd  S(   Nt   systemt   popent   popen2t   popen3t   popen4t   spawnlt   spawnlet   spawnlpt   spawnlpet   spawnvt   spawnvet   spawnvpt   spawnvpeRo   s   os.s   ()Rp   (   t   getattrRu   R   Rn   t   setattr(   t   fnR„   t   w(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyt   _install_advertise_subprocessù   s    (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (&   t
   __future__R    R   R   Ru   R   R&   R	   R   R   t   __builtins__R   R;   R   R$   t   version_infot	   vers_infoR1   R*   R2   t   polart   rectR8   t   objectR7   RY   Rc   t   setst   Sett   ImmutableSetRe   Rg   Rj   Rd   Rk   Rl   Rn   R¦   (    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/forward_compatibility.pyt   <module>   s^   		
?		
	.	
