Ņō
ã=Pc           @   sĖ   d  Z  d d k l Z d d k Z d d k Td d k Td d k Td d k l Z	 d d k l Z
 d d k l Z d d k l Z d d k l Z l Z e e  Z d	 d d
     YZ d d d     YZ d S(   sL  
The I{schema} module provides a intelligent representation of
an XSD schema.  The I{raw} model is the XML tree and the I{model}
is the denormalized, objectified and intelligent view of the schema.
Most of the I{value-add} provided by the model is centered around
tranparent referenced type resolution and targeted denormalization.
iĸĸĸĸ(   t	   getLoggerN(   t   *(   t   Factory(   t   SchemaObject(   t   DepList(   t   splitPrefixt	   Namespacet   SchemaCollectionc           B   sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   s  
    A collection of schema objects.  This class is needed because WSDLs 
    may contain more then one <schema/> node.
    @ivar wsdl: A wsdl object.
    @type wsdl: L{suds.wsdl.Definitions}
    @ivar children: A list contained schemas.
    @type children: [L{Schema},...]
    @ivar namespaces: A dictionary of contained schemas by namespace.
    @type namespaces: {str:L{Schema}}
    c         C   s+   | |  _  | i |  _ g  |  _ h  |  _ d S(   sZ   
        @param wsdl: A wsdl object.
        @type wsdl: L{suds.wsdl.Definitions}
        N(   t   wsdlt   optionst   childrent
   namespaces(   t   selfR   (    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyt   __init__3   s    		c         C   sĶ   | \ } } t  | | i |  i d |  } | i d } |  i i |  } | d j o! |  i i |  | |  i | <n, | i	 i | i 7_ | i	 i
 i | i
  d S(   sî   
        Add a schema node to the collection.  Schema(s) within the same target
        namespace are consolidated.
        @param schema: A <schema/> entry.
        @type schema: (L{suds.wsdl.Definitions},L{sax.element.Element})
        t	   containeri   N(   t   Schemat   urlR	   t   tnsR   t   gett   NoneR
   t   appendt   roott
   nsprefixest   update(   R   t   schemaR   R   t   childt   keyt   existing(    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyt   add=   s    c      	   C   s   x |  i  D] } | i   q
 Wx |  i  D] } | i   q( Wx |  i  D] } | i   qF Wt i d |   |  i   } t i d |  | S(   sŧ   
        Load the schema objects for the root nodes.
            - de-references schemas
            - merge schemas
        @return: The merged schema.
        @rtype: L{Schema}
        s
   loaded:
%ss
   MERGED:
%s(   R
   t   buildt   open_importst   dereferencet   logt   debugt   merge(   R   R   t   merged(    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyt   loadO   s    
 
 
 c         C   s   |  i  i | d  S(   s$  
        Find a schema by namespace.  Only the URI portion of
        the namespace is compared to each schema's I{targetNamespace}
        @param ns: A namespace.
        @type ns: (prefix,URI)
        @return: The schema matching the namesapce, else None.
        @rtype: L{Schema}
        i   (   R   R   (   R   t   ns(    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyt   locateb   s    	c         C   sL   t  |   o7 |  i d } x" |  i d D] } | i |  q( W| Sd Sd S(   su   
        Merge the contained schemas into one.
        @return: The merged schema.
        @rtype: L{Schema}
        i    i   N(   t   lenR
   R"   R   (   R   R   t   s(    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyR"   m   s     c         C   s   t  |  i  S(   N(   R'   R
   (   R   (    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyt   __len__{   s    c         C   s   t  |   i d  S(   Ns   utf-8(   t   unicodet   encode(   R   (    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyt   __str__~   s    c         C   s@   d g } x' |  i  D] } | i | i d   q Wd i |  S(   Ns   
schema collectioni   s   
(   R
   R   t   strt   join(   R   t   resultR(   (    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyt   __unicode__   s
    	
 (   t   __name__t
   __module__t   __doc__R   R   R$   R&   R"   R)   R,   R0   (    (    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyR   '   s   
	
						R   c           B   s   e  Z d  Z d Z d d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d d	  Z d d
  Z d   Z d d  Z d   Z d   Z d   Z RS(   sĸ  
    The schema is an objectification of a <schema/> (xsd) definition.
    It provides inspection, lookup and type resolution.
    @ivar root: The root node.
    @type root: L{sax.element.Element}
    @ivar baseurl: The I{base} URL for this schema.
    @type baseurl: str
    @ivar options: An options dictionary.
    @type options: L{options.Options}
    @ivar container: A schema collection containing this schema.
    @type container: L{SchemaCollection}
    @ivar types: A schema types cache.
    @type types: {name:L{SchemaObject}}
    @ivar groups: A schema groups cache.
    @type groups: {name:L{SchemaObject}}
    @ivar children: A list of direct top level children.
    @type children: [L{SchemaObject},...]
    @ivar all: A list of all (includes imported) top level children.
    @type all: [L{SchemaObject},...]
    @ivar imports: A list of import objects.
    @type imports: [L{SchemaObject},...]
    @ivar form_qualified: The flag indicating:
        (@elementFormDefault).
    @type form_qualified: bool
    R   c         C   sB  | |  _  t |   |  _ |  i   |  _ | |  _ | |  _ | |  _ g  |  _ g  |  _	 h  |  _
 g  |  _ h  |  _ h  |  _ h  |  _ h  |  _ |  i i } | d j	 o | i |  n |  i  i d  } | d j o t |  _ n | d j |  _ | d j oB |  i   |  i   t i d |   |  i   t i d |   n d S(   si  
        @param root: The xml root.
        @type root: L{sax.element.Element}
        @param baseurl: The base url used for importing.
        @type baseurl: basestring
        @param options: An options dictionary.
        @type options: L{options.Options}
        @param container: An optional container.
        @type container: L{SchemaCollection}
        t   elementFormDefaultt	   qualifieds	   built:
%ss   dereferenced:
%sN(   R   t   objidt   idt   mktnsR   t   baseurlR	   R   R
   t   allt   typest   importst   elementst
   attributest   groupst   agrpst   doctorR   t   examineR   t   Falset   form_qualifiedR   R   R    R!   R   (   R   R   R9   R	   R   RA   t   form(    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyR   Ĩ   s6    												


c         C   sQ   d |  i i d  g } | d d j	 o |  i i | d  | d <n t |  S(   sī   
        Make the schema's target namespace.
        @return: The namespace representation of the schema's
            targetNamespace value.
        @rtype: (prefix, uri)
        t   targetNamespacei   i    N(   R   R   R   t
   findPrefixt   tuple(   R   R   (    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyR8   Í   s    c         C   s   t  i |  i |   |  _ t  i |  i  } | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _	 | d |  _
 d S(	   sĢ   
        Build the schema (object graph) using the root node
        using the factory.
            - Build the graph.
            - Collate the children.
        i    i   i   i   i   i   i   N(   t   BasicFactoryR   R   R
   t   collateR>   R<   R=   R;   R?   R@   (   R   t   collated(    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyR   Ų   s    c         C   sã  x[ | i  i   D]J } | d |  i  j o q n |  i i | d  | d |  i  | d <q Wx[ | i i   D]J } | d |  i j o qn n |  i i | d  | d |  i | d <qn Wx[ | i i   D]J } | d |  i j o qĖ n |  i i | d  | d |  i | d <qĖ Wx[ | i i   D]J } | d |  i j o q*n |  i i | d  | d |  i | d <q*Wx[ | i i   D]J } | d |  i j o qn |  i i | d  | d |  i | d <qWt | _	 |  S(   s  
        Merge the contents from the schema.  Only objects not already contained
        in this schema's collections are merged.  This is to provide for bidirectional
        import which produce cyclic includes.
        @returns: self
        @rtype: L{Schema} 
        i    i   (
   R>   t   itemsR:   R   R=   R;   R?   R@   t   TrueR#   (   R   R   t   item(    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyR"   ę   s@         	c         C   s_   xX |  i  D]M } | i   } | d j o q
 n | i   t i d |  |  i |  q
 Wd S(   s·   
        Instruct all contained L{sxbasic.Import} children to import
        the schema's which they reference.  The contents of the
        imported schema are I{merged} in.
        s   imported:
%sN(   R<   t   openR   R   R    R!   R"   (   R   t   impt   imported(    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyR     s    
 
c   
      C   s  g  } h  } x |  i  D] } | i |  q Wt   } xS | D]K } | i   | i   \ } } | t |  f } | i |  | | | <q= Wx} | i   D]o \ } } | i |  } | d j o q n | | }	 t
 i d |  i d t |  t |	   | i |	  q Wd S(   sA   
        Instruct all children to perform dereferencing.
        s   (%s) merging %s <== %si   N(   R
   t   contentR   t   qualifyt   dependenciesRH   R   t   sortR   R   R    R!   R   t   ReprR"   (
   R   R:   t   indexesR   t   deplistt   xt   midxt   depsRN   t   d(    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyR     s*    
 	 
  
)c         C   s)   |  i  d j	 o |  i  i |  Sd Sd S(   sU  
        Find a schema by namespace.  Only the URI portion of
        the namespace is compared to each schema's I{targetNamespace}.
        The request is passed to the container.
        @param ns: A namespace.
        @type ns: (prefix,URI)
        @return: The schema matching the namesapce, else None.
        @rtype: L{Schema}
        N(   R   R   R&   (   R   R%   (    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyR&   2  s    
c         C   s'   | d j o t S|  i | |  Sd S(   sÞ   
        Get whether the specified reference is B{not} an (xs) builtin.
        @param ref: A str or qref.
        @type ref: (str|qref)
        @return: True if B{not} a builtin, else False.
        @rtype: bool 
        N(   R   RM   t   builtin(   R   t   reft   context(    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyt   customA  s    c         C   sŽ   d } y t  |  o, | d } | d t i j o | i |  S| d j o |  i } n t |  d } | i | d  } | | j o | d t i j SWn t SXd S(   sÎ   
        Get whether the specified reference is an (xs) builtin.
        @param ref: A str or qref.
        @type ref: (str|qref)
        @return: True if builtin, else False.
        @rtype: bool 
        s   http://www.w3.orgi   i    t
   startswithN(	   t   isqrefR   t   tagsRa   R   R   R   t   findPrefixesRC   (   R   R^   R_   t   w3R%   t   prefixt   prefixes(    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyR]   N  s    
""c         C   s   t  | | |  i  S(   s|  
        Create and return an new schema object using the
        specified I{root} and I{url}.
        @param root: A schema root node.
        @type root: L{sax.element.Element}
        @param baseurl: A base URL.
        @type baseurl: str
        @return: The newly created schema object.
        @rtype: L{Schema}
        @note: This is only used by Import children.
        (   R   R	   (   R   R   R9   (    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyt   instancec  s    i    c         C   sŧ   d | d d f } g  } | i  d | |  i f  | i  d |  | i  |  i i | d   | i  d |  x+ |  i D]  } | i  | i | d   q} W| i  d  d i |  S(	   Ns   %*si   t    s   %s%ss   %s(raw)i   s	   %s(model)s   
(   R   R7   R   R-   R
   R.   (   R   t   indentt   tabR/   t   c(    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyR-   q  s    
 c         C   s'   d |  i  |  i d f } | i d  S(   Ns   <%s tns="%s"/>i   s   utf-8(   R7   R   R+   (   R   t   myrep(    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyt   __repr__}  s    c         C   s   t  |   i d  S(   Ns   utf-8(   R*   R+   (   R   (    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyR,     s    c         C   s
   |  i    S(   N(   R-   (   R   (    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyR0     s    N(   R1   R2   R3   t   TagR   R   R8   R   R"   R   R   R&   R`   R]   Rh   R-   Rn   R,   R0   (    (    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyR      s    (			$						(    (    (   R3   t   loggingR    t   suds.metricst   sudst   suds.xsdt   suds.xsd.sxbuiltint   suds.xsd.sxbasicR   RI   t   BuiltinFactoryt   suds.xsd.sxbaseR   t   suds.xsd.deplistR   t   suds.saxR   R   R1   R    R   R   (    (    (    sN   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.pyt   <module>   s   


a