ó
a#nSc           @   sä   d  Z  d d l Z d d d „  ƒ  YZ e d k rà d Z e e ƒ Z e j ƒ  Z d GHx- e e	 e ƒ ƒ D] Z
 d e
 e e
 f GHqg We j ƒ  d	 GHe j ƒ  Z d
 Z x8 e d k rÜ d e e f GHe d Z e j ƒ  Z q¨ Wn  d S(   sD    contains class REFile, for working with files containing comments

iÿÿÿÿNt   REFilec           B   sA   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d d d „ Z RS(   sÖ   behaves more or less like a normal file, but removes comments

   Any read from the file skips lines beginning with a comment character
     and cleaves off any portion of the line following a comment character

  c         C   s   |  j  j ƒ  d S(   s    closes the file

    N(   t   inFilet   close(   t   self(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/utils/REFile.pyR      s    c         C   s   |  j  j d ƒ d S(   s0    rewinds the file (seeks to the beginning)

    i    N(   R   t   seek(   R   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/utils/REFile.pyt   rewind   s    c         C   sÍ   g  } d } xº | sÈ |  j  j ƒ  } | d k r9 d } n |  j j | ƒ d } d } xW t | ƒ d k r® | r® |  j  j ƒ  } | d k r• d } qX |  j j | ƒ d } qX W| s | j | ƒ q q W| S(   s)    reads in all the lines of the file

    i    t    i   (   R   t   readlinet   exprt   splitt   lent   append(   R   t   rest   eofHitt   l(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/utils/REFile.pyt	   readlines   s     			c         C   sž   |  j  j ƒ  } | d k r$ d } n |  j j | ƒ d } d } xW t | ƒ d k r™ | r™ |  j  j ƒ  } | d k r€ d } qC |  j j | ƒ d } qC W| S(   s+    reads in a single line from the file

    R   i   i    (   R   R   R   R	   R
   (   R   R   R   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/utils/REFile.pyR   3   s    		t   rs   #|
c         C   s:   t  j | ƒ |  _ | |  _ | |  _ t | | ƒ |  _ d S(   sÐ    Constructor

      **Arguments**

        - fileName: the filename from which to read

        - mode: the mode in which to open the file

        - commentChar: a regexp defining the comment character

    N(   t   ret   compileR   t   fileNamet   modet   openR   (   R   R   R   t   commentChar(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/utils/REFile.pyt   __init__E   s    		(   t   __name__t
   __module__t   __doc__R   R   R   R   R   (    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/utils/REFile.pyR    	   s   				t   __main__s
   retest.txts
   readlines:s   	%d: %ss	   readline:i    R   i   (    (   R   R   R    R   t   fNamet   refR   t   linest   xrangeR
   t   iR   R   t   inStrt   nRead(    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/utils/REFile.pyt   <module>   s"   O

