
e#]c           @   s   d  Z  d d l Z d d l Z d d l Z d d l m Z m Z d d l m Z e j	 e
  Z d e j f d     YZ d e j f d     YZ d	   Z e j d
 e f d     Y Z d S(   s   Classes and global objects related to resolving U{XML
Namespaces<http://www.w3.org/TR/2006/REC-xml-names-20060816/index.html>}.iN(   t   archivet   utility(   t   sixt   _Resolvable_mixinc           B   s5   e  Z d  Z e Z d   Z d   Z d d d  Z RS(   sV  Mix-in indicating that this object may have references to unseen named components.

    This class is mixed-in to those XMLSchema components that have a reference
    to another component that is identified by a QName.  Resolution of that
    component may need to be delayed if the definition of the component has
    not yet been read.
    c         C   s    t  d t |   j f   d S(   s^   Determine whether this named component is resolved.

        Override this in the child class.s"   _Resolvable_mixin.isResolved in %sN(   t   NotImplementedErrort   typet   __name__(   t   self(    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt
   isResolved'   s    c         C   s    t  d t |   j f   d S(   st  Perform whatever steps are required to resolve this component.

        Resolution is performed in the context of the namespace to which the
        component belongs.  Invoking this method may fail to complete the
        resolution process if the component itself depends on unresolved
        components.  The sole caller of this should be
        L{_NamespaceResolution_mixin.resolveDefinitions}.

        This method is permitted (nay, encouraged) to raise an exception if
        resolution requires interpreting a QName and the named component
        cannot be found.

        Override this in the child class.  In the prefix, if L{isResolved} is
        true, return right away.  If something prevents you from completing
        resolution, invoke L{self._queueForResolution()} (so it is retried
        later) and immediately return self.  Prior to leaving after successful
        resolution discard any cached dom node by setting C{self.__domNode=None}.

        @return: C{self}, whether or not resolution succeeds.
        @raise pyxb.SchemaValidationError: if resolution requlres a reference to an unknown component
        s    _Resolvable_mixin._resolve in %sN(   R   R   R   (   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   _resolve-   s    c         C   sH   | d k	 r. |  j r. t j d |  | |  n  |  j   j |  |  d S(   sU   Short-hand to requeue an object if the class implements _namespaceContext().
        s-   Resolution delayed for %s: %s
	Depends on: %sN(   t   Nonet   _TraceResolutiont   _logt   infot   _namespaceContextt   queueForResolution(   R   t   whyt
   depends_on(    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   _queueForResolutionE   s    N(	   R   t
   __module__t   __doc__t   FalseR   R   R	   R
   R   (    (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR      s
   		t   _NamespaceResolution_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 d	  Z d
   Z d   Z e d  Z d   Z d   Z RS(   sj   Mix-in that aggregates those aspects of XMLNamespaces relevant to
    resolving component references.
    c         C   sM   t  t t |   d d      g  |  _ i  |  _ t   |  _ t   |  _ d S(   sk   CSC extension to reset fields of a Namespace.

        This one handles component-resolution--related data.t   _resetc          _   s   d  S(   N(   R
   (   t   argst   kw(    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   <lambda>f   s    N(   t   getattrt   superR   t0   _NamespaceResolution_mixin__unresolvedComponentst0   _NamespaceResolution_mixin__unresolvedDependentst   sett.   _NamespaceResolution_mixin__importedNamespacest0   _NamespaceResolution_mixin__referencedNamespaces(   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR   b   s
    		c         C   sC   | j  i |  j d 6|  j d 6 t t t |   d d    |  S(   Nt   importedNamespacest   referencedNamespacest   _getState_cscc         S   s   |  S(   N(    (   t   _kw(    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR   q   s    (   t   updateR    R!   R   R   R   (   R   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR$   l   s    	
c            sB   | d   _  | d   _ t t t    d   f d    |  S(   NR"   R#   t   _setState_cscc            s     S(   N(    (   R%   (   R   (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR   v   s    (   R    R!   R   R   R   (   R   R   (    (   R   sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR'   s   s    c         C   s   |  j  j |  |  S(   N(   R    t   add(   R   t	   namespace(    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   importNamespacex   s    c         C   s   |  j    |  j j |  |  S(   N(   t	   _activateR!   R(   (   R   R)   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   _referenceNamespace|   s    
c         C   s   t  |  j  S(   so   Return the set of namespaces which some schema imported while
        processing with this namespace as target.(   t	   frozensetR    (   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR"      s    c         C   s9   t  | t j  s t  | j |  j  |  j j   d  S(   N(   t
   isinstanceR    t   ModuleRecordt   AssertionErrort   _setReferencedNamespacesR!   t   clear(   R   t   module_record(    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   _transferReferencedNamespaces   s    c         C   s   t  |  j  S(   st   Return the set of namespaces which appear in namespace declarations
        of schema with this namespace as target.(   R-   R!   (   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR#      s    c         C   s   t  | t  s t  | j   s | d k sB t  | t  sB t  |  j j |  | d k	 r | j   r d d l m } t  | t  s t  t  | | j	  s t  |  j
 j | t    j |  q n  | S(   sI  Invoked to note that a component may have references that will need
        to be resolved.

        Newly created named components are often unresolved, as are components
        which, in the course of resolution, are found to depend on another
        unresolved component.

        @param resolvable: An instance of L{_Resolvable_mixin} that is later to
        be resolved.

        @keyword depends_on: C{None}, or an instance of L{_Resolvable_mixin}
        which C{resolvable} requires to be resolved in order to resolve
        itself.

        @return: C{resolvable}
        i(   t
   structuresN(   R.   R   R0   R   R
   R   t   appendt   pyxb.xmlschemaR5   t   _NamedComponent_mixinR   t
   setdefaultR   R(   (   R   t
   resolvableR   R5   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR      s    !%c         C   s   |  j  d k	 S(   s8   Return C{True} iff this namespace has not been resolved.N(   R   R
   (   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   needsResolution   s    c            s   y| |  j  j |  }   d k s0   |  j  k r= |  j  | =n" t   t  sR t    |  j  | <| |  j k r{ |  j | =n  Wn t k
 r n Xt t	 t
 |   d   f d    |    S(   sX   Replace a component definition if present in the list of unresolved components.
        t   _replaceComponent_cscc             s     S(   N(    (   R   R   (   t   replacement_def(    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR      s    N(   R   t   indexR
   R.   R   R0   R   t
   ValueErrorR   R   R   (   R   t   existing_defR=   R>   (    (   R=   sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR<      s    c         C   s  |  j    s t Sxad t |  j  k  rs|  j } g  |  _ i  |  _ xs | D]k } | j   | j   s | |  j k s t d | f   | j   rJ | j   d	 k	 rJ t
 s t  qJ qJ W|  j | k r | r t
 Sg  } d d l m } xc |  j D]X } t | | j  r0| j d | j j | j   f  q | j d | j j f  q Wt j d d j |  f   q q Wd	 |  _ d	 |  _ |  j   t S(
   s  Loop until all references within the associated resolvable objects
        have been resolved.

        This method iterates through all components on the unresolved list,
        invoking the _resolve method of each.  If the component could not be
        resolved in this pass, it iis placed back on the list for the next
        iteration.  If an iteration completes without resolving any of the
        unresolved components, a pyxb.NotInNamespaceError exception is raised.

        @note: Do not invoke this until all top-level definitions for the
        namespace have been provided.  The resolution routines are entitled to
        raise a validation exception if a reference to an unrecognized
        component is encountered.
        i    s   Lost resolvable %si(   R5   s   %s named %ss   Anonymous %ss!   Infinite loop in resolution:
  %ss   
  N(   R;   t   Truet   lenR   R   R	   R   R0   t   _clonesR
   R   R7   R5   R.   R8   R6   t	   __class__R   t   namet   pyxbt   NotInNamespaceErrort   joint   _releaseNamespaceContexts(   R   t   allow_unresolvedt
   unresolvedR:   t   failed_componentsR5   t   d(    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   resolveDefinitions   s2    			
.&&		
c         C   s   |  j  S(   s9   Returns a reference to the list of unresolved components.(   R   (   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   _unresolvedComponents  s    c         C   s   |  j  S(   sc   Returns a map from unresolved components to sets of components that
        must be resolved first.(   R   (   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   _unresolvedDependents  s    N(   R   R   R   R
   R    R!   R   R   R   R$   R'   R*   R,   R"   R4   R#   R   R;   R<   R   RN   RO   RP   (    (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR   L   s&   	
									D	c      	   C   sA  x1 |  D]) } | j  t j j   g  | j   q Wd   } t |   } i  } d } x| r<t |  } | r | j d | |   n  t   } i  } x| D] } | j	   s q n  | j
 d t  s | j | t    } xb t j | j    D]K \ } }	 x< |	 D]4 }
 |
 j   j   } | | k r| j |  qqWq Wt j d | j   t j d  j g  | D] } t j |  ^ qk  | j |  q q Wg  } x- | D]% } | j | t | j    f  qWt |  } | | k r3t j d t j d  j g  | D] } t j |  ^ q f   n  | } qX Wd S(	   s   Resolve all components in the sibling_namespaces.

    @param sibling_namespaces : A set of namespaces expected to be closed
    under dependency.c            s    d t  f   f d     Y} | S(   s   Sort namespaces so dependencies get resolved first.

        Uses the trick underlying functools.cmp_to_key(), but optimized for
        this special case.  The dependency map is incorporated into the class
        definition by scope.
        t   Kc              sS   e  Z d    Z   f d   Z   f d   Z d   Z d   Z d   Z d   Z RS(   c         W   s   | |  _  d  S(   N(   t   _K__ns(   R   t   nsR   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   __init__"  s    c            s@   |  j    j | j  t    k o? | j    j |  j  t    k S(   N(   RR   t   getR   (   R   t   other(   t   dependency_map(    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   __lt__'  s    !c            s@   |  j    j | j  t    k | j    j |  j  t    k k S(   N(   RR   RU   R   (   R   RV   (   RW   (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   __eq__-  s    c         S   s   |  j  |  S(   N(   RY   (   R   RV   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   __ne__1  s    c         S   s   |  j  |  p |  j |  S(   N(   RX   RY   (   R   RV   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   __le__3  s    c         S   s   | j  |  j  S(   N(   RX   RR   (   R   RV   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   __gt__5  s    c         S   s   | j  |  j  p |  j |  S(   N(   RX   RR   RY   (   R   RV   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   __ge__7  s    (	   R   R   RT   RX   RY   RZ   R[   R\   R]   (    (   RW   (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyRQ   !  s   				(   t   object(   RW   RQ   (    (   RW   sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   __keyForCompare  s    t   keyRJ   s/   Holding incomplete resolution %s depending on: s    ; s8   Unexpected external dependency in sibling namespaces: %ss   
  N(   t   configureCategoriesR    t   NamespaceArchivet   _AnonymousCategoryt   validateComponentModelR   R
   t   listt   sortR;   RN   RA   R9   R   t	   iteritemsRP   t   expandedNameR)   R(   R   R   t   urit   uRH   t	   text_typeR6   RB   RO   t   tupleRF   t
   LogicError(   t   sibling_namespacesRS   R_   t   need_resolved_setRW   t
   last_statet   need_resolved_listt   depst   ct   dcst   dct   dnst   _dnst   statet   _ns(    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   ResolveSiblingNamespaces  s@    	!		"G#Gt   NamespaceContextc        
   B   s  e  Z d  Z d   Z g  Z e d    Z e d    Z e d    Z i  Z	 e d    Z
 e d    Z d Z d   Z d Z d   Z 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 e d    Z d   Z  e d    Z! d   Z" d Z# d e d  Z$ d   Z% d d d  Z& d   Z' d d d e( d d d d e( d 	 Z) d e d  Z* d d  Z+ RS(   sB   Records information associated with namespaces at a DOM node.
    c         C   s   t  j d  g } |  j   d  k	 rL | j d t  j |  j    d g  n  |  j   d  k	 r | j d t  j |  j    d g  n  | j d  xR t  j |  j	    D]; \ } } | d  k	 r | j d | t  j |  f  q q Wt  j d  j
 |  S(   Ns   NamespaceContext s   (defaultNamespace=s   ) s   (targetNamespace=s   
s     xmlns:%s=%st    (   R   Rj   t   defaultNamespaceR
   t   extendRk   t   targetNamespaceR6   Rg   t   inScopeNamespacesRH   (   R   t   rvt   pfxRS   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   __str__b  s    (("'c         C   s)   t  | |   s t  |  j j |  | S(   si   Make C{ctx} the currently active namespace context.

        Prior contexts are retained on a LIFO stack.(   R.   R0   t   _NamespaceContext__ContextStackR6   (   t   clst   ctx(    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   PushContexto  s    c         C   s   |  j  r |  j  d Sd S(   s   Access the currently active namespace context.

        If no context is active, C{None} is returned.  This probably
        represents mis-use of the infrastructure (viz., failure to record the
        context within which a QName must be resolved).iN(   R   R
   (   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   Currentx  s    	c         C   s   |  j  j   S(   s~   Discard the currently active namespace context, restoring its
        predecessor.

        The discarded context is returned.(   R   t   pop(   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt
   PopContext  s    c         C   s#   | d  k	 s t  | |  j | <d  S(   N(   R
   R0   t,   _NamespaceContext__TargetNamespaceAttributes(   R   t   expanded_namet   attribute_name(    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   _AddTargetNamespaceAttribute  s    c         C   s   |  j  j |  S(   N(   R   RU   (   R   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   _TargetNamespaceAttribute  s    c         C   s   |  j  S(   sL   The default namespace in effect at this node.  E.g., C{xmlns="URN:default"}.(   t#   _NamespaceContext__defaultNamespace(   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR}     s    c         C   sa   t  | t j  r* t j | d t } n  | d k	 rT | j   rT t j	 d   n  | |  _
 d S(   s  Set the default namespace for the generated document.

        Even if invoked post construction, the default namespace will affect
        the entire document, as all namespace declarations are placed in the
        document root.

        @param default_namespace: The namespace to be defined as the default
        namespace in the top-level element of the document.  May be provided
        as a real namespace, or just its URI.
        @type default_namespace: L{pyxb.namespace.Namespace} or C{str} or
        C{unicode}.
        t   create_if_missings1   Default namespace must not be an absent namespaceN(   R.   R   t   string_typesR   t   NamespaceForURIRA   R
   t   isAbsentNamespaceRF   t
   UsageErrorR   (   R   t   default_namespace(    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   setDefaultNamespace  s
    c         C   s   |  j  S(   s   The target namespace in effect at this node.  Usually from the
        C{targetNamespace} attribute.  If no namespace is specified for the
        schema, an absent namespace was assigned upon creation and will be
        returned.(   t"   _NamespaceContext__targetNamespace(   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR     s    c         C   s   |  j  S(   s   Map from prefix strings to L{Namespace} instances associated with those
        prefixes.  The prefix C{None} identifies the default namespace.(   t$   _NamespaceContext__inScopeNamespaces(   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR     s    c         C   sV   |  j  j | d   } | d  k	 rR |  j j |  } | d  k	 rR | j |  qR n  d  S(   N(   R   R   R
   t"   _NamespaceContext__inScopePrefixesRU   t   discard(   R   R   RS   t   pfxs(    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   __removePrefixMap  s
    c         C   s0   | |  j  | <|  j j | t    j |  d  S(   N(   R   R   R9   R   R(   (   R   R   RS   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   __addPrefixMap  s    c         C   sX   |  j  j   |  _  i  } x0 t j |  j  D] \ } } | j   | | <q+ W| |  _ d  S(   N(   R   t   copyR   Rg   R   (   R   t   ispRS   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   __clonePrefixMap  s
    c         C   s~   |  j  d  k	 r d  Sd d l m } | j |  _  i  |  _ x? t j |  j   D]+ \ } } |  j j | t	    j
 |  qK Wd  S(   Ni(   t   builtin(   t)   _NamespaceContext__InitialScopeNamespacesR
   t   pyxb.namespaceR   t   _UndeclaredNamespaceMapt'   _NamespaceContext__InitialScopePrefixesR   Rg   R9   R   R(   (   R   R   R   RS   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   __BuildInitialPrefixMap  s    	c         C   s,   |  j  j |  } | r( t t |   Sd S(   s   Return a prefix associated with the given namespace in this
        context, or None if the namespace is the default or is not in
        scope.N(   R   RU   t   nextt   iterR
   (   R   R)   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   prefixForNamespace  s    c         K   s-   y | j  SWn t k
 r( t | |  SXd S(   s  Get the L{NamespaceContext} instance that was assigned to the node.

        If none has been assigned and keyword parameters are present, create
        one treating this as the root node and the keyword parameters as
        configuration information (e.g., default_namespace).

        @raise pyxb.LogicError: no context is available and the keywords
        required to create one were not provided
        N(   t#   _NamespaceContext__namespaceContextt   AttributeErrorR{   (   R   t   nodeR   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   GetNodeContext  s    c         C   s   |  | _  d  S(   N(   R   (   R   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   setNodeContext  s    c         C   s]  t  | t j j  s' t j d   n  | j   rE t j d   n  | d k r` | j   } n  | d k r |  j j	 |  } | r t
 t |   } q n  xG | d k r |  j d 7_ d |  j f } | |  j k r | } q q W|  j j	 |  } | r*| | k r&t j d | | f   n  | S|  j sI|  j   t |  _ n  |  j | |  | S(   s  Record the given namespace as one to be used in this document.

        @param namespace: The namespace to be associated with the document.
        @type namespace: L{pyxb.namespace.Namespace}

        @keyword prefix: Optional prefix to be used with this namespace.  If
        not provided, a unique prefix is generated or a standard prefix is
        used, depending on the namespace.

        @return: a prefix that may be used with the namespace.  If C{prefix}
        was C{None} the return value may be a previously-assigned prefix.

        @todo: ensure multiple namespaces do not share the same prefix
        @todo: provide default prefix in L{pyxb.namespace.Namespace}
        s4   declareNamespace: must be given a namespace instances;   declareNamespace: namespace must not be an absent namespacei   s   ns%ds"   Prefix %s is already in use for %sN(   R.   RF   R)   t	   NamespaceR   R   R
   t   prefixR   RU   R   R   t)   _NamespaceContext__namespacePrefixCounterR   Rm   t+   _NamespaceContext__mutableInScopeNamespacest!   _NamespaceContext__clonePrefixMapRA   t   _NamespaceContext__addPrefixMap(   R   R)   R   t
   add_to_mapR   t   candidate_prefixRS   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   declareNamespace  s2    	
c         C   s_  d d l  m } |  j s/ |  j   t |  _ n  | j j   | k r{ | d  k se | j j   | k ri d  St	 j
 d   n  | r| d  k r t j | d t } |  _ |  j |  j d  <n2 t j | d t } |  j |  |  j | |  |  j r
|  j j |  q[|  j j |  n> | d  k	 rEt	 j |  d | f   n  |  j |  d  |  _ d  S(   Ni(   R   s"   Cannot manipulate bound prefix xmlR   s,   Attempt to undefine non-default namespace %s(   R   R   R   R   RA   t   XMLt   boundPrefixR
   Ri   RF   Rm   R   R   R   R   t"   _NamespaceContext__removePrefixMapR   R   R,   t.   _NamespaceContext__pendingReferencedNamespacesR(   t   NamespaceError(   R   R   Ri   R   RS   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   processXMLNS;  s,    	
!	c         C   s-  | d  k	 r? d t |  k  s$ t  t j | d t |  _ no |  j d  k r | d  k	 ru | j   |  _ t |  _ q | d  k r t j	   |  _ q t j | d t |  _ n  |  j
 d  k	 r g  |  j
 D] } |  j j |  ^ q d  |  _ n  |  j d  k	 st  |  j r)|  j j   r)t |  _ n  d  S(   Ni    R   (   R
   RB   R0   R   R   RA   R   R   t,   _NamespaceContext__fallbackToTargetNamespacet   CreateAbsentNamespaceR   R,   t-   _NamespaceContext__pendingReferencedNamespaceR   (   R   t   tns_urit   including_contextRy   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   finalizeTargetNamespace^  s     &c         C   s.   |  j  |  _ |  j |  _ t |  _ d |  _ d S(   s  Reset this instance to the state it was when created, exclusive of
        XMLNS directives passed in a constructor C{dom_node} parameter.

        This preserves parent context and constructor-specified prefix maps,
        but clears the namespace-prefix mapping of any additions made while
        processing namespace directives in DOM nodes, or manually added
        post-construction.

        The defaultNamespace is also retained.i    N(   t)   _NamespaceContext__initialScopeNamespacesR   t'   _NamespaceContext__initialScopePrefixesR   R   R   R   (   R   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   resetv  s    
	c
      	   C   s  d d l  m }
 | d k	 rU y | j d k s4 t  Wn t k
 rH n X|  | _ n  | |  _ | |  _ |  j d k r |  j	   n  |  j |  _
 |  j |  _ t |  _ d |  _ | d k	 r| j
 |  _
 | j |  _ | j r |  j   n  | j   |  _ | j   |  _ | j |  _ n  | d k	 rs|  j   t |  _ x= t j |  D]) \ } } |  j |  |  j | |  qCWn  |  j
 |  _ |  j |  _ t |  _ |  j d k rt   |  _ n  i  } | d k	 r| d k rt j j |  } n  x t  | j! j"  D] } | j! j# |  } |
 j$ j%   | j& k r\| j' } d | k rFd } n  |  j( | | j)  q| j& d k	 rt* j+ | j& d t } t j j | | j'  } n t j j d | j'  } | j) | | <qWn  |	 rd } |  j, |  } | d k	 r| j- |  } |  j. | d | qn  | d k	 r| rd d l/ m0 } | j1 | j2 k sSt  xB | j3 D]4 } | j1 | j2 k r]t4 d | d	 |  d
 t  q]q]Wn  d S(   s  Determine the namespace context that should be associated with the
        given node and, optionally, its element children.

        Primarily this class maintains a map between namespaces and prefixes
        used in QName instances.  The initial map comprises the bound prefixes
        (C{xml} and C{xmlns}), prefixes inherited from C{parent_context}, and
        prefixes passed through the C{in_scope_namespaces}
        parameter to the constructor.  This map is then augmented by any
        namespace declarations present in a passed C{dom_node}.  The initial
        map prior to augmentation may be restored through the L{reset()}
        method.

        @param dom_node: The DOM node
        @type dom_node: C{xml.dom.Element}
        @keyword parent_context: Optional value that specifies the context
        associated with C{dom_node}'s parent node.  If not provided, only the
        C{xml} namespace is in scope.
        @type parent_context: L{NamespaceContext}
        @keyword recurse: If True (default), create namespace contexts for all
        element children of C{dom_node}
        @type recurse: C{bool}
        @keyword default_namespace: Optional value to set as the default
        namespace.  Values from C{parent_context} would override this, as
        would an C{xmlns} attribute in the C{dom_node}.
        @type default_namespace: L{NamespaceContext}
        @keyword target_namespace: Optional value to set as the target
        namespace.  Values from C{parent_context} would override this, as
        would a C{targetNamespace} attribute in the C{dom_node}
        @type target_namespace: L{NamespaceContext}
        @keyword in_scope_namespaces: Optional value to set as the initial set
        of in-scope namespaces.  The always-present namespaces are added to
        this if necessary.
        @type in_scope_namespaces: C{dict} mapping prefix C{string} to L{Namespace}.
        i(   R   i    t   xmlnsR   R   (   t   Nodet   dom_nodet   parent_contextt   recurseN(5   R   R   R
   R   R0   R   R   R   R   t(   _NamespaceContext__BuildInitialPrefixMapR   R   R   R   R   R   R   R}   R   R   RA   R   Rg   R   R   R   R   R   R   RF   R)   t   ExpandedNamet   ranget
   attributest   lengtht   itemt   XMLNamespacesRi   t   namespaceURIt	   localNameR   t   valueR   R   R   RU   R   t   xml.domR   t   ELEMENT_NODEt   nodeTypet
   childNodesR{   (   R   R   R   R   R   R   t   target_namespacet   in_scope_namespacesR   t   finalize_target_namespaceR   R   RS   t   attribute_mapt   ait   attrR   Ri   R`   R   t   tns_attrR   t   cn(    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyRT     s|    ,					
				c         C   s;  t  | t j j  r | St  | t j  s1 t  d | j d  k r | j d d  \ } } |  j	   d k	 sv t  |  j	   j |  } | d k r(t j d | |    q(nv | } |  j   d k	 r |  j   } n  | d k r |  j r |  j   } n  | d k r(| r(t j d | |    n  t j j | |  S(   s  Convert the provided name into an L{ExpandedName}, i.e. a tuple of
        L{Namespace} and local name.

        If the name includes a prefix, that prefix must map to an in-scope
        namespace in this context.  Absence of a prefix maps to
        L{defaultNamespace()}, which must be provided (or defaults to the
        target namespace, if that is not absent).

        @param name: A QName.
        @type name: C{str} or C{unicode}
        @param name: Optional namespace to use for unqualified names when
        there is no default namespace.  Note that a defined default namespace,
        even if absent, supersedes this value.
        @keyword default_no_namespace: If C{False} (default), an NCName in a
        context where C{namespace} is C{None} and no default or fallback
        namespace can be identified produces an exception.  If C{True}, such an
        NCName is implicitly placed in no namespace.
        @return: An L{ExpandedName} tuple: ( L{Namespace}, C{str} )
        @raise pyxb.QNameResolutionError: The prefix is not in scope
        @raise pyxb.QNameResolutionError: No prefix is given and the default namespace is absent
        i    t   :i   s#   No namespace declaration for prefixs<   NCName with no fallback/default namespace cannot be resolvedN(   R.   RF   R)   R   R   R   R0   t   findt   splitR   R
   RU   t   QNameResolutionErrorR}   R   R   (   R   RE   R)   t   default_no_namespaceR   t
   local_name(    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   interpretQName  s"    c         C   s+   t  | t  s t  |  j   j | |  S(   sZ   Forwards to L{queueForResolution()<Namespace.queueForResolution>} in L{targetNamespace()}.(   R.   R   R0   R   R   (   R   t	   componentR   (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR   *  s    N(,   R   R   R   R   R   t   classmethodR   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   R   R   R   R   R   RA   RT   R   R   (    (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyR{   ]  s\   									
			*	#	p,(   R   t   loggingRF   t   pyxb.utils.utilityR   R    R   t
   pyxb.utilsR   t	   getLoggerR   R   t   cscRootR   R   Rz   t   python_2_unicode_compatibleR^   R{   (    (    (    sN   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/namespace/resolution.pyt   <module>   s   1	M	