³ò
—ã=Pc           @   s±   d  Z  d d k l Z d d k l Z l Z d d k l Z e e ƒ Z	 d d d „  ƒ  YZ
 d e
 f d „  ƒ  YZ d	 d d
 „  ƒ  YZ d d d „  ƒ  YZ d 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   Elementt   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(    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyt   examine!   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s'   suds-0.3.7-py2.6.egg/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   (    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyt   __init__1   s    c         C   s   |  i  i | ƒ 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(    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyt   add4   s    c         C   s%   x |  i  D] } | i | ƒ q
 W| S(   N(   R   R   (   R   R   t   d(    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyR   <   s    
 (   R   R	   R
   R   R   R   (    (    (    s'   suds-0.3.7-py2.6.egg/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  |  _  |  i | Œ  d S(   sW   
        @param tns: A list of target namespaces.
        @type tns: [str,...]
        N(   t   tnsR   (   R   R   (    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyR   I   s    	c         G   s   |  i  | 7_  d S(   s„   
        Add I{targetNamesapces} to be added.
        @param tns: A list of target namespaces.
        @type tns: [str,...]
        N(   R   (   R   R   (    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyR   Q   s    c         C   sP   | i  d ƒ } t |  i ƒ o | |  i j } n d } | | j } | o | 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(    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyt   matchY   s    (   R   R	   R
   R   R   R   (    (    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyR   B   s   		t   Importc           B   sG   e  Z d  Z e i 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   (    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyR   z   s    		c         C   s   | |  _  d S(   sl   
        Set the filter.
        @param filter: A filter to set.
        @type filter: L{TnsFilter}
        N(   R   (   R   R   (    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyt	   setfilter…   s    c         C   s©   |  i  i | |  i ƒ p d Sn |  i | ƒ o d Sn t d d |  i ƒ} | i d |  i ƒ |  i d j	 o | i d |  i ƒ n t	 i
 d | ƒ | i | ƒ 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(    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyt   apply   s    c         C   sp   t  d d |  i ƒ} | i d |  i ƒ |  i d j	 o | i d |  i ƒ n t i d | ƒ | i | ƒ 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)   (    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyR       s    c         C   sV   xO | i  D]D } | i d j o q
 n | i d ƒ } |  i | j o d Sq
 q
 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   (    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyR"   ­   s    
 N(   R   R	   R
   R   R#   R%   R   R   R*   R   R"   (    (    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyR   j   s   				t   ImportDoctorc           B   s)   e  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  |  _  |  i | Œ  d S(   s	   
        N(   t   importsR   (   R   R.   (    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyR   Ä   s    	c         G   s   |  i  | 7_  d S(   s‹   
        Add a namesapce to be checked.
        @param imports: A list of L{Import} objects.
        @type imports: [L{Import},..]
        N(   R.   (   R   R.   (    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyR   Ê   s    c         C   s%   x |  i  D] } | i | ƒ q
 Wd  S(   N(   R.   R*   (   R   R   t   imp(    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyR   Ò   s    
 (   R   R	   R
   R   R   R   (    (    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pyR-   ½   s   		N(    (    (    (   R
   t   loggingR    t   suds.saxR   R   t   suds.sax.elementR   R   R&   R   R   R   R   R-   (    (    (    s'   suds-0.3.7-py2.6.egg/suds/xsd/doctor.pys   <module>   s   (S