ó
þ™xTc           @   s{   d  d l  m Z d  d l m Z d e f d „  ƒ  YZ e d k rw d  d l Z x& e j d D] Z e j	 e ƒ GHq\ Wn  d S(   iÿÿÿÿ(   t   division(   t   Formatt	   FormatCBFc           B   s>   e  Z d  Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z RS(   s»   An image reading class for CBF format images i.e. those from Dectris
  amongst others. This is just a first base class which will be used to
  determine whether this is really a CBF file.c         C   s)   d t  j |  d ƒ j d ƒ k r% t St S(   sV   Check to see if this looks like an CBF format image, i.e. we can
    make sense of it.s   ###CBFt   rbi   (   R   t	   open_filet   readt   Truet   False(   t
   image_file(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBF.pyt
   understand   s    !c         C   sh   t  j |  d ƒ } | j d ƒ } x3 d | k rV | j d ƒ } | rR | | 7} q$ Pq$ W| j d ƒ d S(   s·   Obtain the text section of the header, which is assumed to be
    everything before --CIF-BINARY-FORMAT-SECTION-- - N.B. for reasons
    of simplicity will read the file in 1k chunks.R   i   s   --CIF-BINARY-FORMAT-SECTION--i    (   R   R   R   t   split(   R   t   fint   headert   add(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBF.pyt   get_cbf_header   s    c         C   s)   |  j  | ƒ s t ‚ t j |  | ƒ d S(   s3   Initialise the image structure from the given file.N(   R	   t   AssertionErrorR   t   __init__(   t   selfR   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBF.pyR   1   s    c         C   s´   t  j |  ƒ t j |  j ƒ |  _ d |  _ t } x| t j |  j d ƒ D]e } d | k rb t	 } n( | rŠ | d d k rŠ |  j | 7_ n  | rG t
 | j ƒ  ƒ d k rG PqG qG Wd S(   sZ   Open the image file, read the image header, copy it into memory
    for future inspection.t    R   s   --CIF-BINARY-FORMAT-SECTION--i    t   XN(   R   t   _startR   R   t   _image_filet   _cif_headert   _mime_headerR   R   R   t   lent   strip(   R   t   in_binary_format_sectiont   record(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBF.pyR   :   s    		(   t   __name__t
   __module__t   __doc__t   staticmethodR	   R   R   R   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBF.pyR      s
   
		t   __main__Ni   (
   t
   __future__R    t   dxtbx.format.FormatR   R   R   t   syst   argvt   argR	   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatCBF.pyt   <module>   s   D