
e#]c           @   s  d  Z  d d l Z d d l Z d d l m Z d d l Z d d l Z e j e	  Z
 e j j j d e j f d     Y Z d e f d     YZ d e j f d	     YZ d
 e j j j e j f d     YZ d e j f d     YZ d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z e j Z d e e j e e j  f d     YZ! d d l" m# Z# d d l" m$ Z$ d d l" m% Z% d d l" m& Z& d d l" m' Z' d d l" m( Z( d d l" m) Z) e j j* e% j+ d  e d   d S(   s  Classes and global objects related to U{XML Namespaces<http://www.w3.org/TR/2006/REC-xml-names-20060816/index.html>}.

Since namespaces hold all referenceable objects, this module also defines the
infrastructure for resolving named object references, such as schema
components.
iN(   t   sixt   ExpandedNamec           B   s   e  Z d  Z d   Z d Z d   Z d Z d   Z d Z	 d Z
 d   Z d   Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s  Represent an U{expanded name
    <http://www.w3.org/TR/REC-xml-names/#dt-expname>}, which pairs a
    namespace with a local name.

    Because a large number of local elements, and most attributes, have no
    namespace associated with them, this is optimized for representing names
    with an absent namespace.  The hash and equality test methods are set so
    that a plain string is equivalent to a tuple of C{None} and that string.

    Note that absent namespaces can be represented in two ways: with a
    namespace of C{None} (the name "has no namespace"), and with a namespace
    that is an L{absent namespace <Namespace.CreateAbsentNamespace>} (the name
    "has an absent namespace").  Hash code calculations are done so that the
    two alternatives produce the same hash; however, comparison is done so
    that the two are distinguished.  The latter is the intended behavior; the
    former should not be counted upon.

    This class allows direct lookup of the named object within a category by
    using the category name as an accessor function.  That is, if the
    namespace of the expanded name C{en} has a category 'typeDefinition', then
    the following two expressions are equivalent::

      en.typeDefinition()
      en.namespace().categoryMap('typeDefinition').get(en.localName())

    This class descends from C{tuple} so that its values can be used as
    dictionary keys without concern for pointer equivalence.
    c         C   s   |  j  S(   s+   The L{Namespace} part of the expanded name.(   t   _ExpandedName__namespace(   t   self(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt	   namespace>   s    c         C   s   |  j  S(   sG   Return the URI of the namespace, or C{None} if the namespace is absent.(   t   _ExpandedName__namespaceURI(   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   namespaceURIC   s    c         C   s   |  j  S(   s$   The local part of the expanded name.(   t   _ExpandedName__localName(   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt	   localNameH   s    c         C   s   |  j    j   S(   s0   Pass model validation through to namespace part.(   R   t   validateComponentModel(   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR	   P   s    c         C   s   |  j  |  j f S(   s  Return a tuple consisting of the namespace URI and the local name.

        This presents the expanded name as base Python types for persistent
        storage.  Be aware, though, that it will lose the association of the
        name with an absent namespace, if that matters to you.(   R   R   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   uriTupleT   s    c            sy   | j  d  r% t t |   j |  S|  j   } | d  k rD d   S| j   | j |  j |  j	        f d   S(   Nt   __c           S   s   d  S(   N(   t   None(    (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   <lambda>c   s    c              s     S(   N(    (    (   t   category_value(    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR   i   s    (
   t
   startswitht   superR   t   __getattr__R   R   R	   t   categoryMapt   getR   (   R   t   namet   ns(    (   R   sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR   ]   s    
c         C   s   t  |  j   |  S(   s   Return a new expanded name in the namespace of this name.

        @param local_name: The local name portion of an expanded name.
        @return: An instance of L{ExpandedName}.
        (   R   R   (   R   t
   local_name(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt
   createNamek   s    c         C   sL   t  | t  s t |  } n  | j   d k rH |  j | j    } n  | S(   s  Return the input name, except if the input name has no namespace,
        return a name that uses the namespace from this name with the local
        name from the input name.

        Use this when the XML document has an unqualified name and we're
        processing using an absent default namespace.

        @warning: Be careful when using a global name to adopt a name from a
        local element: if the local element (with no namespace) has the same
        localName as but is different from the global element (with a
        namespace), this will improperly provide a namespace when one should
        not be present.  See the comments in
        L{pyxb.binding.basis.element.elementForName}.
        N(   t
   isinstanceR   R   R   R   R   (   R   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt	   adoptNames   s
    c         O   s  | j  d  } d t |  k r3 t j d   n  d t |  k  rW t j d   n  d t |  k rx | \ } } n d t |  k s t  | d } d } t | t j  r n t | t	  r d t |  k r | \ } } n t | t
  r| j   } | j   } n t | t j j  r|| j t j j j t j j j f k rgt j d | j f   n  | j } | j } n t j d t |  f   | d k r| d k	 r| j   r| } qn  t | t j  rt | d	 t } n  t | t
  r| j   } n  | d k	 r;t | t  r;t j d
   n  | |  _ |  j d k	 rh|  j j   |  _ n  | |  _ |  j d k	 st  |  j |  j f |  _ |  j |  j f |  _ t t
 |   j  | |   d S(   s
  Create an expanded name.

        Expected argument patterns are:

         - ( C{str} ) : the local name in an absent namespace
         - ( L{ExpandedName} ) : a copy of the given expanded name
         - ( C{xml.dom.Node} ) : The name extracted from node.namespaceURI and node.localName
         - ( C{str}, C{str} ) : the namespace URI and the local name
         - ( L{Namespace}, C{str} ) : the namespace and the local name
         - ( L{ExpandedName}, C{str}) : the namespace from the expanded name, and the local name

        Wherever C{str} occurs C{unicode} is also permitted.

        @keyword fallback_namespace: Optional Namespace instance to use if the
        namespace would otherwise be None.  This is only used if it is an
        absent namespace.

        t   fallback_namespacei    s-   Too few arguments to ExpandedName constructori   s.   Too many arguments to ExpandedName constructori   s8   Cannot create expanded name from non-element DOM node %ss   Unrecognized argument type %st   create_if_missingsF   ExpandedName must include a valid (perhaps absent) namespace, or None.N(!   R   t   lent   pyxbt
   LogicErrort   AssertionErrorR   R   R    t   string_typest   tupleR   R   R   t   xmlt   domt   Nodet   nodeTypet   ELEMENT_NODEt   ATTRIBUTE_NODER   t   typet   isAbsentNamespacet   NamespaceForURIt   Truet	   NamespaceR   t   uriR   R   t   _ExpandedName__expandedNamet   _ExpandedName__uriTupleR   t   __init__(   R   t   argst   kwR   R   t   ln(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR0      sP    
!'			c         C   sB   |  j  d  k	 s t  |  j d  k	 r8 d |  j |  j  f S|  j   S(   Ns   {%s}%s(   R   R   R   R   R   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   __str__   s    c         C   s8   |  j  d  k r( t |  j  j |  j  St j |  j  S(   N(   R   R   R(   R   t   __hash__R!   R.   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR5      s    c         C   sp   t  | t j  r! d  | f } n  t  | t  s< | j } n  t  | d t  rl | d j   | d f } n  | S(   Ni    i   (   R   R    R    R   R!   R/   R,   R-   (   R   t   other(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   __otherForCompare   s    c         C   s8   | d  k r t Sd t j j j |  j |  j |   k S(   Ni    (   R   t   FalseR   t   utilst   utilityt   IteratedCompareMixedR/   t   _ExpandedName__otherForCompare(   R   R6   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   __eq__   s    c         C   s8   | d  k r t Sd t j j j |  j |  j |   k S(   Ni    (   R   R8   R   R9   R:   R;   R/   R<   (   R   R6   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   __lt__   s    c         C   s2   | j  |  j |  j  r. | j |  j |  j  Sd S(   s   Return the value of the attribute identified by this name in the given node.

        @return: An instance of C{xml.dom.Attr}, or C{None} if the node does
        not have an attribute with this name.
        N(   t   hasAttributeNSR   R   t   getAttributeNSR   (   R   t   dom_node(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   getAttribute   s    c         C   s"   | j  |  j k o! | j |  j k S(   sI   Return C{True} iff the dom node expanded name matches this expanded name.(   R   R   R   R   (   R   RA   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   nodeMatches   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R.   R	   R
   R   R   R   R0   R4   R5   R<   R=   R>   RB   RC   (    (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR      s*   										@							
t   NamedObjectMapc           B   s5   e  Z d  Z d   Z d Z d   Z d Z d   Z RS(   s  An extended dictionary intended to assist with QName resolution.

    These dictionaries have an attribute that identifies a category of named
    objects within a Namespace; the specifications for various documents
    require that certain groups of objects must be unique, while uniqueness is
    not required between groups.  The dictionary also retains a pointer to the
    Namespace instance for which it holds objects.c         C   s   |  j  S(   s.   The namespace to which the object map belongs.(   t   _NamedObjectMap__namespace(   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR      s    c         C   s   |  j  S(   sC   The category of objects (e.g., typeDefinition, elementDeclaration).(   t   _NamedObjectMap__category(   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   category  s    c         O   s/   | |  _  | |  _ t t |   j | |   d  S(   N(   RI   RH   R   RG   R0   (   R   RJ   R   R1   R2   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR0     s    		N(	   RD   RE   RF   R   R   RH   RJ   RI   R0   (    (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyRG      s   		t   _NamespaceCategory_mixinc           B   s   e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z RS(   s  Mix-in that aggregates those aspects of XMLNamespaces that hold
    references to categories of named objects.

    Arbitrary groups of named objects, each requiring unique names within
    themselves, can be saved.  Unless configured otherwise, the Namespace
    instance is extended with accessors that provide direct access to
    individual category maps.  The name of the method is the category name
    with a suffix of "s"; e.g., if a category "typeDefinition" exists, it can
    be accessed from the namespace using the syntax C{ns.typeDefinitions()}.

    Note that the returned value from the accessor is a live reference to
    the category map; changes made to the map are reflected in the
    namespace.
    c         C   s,   t  t t |   d d      i  |  _ d S(   s^   CSC extension to reset fields of a Namespace.

        This one handles category-related data.t   _resetc          _   s   d  S(   N(   R   (   R1   R2   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR   %  s    N(   t   getattrR   RK   t%   _NamespaceCategory_mixin__categoryMap(   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyRL   !  s    c         C   s   t  |  j j    S(   s9   The list of individual categories held in this namespace.(   t   listRN   t   keys(   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt
   categories(  s    c         C   s   |  j  S(   s6   Return the whole map from categories to named objects.(   RN   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   _categoryMap,  s    c         C   sC   y |  j  | SWn- t k
 r> t j |  d |  | f   n Xd S(   sH   Map from local names to NamedObjectMap instances for the given category.s   %s has no category %sN(   RN   t   KeyErrorR   t   NamespaceError(   R   RJ   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR   0  s    c         C   sD   x= |  j    D]/ } | d } t |  | |  j |  d   q Wd S(   s   Define public methods on the Namespace which provide access to
        individual NamedObjectMaps based on their category.

        t   sc         S   s   |  S(   N(    (   t   _map(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR   >  s    N(   RQ   t   setattrR   (   R   RJ   t   accessor_name(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   __defineCategoryAccessors7  s    
c         C   sl   |  j    |  j d k r% i  |  _ n  x6 | D]. } | |  j k r, t | |   |  j | <q, q, W|  j   |  S(   s   Ensure there is a map for each of the given categories.

        Category configuration
        L{activates<archive._NamespaceArchivable_mixin.isActive>} a namespace.

        Existing maps are not affected.N(   t	   _activateRN   R   RG   t1   _NamespaceCategory_mixin__defineCategoryAccessors(   R   RQ   RJ   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   configureCategories@  s    

c         C   sf   |  j  |  } | j |  } | d k	 rX | | k rX t j |  d |  | | f   n  | | | <| S(   s   Allow access to the named_object by looking up the local_name in
        the given category.

        Raises pyxb.NamespaceUniquenessError if an object with the same name
        already exists in the category.s*   %s: name %s used for multiple values in %sN(   R   R   R   R   t   NamespaceUniquenessError(   R   RJ   R   t   named_objectt   name_mapt
   old_object(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   addCategoryObjectQ  s    "
c         C   s9   |  j  |  } | | j |  k r1 | | | <n  | | S(   s   Replace the referenced object in the category.

        The new object will be added only if the old_object matches the
        current entry for local_name in the category.(   R   R   (   R   RJ   R   R`   t
   new_objectR_   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   replaceCategoryObject^  s    c            s   xl t  j |  j  D]X \ } } xI | j   D]; \ } } | | k r, | | =  d k	 rg   | | <qg q, q, Wq Wt t t |   d   f d    |    S(   s   Replace a component definition where present in the category maps.

        @note: This is a high-cost operation, as every item in every category
        map must be examined to see whether its value field matches
        C{existing_def}.t   _replaceComponent_cscc             s     S(   N(    (   R1   R2   (   t   replacement_def(    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR   t  s    N(   R    t	   iteritemsRN   t   itemsR   RM   R   RK   (   R   t   existing_defRe   t   catt   registryt   kt   v(    (   Re   sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyRd   h  s    c         C   s~   |  j  d  k r t St |  j  t  s+ t  d t |  j   k rD t Sx3 |  j   D]% } d t |  j |   k  rQ t	 SqQ Wt S(   Ni    (
   RN   R   R+   R   t   dictR   R   RQ   R   R8   (   R   Rk   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   __checkCategoriesEmpty{  s    c         C   s@   t    } x0 t j |  j  D] } | j t j |   q W| S(   N(   t   setR    t
   itervaluesRN   t   update(   R   t   objectst   category_map(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   _namedObjects  s    	c         C   s   |  j  t j |   x t j |  D] } |  j |  } | | } x t j |  D]x \ } } | j |  } | d k r | | | <qU | j |  r | j |  qU t	 j
 |  d | | |  j   f   qU Wq& W|  j   d S(   s   Add the named objects from the given map into the set held by this namespace.
        It is an error to name something which is already present.s&   Load attempted to override %s %s in %sN(   R\   R    t   iterkeysR   Rf   R   R   t   _allowUpdateFromOthert   _updateFromOtherR   RT   R-   R[   (   R   Rs   RJ   t   current_mapt   new_mapR   t	   componentt   existing_component(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   _loadNamedObjects  s    
-c         C   s   d |  j  k S(   sb  Return C{True} iff schema components have been associated with this namespace.

        This only checks whether the corresponding categories have been added,
        not whether there are any entries in those categories.  It is useful
        for identifying namespaces that were incorporated through a
        declaration but never actually referenced.t   typeDefinition(   RN   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   hasSchemaComponents  s    c         C   s   | j    |  k s t  | j   |  j t j j   g  | j   } x t j	 |  j
  D]l \ } } x] t j	 |  D]L \ } } t | t j  rv | j   | k rv | j   j | | |  qv qv WqZ Wd S(   s  Add links from L{pyxb.namespace.archive._ObjectOrigin} instances.

        For any resolvable item in this namespace from an origin managed by
        the module_record, ensure that item can be found via a lookup through
        that origin.

        This allows these items to be found when a single namespace comprises
        items translated from different schema at different times using
        archives to maintain consistency.N(   R   R   t   resetCategoryObjectsR\   t   archivet   NamespaceArchivet   _AnonymousCategoryt   originsR    Rf   RN   R   t   _ArchivableObject_mixint   _objectOrigint   addCategoryMember(   R   t   module_recordt
   origin_setRi   t   cat_mapt   nRl   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   _associateOrigins  s    

$N(   RD   RE   RF   R   RN   RL   RQ   RR   R   R[   R\   Ra   Rc   Rd   t.   _NamespaceCategory_mixin__checkCategoriesEmptyRt   R|   R~   R   (    (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyRK     s    									
						t   _ComponentDependency_mixinc           B   sK   e  Z d  Z e   Z d Z e j d  d   Z e	 e	 d  Z
 d   Z RS(   s:   Mix-in for components that can depend on other components.t   bindingRequiresc         K   s/   t  t t |   d d    |   d |  _ d S(   s   CSC extension to reset fields of a component.  This one clears
        dependency-related data, since the clone will have to revise its
        dependencies.
        @rtype: C{None}t   _resetClone_cscc          _   s   d  S(   N(   R   (   t   _argst   _kw(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR     s    N(   RM   R   R   R   t+   _ComponentDependency_mixin__bindingRequires(   R   R2   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR     s    "c         C   s   | s |  j  d k r t |  t j  rk |  j   rk t j d |  j j	 |  j
   j   |  j   f   n  |  j |  |  _  n  |  j  S(   s  Return a set of components upon whose bindings this component's
        bindings depend.

        For example, bindings that are extensions or restrictions depend on
        their base types.  Complex type definition bindings require that the
        types of their attribute declarations be available at the class
        definition, and the types of their element declarations in the
        postscript.

        @keyword include_lax: if C{False} (default), only the requirements of
        the class itself are returned.  If C{True}, all requirements are
        returned.
        @rtype: C{set(L{pyxb.xmlschema.structures._SchemaComponent_mixin})}
        s   Unresolved %s in %s: %sN(   R   R   R   t
   resolutiont   _Resolvable_mixint
   isResolvedR   R   t	   __class__RD   t   _namespaceContextt   targetNamespaceR   t   _bindingRequires_vx(   R   t   resett   include_lax(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR     s
    7c         C   s    t  j d t |   f   d S(   s'  Placeholder for subclass method that identifies the necessary components.

        @note: Override in subclasses.

        @return: The component instances on which this component depends
        @rtype: C{frozenset}
        @raise LogicError: A subclass failed to implement this method
        s)   %s does not implement _bindingRequires_vxN(   R   R   R(   (   R   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR     s    	N(   RD   RE   RF   Ro   t,   _ComponentDependency_mixin__PrivateTransientR   R   t   addR   R8   R   R   (    (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR     s   		t$   _NamespaceComponentAssociation_mixinc           B   sb   e  Z d  Z d	 Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	 Z d   Z d   Z RS(
   s  Mix-in for managing components defined within this namespace.

    The component set includes not only top-level named components (such as
    those accessible through category maps), but internal anonymous
    components, such as those involved in representing the content model of a
    complex type definition.  We need to be able to get a list of these
    components, sorted in dependency order, so that generated bindings do not
    attempt to refer to a binding that has not yet been generated.c         C   sD   t  t t |   d d      t   |  _ t   |  _ i  |  _ d S(   s   CSC extension to reset fields of a Namespace.

        This one handles data related to component association with a
        namespace.RL   c          _   s   d  S(   N(   R   (   R1   R2   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR     s    N(   RM   R   R   Ro   t0   _NamespaceComponentAssociation_mixin__componentst-   _NamespaceComponentAssociation_mixin__originst/   _NamespaceComponentAssociation_mixin__schemaMap(   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyRL     s    c         C   s]   |  j    |  j d k	 s t  t | t  s4 t  | |  j k sI t  |  j j |  d S(   sK   Record that the responsibility for the component belongs to this namespace.N(   RZ   R   R   R   R   R   R   (   R   Rz   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   _associateComponent  s
    
c            sZ   |  j  j |    d k	 r/ |  j  j    n  t t t |   d   f d    |    S(   s   Replace a component definition in the set of associated components.

        @raise KeyError: C{existing_def} is not in the set of components.Rd   c             s     S(   N(    (   R1   R2   (   Re   (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR     s    N(   R   t   removeR   R   RM   R   R   (   R   Rh   Re   (    (   Re   sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyRd   
  s    c         C   s   x |  j  D]v } t | t j  r
 | j d |  r
 t j d | j   | j   j   |   t	 j
 |  | j   | j     q
 q
 Wt j d |  } | j   j |  |  j  j |  | S(   Nt   schemas/   Hash for %s matches %s already registered as %s(   R   R   R   t   _SchemaOrigint   matcht   _logt   infot   locationR   R   t   SchemaUniquenessErrort   generationUIDt   associateObjectR   (   R   R   t   sr(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt	   addSchema  s    $((c         C   s   xE |  j  D]: } t | t j  r
 | j d |  r
 t | j   f Sq
 Wx0 |  j   D]" } | j d |  rU t d  f SqU Wt
 d  f S(   NR   (   R   R   R   R   R   R+   R   t   moduleRecordst   hasMatchingOriginR   R8   (   R   t   schema_locationR   t   mr(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   lookupSchemaByLocation  s    $c         C   s[   t    } xK |  j D]@ } t | t j  r | j   d  k	 r | j | j    q q W| S(   N(   Ro   R   R   R   R   R   R   R   (   R   RU   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   schemas'  s
    	$c         C   s   t  |  j  S(   s\   Return a frozenset of all components, named or unnamed, belonging
        to this namespace.(   t	   frozensetR   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt
   components0  s    c         C   s"   x |  j  D] } | j   q
 Wd  S(   N(   R   t   _clearNamespaceContext(   R   t   c(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   _releaseNamespaceContexts5  s    N(   RD   RE   RF   R   R   RL   R   Rd   R   R   R   R   R   R   (    (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR     s   	
		
	
				(   R   (   t   NamespaceInstance(   R*   (   t   CreateAbsentNamespace(   t   AvailableNamespaces(   R   R,   c        	   B   s  e  Z d  Z d# Z d Z d# Z d# Z i  Z e	   Z
 d# Z e Z e Z e Z d# Z e Z d# Z d# Z d# Z d# Z d# Z e d    Z i  Z d# Z d Z d   Z d   Z e d    Z d# d# d# e e d# d# d# d  Z d   Z  d	   Z! d
   Z" d   Z# d   Z$ d   Z% e d    Z& d   Z' d   Z( d   Z) d   Z* d   Z+ d   Z, d   Z- d   Z. d# d  Z/ d   Z0 d   Z1 d   Z2 d   Z3 e Z4 d   Z5 d   Z6 e Z7 e Z8 d# d  Z9 d   Z: d    Z; d!   Z< d"   Z= RS($   s  Represents an XML namespace (a URI).

    There is at most one L{Namespace} class instance per namespace (URI).  The
    instance also supports associating arbitrary L{maps<NamedObjectMap>} from
    names to objects, in separate categories.  The default categories are
    configured externally; for example, the
    L{Schema<pyxb.xmlschema.structures.Schema>} component defines a category
    for each named component in XMLSchema, and the customizing subclass for
    WSDL definitions adds categories for the service bindings, messages, etc.

    Namespaces can be written to and loaded from pickled files.  See
    L{NamespaceArchive} for information.
    i    c         C   s.   | d k r t j d   n  |  j j |  S(   s   If a Namespace instance for the given URI exists, return it; otherwise return None.

        Note: Absent namespaces are not stored in the registry.  If you use
        one (e.g., for a schema with no target namespace), don't lose hold of
        it.s!   Absent namespaces are unlocatableN(   R   R   t
   UsageErrort   _Namespace__RegistryR   (   t   clsR-   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   _NamespaceForURI  s    t   absentc         C   s   |  j    d k ru |  j d k r\ t j d  t j j j   |  _ |  |  j	 |  j j
   <n  |  j |  j j
   f f S|  j    f S(   s   Pickling support.

        To ensure that unpickled Namespace instances are unique per
        URI, we ensure that the routine that creates unpickled
        instances knows what it's supposed to return.sE   Instances with absent namespaces can only be reconstructed in-sessionN(   R-   R   t    _Namespace__absentSerializedUUIDR   t   warningR   R9   R:   t   UniqueIdentifiert#   _Namespace__AbsentNamespaceRegistryt   uidt#   _Namespace__SerializedVariantAbsent(   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   __getnewargs__  s    c         O   s   | \ } t  | t  r | \ } } |  j | k rg |  j j |  } | d k rc t j d   n  | St j d | | f   na | |  j	 k r t
 j |   } | | _ | j   | d k r |  j j |  | S| |  j	 | <n  |  j	 | S(   s  Pickling and singleton support.

        This ensures that no more than one Namespace instance exists
        for any given URI.  We could do this up in __init__, but that
        doesn't normally get called when unpickling instances; this
        does.  See also __getnewargs__().s2   Unable to reconstruct instance of absent namespaces3   Unrecognized serialized namespace variant %s uid %sN(   R   R!   R   R   R   R   R   R   R   R   t   objectt   __new__t   _Namespace__uriRL   t   _Namespace__AbsentNamespacesR   (   R   R1   R2   R-   t   variantR   R   t   instance(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR     s$    		
c         C   s   |  j  j t j |  j   S(   s7   Return a set of all Namespace instances defined so far.(   R   t   unionR    Rp   R   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR     s    c
         C   s   t  t |   j   | |  _ |	 |  _ | d k	 }
 |
 sX | d k	 rX t j d   qX n  |  j | k sm t	  | |  _
 | |  _ |
 |  _ | |  _ | |  _ | |  _ | |  _ |  j   |  j d k s |  j |  j |  k s t	  d S(   s+  Create a new Namespace.

        The URI must be non-None, and must not already be assigned to
        a Namespace instance.  See _NamespaceForURI().

        User-created Namespace instances may also provide a description.

        Users should never provide a builtin_namespace parameter.
        s1   Only permanent Namespaces may have bound prefixesN(   R   R,   R0   t#   _Namespace__contextDefaultNamespacet$   _Namespace__contextInScopeNamespacesR   R   R   R   R   t   _Namespace__boundPrefixt   _Namespace__descriptiont   _Namespace__isBuiltinNamespacet$   _Namespace__builtinNamespaceVariablet   _Namespace__builtinModulePatht!   _Namespace__isUndeclaredNamespacet   _Namespace__isLoadedNamespaceRL   R   (   R   R-   t   descriptiont   builtin_namespacet   builtin_module_patht   is_undeclared_namespacet   is_loaded_namespacet   bound_prefixt   default_namespacet   in_scope_namespacest   is_builtin_namespace(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR0     s"    									
c         C   s?   |  j    s t  t t t |   d d      d  |  _ d  S(   NRL   c          _   s   d  S(   N(   R   (   R1   R2   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR     s    (   t   isActiveR   RM   R   R,   R   t#   _Namespace__initialNamespaceContext(   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyRL     s    c         C   s   |  j  S(   s   Return the URI for the namespace represented by this instance.

        If the URI is None, this is an absent namespace, used to hold
        declarations not associated with a namespace (e.g., from schema with
        no target namespace).(   R   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR-     s    c         C   st   |  j  d  k	 r7 |  j  | k r" |  St j |  d   n  d  | k	 rg d t |  k rg t j d   n  | |  _ |  S(   Ns-   Cannot change the prefix of a bound namespacei    s   prefix must be non-empty string(   R   R   R   RT   R   R   t   _Namespace__prefix(   R   t   prefix(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt	   setPrefix  s    	c         C   s   |  j  r |  j  S|  j S(   N(   R   R   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR   (  s    	c         C   s   |  j  d k S(   s   Return True iff this namespace is an absent namespace.

        Absent namespaces have no namespace URI; they exist only to
        hold components created from schemas with no target
        namespace.N(   R   R   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR)   -  s    c         C   s   |  j    r |  Sd S(   s   When known to be operating in this namespace, provide the Namespace
        instance to be used when names are associated with no namespace.N(   R)   R   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   fallbackNamespace5  s    c         C   s+   t  d  } |  j | _ |  j d 7_ | S(   s   Create an absent namespace.

        Use this instead of the standard constructor, in case we need
        to augment it with a uuid or the like.i   N(   R,   R   t   _Namespace__absentNamespaceID(   R   t   rv(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR   <  s    c         C   s   |  j    s t  | |  _ d  S(   N(   R)   R   R   (   R   R-   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   _overrideAbsentNamespaceH  s    c         C   s   |  j  S(   sD  Return the standard prefix to be used for this namespace.

        Only a few namespace prefixes are bound to namespaces: xml and xmlns
        are two.  In all other cases, this method should return None.  The
        infrastructure attempts to prevent user creation of Namespace
        instances that have bound prefixes.(   R   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   boundPrefixL  s    c         C   s   |  j  S(   s   Return True iff this namespace was defined by the infrastructure.

        That is the case for all namespaces in the Namespace module.(   R   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   isBuiltinNamespaceU  s    c         C   s#   |  j  d  k	 s t  d |  j  f S(   Ns   pyxb.namespace.%s(   R   R   R   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   builtinNamespaceRepresentation[  s    c         C   sx   d d l  m } |  j s2 t j d |  f   n  |  j | j  } | d  k	 sV t  | j	   |  j k sq t  |  j S(   Ni(   t   builtins$   Namespace has no built-in module: %s(
   t   pyxb.namespaceR   R   R   R   t   lookupModuleRecordByUIDt   BuiltInObjectUIDR   R   t
   modulePath(   R   R   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   builtinModulePath_  s    	c         C   s   |  j  S(   s  Return True iff this namespace is always available
        regardless of whether there is a declaration for it.

        This is the case only for the
        xml(http://www.w3.org/XML/1998/namespace) and
        xmlns(http://www.w3.org/2000/xmlns/) namespaces.(   R   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   isUndeclaredNamespaceh  s    c         C   s   |  j  S(   sF   Return C{True} iff this namespace was loaded from a namespace archive.(   R   (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   isLoadedNamespaceq  s    c         C   s   |  j  S(   so   Return C{True} iff this namespace has been saved to a namespace archive.
        See also L{isLoadedNamespace}.(   t   _Namespace__hasBeenArchived(   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   hasBeenArchivedu  s    c         C   s   | d k	 r | |  _ n  |  j S(   s4   Get, or set, a textual description of the namespace.N(   R   R   (   R   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR   z  s    c         G   s"   | j  |  j   k o! | j | k S(   N(   R   R-   R   (   R   t   nodet   local_names(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   nodeIsNamed  s    c         C   s   t  |  |  S(   N(   R   (   R   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   createExpandedName  s    c         C   s   i  S(   s   Support pickling.

        Well, no, not really.  Because namespace instances must be unique, we
        represent them as their URI, and that's done by __getnewargs__
        above.  All the interesting information is in the ModuleRecords.(    (   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   __getstate__  s    c         C   s   d  S(   N(    (   R   t   structures_module(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   _defineBuiltins_ox  s    c         C   ss   |  j    s t  |  j so d d l m } |  j | j d t d |  j } |  j	 |  t |  _ | j
   n  |  S(   Ni(   R   R   t   module_path(   R   R   t   _Namespace__definedBuiltinsR   R   R   R   R+   R   R   t   markIncorporated(   R   R   R   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   _defineBuiltins  s    	!	c         C   s   x |  j    D] } | j   r | j   r t j d | | j    y | j   j   Wq t j k
 r{ t j	 d  q Xq t j d |  q q W|  j
   d S(   s  Attempts to load the named objects held in this namespace.

        The base class implementation looks at the set of available archived
        namespaces, and if one contains this namespace unserializes its named
        object maps.

        Sub-classes may choose to look elsewhere, if this version fails or
        before attempting it.

        There is no guarantee that any particular category of named object has
        been located when this returns.  Caller must check.
        s   Load %s from %ss%   Failure reading namespaces in archives(   Ignoring private module %s in validationN(   R   t
   isLoadablet   isPublicR   R   R   t   readNamespacesR   t   NamespaceArchiveErrort	   exceptionRZ   (   R   R   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   _loadComponentsFromArchives  s    c         C   s}   |  j  sy | d k r* d d l j j } n  |  j   rF |  j |  n  z# t |  _ |  j	 |  t |  _  Wd t
 |  _ Xn  t S(   s   Ensure this namespace is ready for use.

        If the namespace does not have a map of named objects, the system will
        attempt to load one.
        iN(   t   _Namespace__didValidationR   t   pyxb.xmlschema.structurest	   xmlschemat
   structuresR   R  R+   t   _Namespace__inValidationR  R8   (   R   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR	     s    		c         C   s   |  j  | |  S(   s  Replace the existing definition with another.

        This is used in a situation where building the component model
        resulted in a new component instance being created and registered, but
        for which an existing component is to be preferred.  An example is
        when parsing the schema for XMLSchema itself: the built-in datatype
        components should be retained instead of the simple type definition
        components dynamically created from the schema.

        By providing the value C{None} as the replacement definition, this can
        also be used to remove components.

        @note: Invoking this requires scans of every item in every category
        map in the namespace.

        @return: C{replacement_def}
        (   Rd   (   R   Rh   Re   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   _replaceComponent  s    c         C   s   |  j  d k r i  } |  j d k	 r] x6 t j |  j  D] \ } } |  j |  | | <q7 Wn  i |  d 6|  j |  j  d 6| d 6} t j d |  |  _  n  |  j  S(   s  Obtain the namespace context to be used when creating components in this namespace.

        Usually applies only to built-in namespaces, but is also used in the
        autotests when creating a namespace without a xs:schema element.  .
        Note that we must create the instance dynamically, since the
        information that goes into it has cross-dependencies that can't be
        resolved until this module has been completely loaded.t   target_namespaceR   R   N(	   R   R   R   R    Rf   t   _Namespace__identifyNamespaceR   R   t   NamespaceContext(   R   t   isnRk   Rl   R2   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   initialNamespaceContext  s    	

c         C   sd   | d k r |  St | t j  r7 t   j |  } n  t | t  rJ | St j d | f   d S(   s  Identify the specified namespace, which should be a built-in.

        Normally we can just use a reference to the Namespace module instance,
        but when creating those instances we sometimes need to refer to ones
        for which the instance has not yet been created.  In that case, we use
        the name of the instance, and resolve the namespace when we need to
        create the initial context.s!   Cannot identify namespace from %sN(	   R   R   R    R    t   globalsR   R,   R   R   (   R   t   nsval(    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   __identifyNamespace  s    c         C   sg   |  j  d  k r d |  j f S|  j  d  k	 s2 t  |  j d  k	 rZ d |  j |  j  f } n	 |  j  } | S(   Ns   AbsentNamespace%ds   %s=%s(   R   R   R   R   R   (   R   R   (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR4     s    	N(>   RD   RE   RF   R   R   R   R   R   R   Ro   R   R   R8   R   R   R   t   _Namespace__namespaceArchiveR   R   t    _Namespace__bindingConfigurationR   R   R   t   classmethodR   R   R   R   R   R   R   R0   RL   R-   R   R   R)   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R  R	  R  R	   R  R  R  R4   (    (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyR,   A  s~   			'			
																			
				(   t   XMLSchema_instance(   t   XMLNamespaces(   t	   XMLSchema(   t   XHTML(   t   XML(   t   XMLSchema_hfp(   R   R   R   (,   RF   R   t   pyxb.utils.utilityt
   pyxb.utilsR    t   xml.domR"   t   loggingt	   getLoggerRD   R   R9   R:   t   BackfillComparisonst   cscRootR   Rm   RG   RK   t   PrivateTransient_mixinR   R   R   R   t   pyxb.namespace.utilityR   R*   R   R   R   R  t   _NamespaceResolution_mixint   _NamespaceArchivable_mixinR,   t   pyxb.namespace.builtinR  R  R  R  R  R  R   t   _AddTargetNamespaceAttributeR   (    (    (    sL   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/__init__.pyt   <module>   s:   %1O	% 