ó
æ™xTc           @   s²   d  d l  m Z d  d l m Z m Z m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z d  d l Z d d d	 „ Z d
 d d „ Z d „  Z d „  Z e d k r® e ƒ  n  d S(   iÿÿÿÿ(   t   division(   t   escape_sh_double_quotedt	   gzip_opent   bz2_open(   t   easy_run(   t   show_string(   t   StringIONt   rt   rbc         C   s  | d k s t  ‚ | d k s$ t  ‚ t j j |  ƒ }  |  j d ƒ rX t d |  d | ƒ S|  j d ƒ r– t t j d d t	 |  ƒ d	 t
 ƒ j ƒ  j ƒ S|  j d
 ƒ r¸ t d |  d | ƒ Sy t |  | ƒ SWn7 t k
 r} t d t |  ƒ d t | ƒ ƒ ‚ n Xd  S(   NR   R   s   .gzt	   file_namet   modes   .Zt   commands   gunzip -c "%s"t   stdout_splitliness   .bz2s!   Cannot open file for reading: %s
s     (   R   s   rb(   R   s   rb(   t   AssertionErrort   ost   patht
   expandusert   endswithR   R   R   t   fully_bufferedR   t   Falset   raise_if_errorst   stdout_bufferR   t   opent   IOErrorR   t   str(   R	   R
   t	   gzip_modet   e(    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/smart_open.pyt   for_reading   s     t   wt   wbc         C   s§   | d
 k s t  ‚ | d k s$ t  ‚ t j j |  ƒ }  |  j d ƒ rX t d |  d | ƒ Sy t |  | ƒ SWn7 t k
 r¢ } t d t |  ƒ d	 t	 | ƒ ƒ ‚ n Xd  S(   NR   R   t   at   abs   .gzR	   R
   s!   Cannot open file for writing: %s
s     (   R   s   wbR   R   (   R   s   wbR   R   (
   R   R   R   R   R   R   R   R   R   R   (   R	   R
   R   R   (    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/smart_open.pyt   for_writing   s    c         C   sZ   | d
 k s t  ‚ t j j |  ƒ }  | d d k rG t d |  d	 | ƒ St d |  d	 | ƒ S(   NR   R   R   R   R   R   i    R	   R
   (   R   s   rbR   s   wbR   s   ab(   R   R   R   R   R   R    (   R	   R
   (    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/smart_open.pyt   file(   s
    c          C   sƒ   d d  l  }  xE |  j d D]6 } t d | ƒ j ƒ  j ƒ  d d d g k s t ‚ q Wt d d ƒ d IJt d d ƒ d IJd	 GHd  S(
   Niÿÿÿÿi   R	   s   line 1s   line 2s   the endt	   tmp_plains   tmp.gzt   OK(   t   syst   argvR   t   readt
   splitlinesR   R    (   R$   R	   (    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/smart_open.pyt   exercise/   s    t   __main__(   t
   __future__R    t   libtbx.utilsR   R   R   t   libtbxR   t   libtbx.str_utilsR   t	   cStringIOR   R   R   R    R!   R(   t   __name__(    (    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/smart_open.pyt   <module>   s   			