³ò
™›\Kc           @   s‚  d  Z  d d g Z d d k Z e i d e d d ƒd Z d	 Z d
 Z d Z d Z	 d Z
 d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d  Z d! Z d" Z  e! ƒ  Z" h  a# d# „  Z$ d$ Z% d% Z& d& d' „ Z' d& d( „ Z( d) „  Z) d* „  Z* d+ „  Z+ d, „  Z, d- „  Z- d. „  Z. d/ „  Z/ d0 „  Z0 e1 d1 j o e0 ƒ  n d S(2   s!   Gopher protocol client interface.t   send_selectort
   send_queryiÿÿÿÿNs"   the gopherlib module is deprecatedt
   stackleveli   s   1/s   gopher.micro.umn.eduiF   t   0t   1t   2t   3t   4t   5t   6t   7t   8t   9t   +t   st   et   ct   ht   Tt   Mt   It   wt   qt   gt   :t   ;t   <c         C   so   t  h  j o> x; t D]/ } | d  d j o | d t  t | ƒ <q q Wn |  t  j o t  |  Sn d |  f S(   s=   Map all file types to strings; unknown types become TYPE='x'.i   t   A_s   TYPE=%r(   t   _type_to_name_mapt   _namest   eval(   t   gtypet   name(    (    s   /usr/lib/python2.5/gopherlib.pyt   type_to_name-   s      s   
s   	i    c         C   sæ   d d k  } | pC | i d ƒ } | d j o# | |  t | | d ƒ } } qV n | p
 t } n* t | ƒ t d ƒ j o t | ƒ } n | i  | i | i ƒ } | i | | f ƒ | i |  t	 ƒ | i
 d ƒ | i d ƒ S(   sG   Send a selector to a given host and port, return a file with the reply.iÿÿÿÿNR   i    i   t    t   rb(   t   sockett   findt   intt   DEF_PORTt   typet   AF_INETt   SOCK_STREAMt   connectt   sendallt   CRLFt   shutdownt   makefile(   t   selectort   hostt   portR$   t   iR   (    (    s   /usr/lib/python2.5/gopherlib.pyR    <   s    '
c         C   s   t  |  d | | | ƒ S(   s#   Send a selector and a query string.s   	(   R    (   R0   t   queryR1   R2   (    (    s   /usr/lib/python2.5/gopherlib.pyR   M   s    c         C   s!   |  d j o d Sn	 |  d Sd S(   sJ   Takes a path as returned by urlparse and returns the appropriate selector.t   /i   N(    (   t   path(    (    s   /usr/lib/python2.5/gopherlib.pyt   path_to_selectorQ   s    c         C   s'   |  d j o d Sn t  |  d ƒ Sd S(   sj   Takes a path as returned by urlparse and maps it to a string.
    See section 3.4 of RFC 1738 for details.R5   s   TYPE='unknown'i   N(   R!   (   R6   (    (    s   /usr/lib/python2.5/gopherlib.pyt   path_to_datatype_nameX   s    c      	   C   s=  g  } x0|  i  ƒ  } | p
 d GHPn | d t j o | d  } n  | d t j o | d  } n | d j o Pn | p d GHq	 n | d } | d i t ƒ } t | ƒ d j  o d	 | f GHq	 n t | ƒ d j o- | d d
 g j o d G| d Gd GHqn | i d ƒ | i d | ƒ | i | ƒ q	 | S(   s1   Get a directory in the form of a list of entries.s   (Unexpected EOF from server)iþÿÿÿiÿÿÿÿt   .s   (Empty line from server)i    i   i   s   (Bad line from server: %r)R   s   (Extra info from server:t   )R"   (   t   readlineR-   t   splitt   TABt   lent   appendt   insert(   t   ft   entriest   lineR   t   parts(    (    s   /usr/lib/python2.5/gopherlib.pyt   get_directoryd   s8    
c         C   s   g  } t  |  | i ƒ | S(   s@   Get a text file as a list of lines, with trailing CRLF stripped.(   t   get_alt_textfileR?   (   RA   t   lines(    (    s   /usr/lib/python2.5/gopherlib.pyt   get_textfile„   s    c         C   s    x™ |  i  ƒ  } | p
 d GHPn | d t j o | d  } n  | d t j o | d  } n | d j o Pn | d  d j o | d } n | | ƒ q d S(	   sN   Get a text file and pass each line to a function, with trailing CRLF stripped.s   (Unexpected EOF from server)iþÿÿÿiÿÿÿÿR9   i   s   ..i   N(   R;   R-   (   RA   t   funcRC   (    (    s   /usr/lib/python2.5/gopherlib.pyRF   Š   s    c         C   s   |  i  ƒ  } | S(   s*   Get a binary file as one solid data block.(   t   read(   RA   t   data(    (    s   /usr/lib/python2.5/gopherlib.pyt
   get_binary›   s    c         C   s/   x( |  i  | ƒ } | p Pn | | ƒ q d S(   s4   Get a binary file and pass each block to a function.N(   RJ   (   RA   RI   t	   blocksizeRK   (    (    s   /usr/lib/python2.5/gopherlib.pyt   get_alt_binary    s
    c          C   sÐ  d d k  }  d d k } | i |  i d d ƒ \ } } t } | d } t } | o | d } | d } n | oŠ | d } | d } t | ƒ d j o | d | } } n& d } | o | d } | d } n d } | o | d } | d } qý n | t j o t | | | ƒ } n t | | ƒ } | t	 j o& t
 | ƒ }	 x |	 D] }
 |
 GHqOWnk | t t f j o& t | ƒ } xH | D] }
 |
 GHqˆWn2 t | ƒ } d Gt | ƒ Gd Gt | d  ƒ d	  GHd S(
   s   Trivial test program.iÿÿÿÿNi   R"   i    s   binary data:s   bytes:id   i(   (   t   syst   getoptt   argvt   DEF_SELECTORt   DEF_HOSTR>   t   A_INDEXR   R    t   A_TEXTRH   t   A_MENURE   RL   t   repr(   RO   RP   t   optst   argsR0   R(   R1   R4   RA   RG   t   itemRB   RK   (    (    s   /usr/lib/python2.5/gopherlib.pyt   test¨   sJ    





    t   __main__(2   t   __doc__t   __all__t   warningst   warnt   DeprecationWarningRR   RS   R'   RU   RV   t   A_CSOt   A_ERRORt   A_MACBINHEXt
   A_PCBINHEXt   A_UUENCODEDRT   t   A_TELNETt   A_BINARYt   A_DUPLICATEt   A_SOUNDt   A_EVENTt
   A_CALENDARt   A_HTMLt   A_TN3270t   A_MIMEt   A_IMAGEt   A_WHOISt   A_QUERYt   A_GIFt   A_WWWt   A_PLUS_IMAGEt   A_PLUS_MOVIEt   A_PLUS_SOUNDt   dirR   R   R!   R-   R=   R    R   R7   R8   RE   RH   RF   RL   RN   R[   t   __name__(    (    (    s   /usr/lib/python2.5/gopherlib.pys   <module>   sd   					 					(