ó
NŽLc           @   sÊ   d  Z  d d l m Z d d l m Z m Z d d l m Z d d l m	 Z	 m
 Z
 e e ƒ Z d d d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 d d „  ƒ  YZ d d d „  ƒ  YZ d e e	 f d „  ƒ  YZ d S(   sK   
The I{doctor} module provides classes for fixing broken (sick)
schema(s).
iÿÿÿÿ(   t	   getLogger(   t   splitPrefixt	   Namespace(   t   Element(   t   DocumentPlugint   DocumentContextt   Doctorc           B   s   e  Z d  Z d „  Z RS(   s   
    Schema Doctor.
    c         C   s   d S(   sŠ   
        Examine and repair the schema (if necessary).
        @param root: A schema root element.
        @type root: L{Element}
        N(    (   t   selft   root(    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyt   examine"   s    (   t   __name__t
   __module__t   __doc__R	   (    (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR      s   t   Practicec           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s`   
    A collection of doctors.
    @ivar doctors: A list of doctors.
    @type doctors: list
    c         C   s   g  |  _  d  S(   N(   t   doctors(   R   (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyt   __init__2   s    c         C   s   |  j  j | ƒ d S(   sv   
        Add a doctor to the practice
        @param doctor: A doctor to add.
        @type doctor: L{Doctor}
        N(   R   t   append(   R   t   doctor(    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyt   add5   s    c         C   s%   x |  j  D] } | j | ƒ q
 W| S(   N(   R   R	   (   R   R   t   d(    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR	   =   s    (   R
   R   R   R   R   R	   (    (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR   +   s   		t	   TnsFilterc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sg   
    Target Namespace filter.
    @ivar tns: A list of target namespaces.
    @type tns: [str,...]
    c         G   s   g  |  _  |  j | Œ  d S(   sW   
        @param tns: A list of target namespaces.
        @type tns: [str,...]
        N(   t   tnsR   (   R   R   (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR   J   s    	c         G   s   |  j  | 7_  d S(   s„   
        Add I{targetNamesapces} to be added.
        @param tns: A list of target namespaces.
        @type tns: [str,...]
        N(   R   (   R   R   (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR   R   s    c         C   sM   | j  d ƒ } t |  j ƒ r0 | |  j k } n d } | | k } | oL | S(   sá   
        Match by I{targetNamespace} excluding those that
        are equal to the specified namespace to prevent
        adding an import to itself.
        @param root: A schema root.
        @type root: L{Element}
        t   targetNamespacei   (   t   gett   lenR   (   R   R   t   nsR   t   matchedt   itself(    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyt   matchZ   s    (   R
   R   R   R   R   R   (    (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR   C   s   		t   Importc           B   sG   e  Z d  Z e j Z d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   sZ  
    An <xs:import/> to be applied.
    @cvar xsdns: The XSD namespace.
    @type xsdns: (p,u)
    @ivar ns: An import namespace.
    @type ns: str
    @ivar location: An optional I{schemaLocation}.
    @type location: str
    @ivar filter: A filter used to restrict application to
        a particular schema.
    @type filter: L{TnsFilter}
    c         C   s"   | |  _  | |  _ t ƒ  |  _ d S(   s›   
        @param ns: An import namespace.
        @type ns: str
        @param location: An optional I{schemaLocation}.
        @type location: str
        N(   R   t   locationR   t   filter(   R   R   R   (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR   {   s    		c         C   s   | |  _  d S(   sl   
        Set the filter.
        @param filter: A filter to set.
        @type filter: L{TnsFilter}
        N(   R   (   R   R   (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyt	   setfilter†   s    c         C   s�   |  j  j | |  j ƒ s d S|  j | ƒ r/ d St d d |  j ƒ} | j d |  j ƒ |  j d k	 r| | j d |  j ƒ n  t	 j
 d | ƒ | j | ƒ d S(   sø   
        Apply the import (rule) to the specified schema.
        If the schema does not already contain an import for the
        I{namespace} specified here, it is added.
        @param root: A schema root.
        @type root: L{Element}
        Nt   importR   t	   namespacet   schemaLocations   inserting: %s(   R   R   R   t   existsR   t   xsdnst   setR   t   Nonet   logt   debugt   insert(   R   R   t   node(    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyt   applyŽ   s    c         C   sn   t  d d |  j ƒ} | j d |  j ƒ |  j d k	 rM | j d |  j ƒ n  t j d | ƒ | j | ƒ d S(   s†   
        Add an <xs:import/> to the specified schema root.
        @param root: A schema root.
        @type root: L{Element}
        R!   R   R"   R#   s   %s insertedN(	   R   R%   R&   R   R   R'   R(   R)   R*   (   R   R   R+   (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR   ¡   s    c         C   sO   xH | j  D]= } | j d k r% q
 n  | j d ƒ } |  j | k r
 d Sq
 Wd S(   sÃ   
        Check to see if the <xs:import/> already exists
        in the specified schema root by matching I{namesapce}.
        @param root: A schema root.
        @type root: L{Element}
        R!   R"   i   i    (   t   childrent   nameR   R   (   R   R   R+   R   (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR$   ®   s    N(   R
   R   R   R   R%   R'   R   R    R,   R   R$   (    (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR   k   s   				t   ImportDoctorc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s   
    Doctor used to fix missing imports.
    @ivar imports: A list of imports to apply.
    @type imports: [L{Import},...]
    c         G   s   g  |  _  |  j | Œ  d S(   s	   
        N(   t   importsR   (   R   R0   (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR   Å   s    	c         G   s   |  j  | 7_  d S(   s‹   
        Add a namesapce to be checked.
        @param imports: A list of L{Import} objects.
        @type imports: [L{Import},..]
        N(   R0   (   R   R0   (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR   Ë   s    c         C   s%   x |  j  D] } | j | ƒ q
 Wd  S(   N(   R0   R,   (   R   R+   t   imp(    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR	   Ó   s    c         C   sr   | j  } | j d k r> t j | j ƒ  ƒ r> |  j | ƒ d  St ƒ  } x$ | D] } | | _  |  j | ƒ qN Wd  S(   Nt   schema(   t   documentR.   R   t   xsdR"   R	   R   t   parsed(   R   t   contextR+   t   child(    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR5   ×   s    	$		(   R
   R   R   R   R   R	   R5   (    (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyR/   ¾   s
   			N(    (    (    (   R   t   loggingR    t   suds.saxR   R   t   suds.sax.elementR   t   suds.pluginR   R   R
   R(   R   R   R   R   R/   (    (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/xsd/doctor.pyt   <module>   s   (S