ó
þ™xTc           @   sS   d  d l  m Z d  d l m Z d d d „  ƒ  YZ d d	 d „  ƒ  YZ e ƒ  Z d S(
   iÿÿÿÿ(   t   division(   t   LoadFormatClassest	   _Registryc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s°   A class to handle all of the recognised image formats within xia2
  working towards the generalization project in #1555 and specifically
  to address the requirements in #1573.c         C   s   g  |  _  t |  _ d S(   sr   Set myself up - N.B. this could trigger a directory search for
    different Format classes to auto-register them.N(   t   _formatst   Falset   _setup(   t   self(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/Registry.pyt   __init__   s    		c         C   s!   |  j  r d St ƒ  t |  _  d S(   sÄ   Look to import format defining modules from around the place -
    this will look in dxtbx/format and $HOME/.xia2/ for files starting
    with Format and ending in .py to allow user extensibility.N(   R   R   t   True(   R   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/Registry.pyt   setup   s
    		c         C   sK   d d l  m } t | | ƒ s% t ‚ | |  j k rG |  j j | ƒ n  d S(   sy   Register a new image format with the registry. N.B. to work
    this object must be inherited from the base Format class.iÿÿÿÿ(   t   FormatN(   t   dxtbx.format.FormatR
   t
   issubclasst   AssertionErrorR   t   append(   R   t   formatR
   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/Registry.pyt   add-   s
    c         C   s   t  |  j ƒ S(   s,   Get a list of image formats registered here.(   t   tupleR   (   R   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/Registry.pyt   get9   s    c            sZ   |  j  ƒ  ‡  f d †  ‰  x- |  j D]" } | j | ƒ r# ˆ  | | ƒ Sq# Wt d | ‚ d S(   s�   More useful - find the best format handler in the registry for your
    image file. N.B. this is in principle a factory function.c            s4   x- |  j  D]" } | j | ƒ r
 ˆ  | | ƒ Sq
 W|  S(   N(   t	   _childrent
   understand(   R   t
   image_filet   child(   t   recurse(    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/Registry.pyR   G   s    s   no format support found for %sN(   R	   R   R   t   IOError(   R   R   R   (    (   R   sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/Registry.pyt   find>   s    
(   t   __name__t
   __module__t   __doc__R   R	   R   R   R   (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/Registry.pyR      s   	
			t   Registryc           B   s8   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z RS(   sÅ   A class to turn the registry above into a singleton, so that we
  can work around some of the more knotty dependency loops which come
  out of things like this. This is something of a boiler plate.c         C   s"   t  j d  k r t ƒ  t  _ n  d  S(   N(   R   t   _Registry__instancet   NoneR   (   R   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/Registry.pyR   Z   s    c         C   s   |  S(   N(    (   R   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/Registry.pyt   __call__`   s    c         C   s   t  |  j | ƒ S(   N(   t   getattrR   (   R   t   attr(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/Registry.pyt   __getattr__c   s    c         C   s   t  |  j | | ƒ S(   N(   t   setattrR   (   R   R"   t   value(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/Registry.pyt   __setattr__f   s    N(	   R   R   R   R   R   R   R    R#   R&   (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/Registry.pyR   S   s   			N(    (    (   t
   __future__R    t   RegistryHelpersR   R   R   (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/Registry.pyt   <module>   s   C