
f#]c           @   sW  d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z e j e	  Z
 d e f d     YZ d e f d     YZ d	 e f d
     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d f  d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d      YZ d! e f d"     YZ d# e f d$     YZ d% e f d&     YZ d' e f d(     YZ d) e f d*     YZ d+ e f d,     YZ  d- e f d.     YZ! d/ e e f d0     YZ" d1 e f d2     YZ# d S(3   s  This module provides Finite Automata with Counters.

FACs are type of state machine where a transition may include a
constraint and a modification to a set of counters.  They are used to
implement regular expressions with numerical constraints, as are found
in POSIX regexp, Perl, and XML schema.

The implementation here derives from U{Regular Expressions with
Numerical Constraints and Automata with Counters
<https://bora.uib.no/bitstream/1956/3628/3/Hovland_LNCS%205684.pdf>},
Dag Hovland, Lecture Notes in Computer Science, 2009, Volume 5684,
Theoretical Aspects of Computing - ICTAC 2009, Pages 231-245.  In what
follows, this reference will be denoted B{HOV09}.

A regular expression is directly translated into a term tree, where
nodes are operators such as sequence, choice, and counter
restrictions, and the leaf nodes denote symbols in the language of the
regular expression.

In the case of XML content models, the symbols include L{element
declarations <pyxb.xmlschema.structures.ElementDeclaration>} and
L{wildcard elements <pyxb.xmlschema.structures.Wildcard>}.  A
numerical constraint node corresponds to an L{XML particle
<pyxb.xmlschema.structures.Particle>}, and choice and sequence nodes
derive from L{model groups <pyxb.xmlschema.structures.ModelGroup>} of
types B{choice} and B{sequence}.  As suggested in U{The Membership
Problem for Regular Expressions with Unordered Concatenation and
Numerical Constraints <http://www.ii.uib.no/~dagh/presLATA2012.pdf>}
the B{all} content model can be translated into state machine using
choice and sequence at the cost of a quadratic size explosion.  Since
some XML content models might have a hundred terms in an unordered
catenation, this is not acceptable, and the implementation here
optimizes this construct by creating a leaf node in the automaton
which in turn contains sub-automata for each term, and permits an exit
transition only when all the terms that are required have been
completed.

@note: In XSD 1.1 the restriction that terms in an B{all} model group
occur at most once has been removed.  Since the current implementation
removes a completed term from the set of available terms, this will
not work: instead the subconfiguration with its counter values must be
retained between matches.
iN(   t   six(   t   xranget   FACErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   D   s   t   InvalidTermTreeErrorc           B   s#   e  Z d  Z d Z d Z d   Z RS(   s   Exception raised when a FAC term tree is not a tree.

    For example, a L{Symbol} node appears multiple times, or a cycle is detected.c         G   s,   | \ |  _  |  _ t t |   j |   d  S(   N(   t   parentt   termt   superR   t   __init__(   t   selft   args(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	   R   s    N(   R   R   t   __doc__t   NoneR   R   R	   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   G   s   t   UpdateApplicationErrorc           B   s#   e  Z d  Z d Z d Z d   Z RS(   s   Exception raised when an unsatisfied update instruction is executed.

    This indicates an internal error in the implementation.c         G   s,   | \ |  _  |  _ t t |   j |   d  S(   N(   t   update_instructiont   valuesR   R   R	   (   R
   R   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	   a   s    N(   R   R   R   R   R   R   R	   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   V   s   t   AutomatonStepErrorc           B   s8   e  Z d  Z d Z d Z d   Z e e  Z d   Z	 RS(   s  Symbol rejected by L{Configuration_ABC.step}.

    The exception indicates that the proposed symbol either failed to
    produce a transition (L{UnrecognizedSymbolError}) or produced
    multiple equally valid transitions
    (L{NondeterministicSymbolError}).c         C   s   |  j  j   S(   sK   A list of symbols that the configuration would accept in its current state.(   t   configurationt   acceptableSymbols(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_acceptableu   s    c         G   s,   | \ |  _  |  _ t t |   j |   d  S(   N(   R   t   symbolR   R   R	   (   R
   R   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	   z   s    N(
   R   R   R   R   R   R   t#   _AutomatonStepError__get_acceptablet   propertyt
   acceptableR	   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   e   s   	t   UnrecognizedSymbolErrorc           B   s   e  Z d  Z RS(   s8   L{Configuration.step} failed to find a valid transition.(   R   R   R   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   ~   s   t   NondeterministicSymbolErrorc           B   s   e  Z d  Z RS(   s1   L{Configuration.step} found multiple transitions.(   R   R   R   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR      s   t   SymbolMatch_mixinc           B   s   e  Z d  Z d   Z RS(   s   Mix-in used by symbols to provide a custom match implementation.

    If a L{State.symbol} value is an instance of this mix-in, then it
    will be used to validate a candidate symbol for a match.c         C   s    t  d t |   j f   d  S(   Ns   %s.match(   t   NotImplementedErrort   typeR   (   R
   R   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   match   s    (   R   R   R   R   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR      s   t   Statec           B   s@  e  Z d  Z d e d  Z d Z d   Z d   Z e	 e  Z
 d Z d   Z e	 e  Z d Z d   Z e	 e  Z d Z d   Z d   Z e	 e  Z d Z d   Z e	 e  Z d Z d	   Z e	 e  Z d Z d
   Z e	 e  Z d d  Z d   Z d Z  d   Z! e	 e!  Z" d   Z# d   Z$ d   Z% d   Z& RS(   sU  A thin wrapper around an object reference.

    The state of the automaton corresponds to a position, or marked
    symbol, in the term tree.  Because the same symbol may appear at
    multiple locations in the tree, and the distinction between these
    positions is critical, a L{State} wrapper is provided to maintain
    distinct values.c         C   s*   | |  _  | |  _ | |  _ | |  _ d S(   s  Create a FAC state.

        @param symbol: The symbol associated with the state.
        Normally initialized from the L{Symbol.metadata} value.  The
        state may be entered if, among other conditions, the L{match}
        routine accepts the proposed input as being consistent with
        this value.

        @param is_initial: C{True} iff this state may serve as the
        first state of the automaton.

        @param final_update: C{None} if this state is not an
        accepting state of the automaton; otherwise a set of
        L{UpdateInstruction} values that must be satisfied by the
        counter values in a configuration as a further restriction of
        acceptance.

        @param is_unordered_catenation: C{True} if this state has
        subautomata that must be matched to execute the unordered
        catenation of an L{All} node; C{False} if this is a regular
        symbol.N(   t   _State__symbolt   _State__isInitialt   _State__finalUpdatet   _State__isUnorderedCatenation(   R
   R   t
   is_initialt   final_updatet   is_unordered_catenation(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	      s    		c         C   s   |  j  S(   s4   Link to the L{Automaton} to which the state belongs.(   t   _State__automaton(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_automaton   s    c         C   s"   |  j  d k s t  | |  _  |  S(   s@   Method invoked during automaton construction to set state owner.N(   R'   R   t   AssertionError(   R
   t	   automaton(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   _set_automaton   s    	c         C   s   |  j  S(   sQ   Application-specific metadata identifying the symbol.

        See also L{match}.(   R    (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_symbol   s    c         C   s   |  j  S(   s
  Indicate whether the state has subautomata for unordered
        catenation.

        To reduce state explosion due to non-determinism, such a state
        executes internal transitions in subautomata until all terms
        have matched or a failure is discovered.(   R#   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_isUnorderedCatenation   s    c         C   s   |  j  S(   s   A sequence of sub-automata supporting internal state transitions.

        This will return C{None} unless L{isUnorderedCatenation} is C{True}.(   t   _State__subAutomata(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_subAutomata   s    c         G   s1   |  j  d  k s t  |  j s$ t  | |  _  d  S(   N(   R.   R   R)   R#   (   R
   t   automata(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   _set_subAutomata   s    c         C   s   |  j  S(   sC   C{True} iff this state may be the first state the automaton enters.(   R!   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_isInitial   s    c         C   s   |  j  d k r g  } |  j r t |  t    } |  j d k rO | j |  q xD |  j D]6 } x- | j D]" } | j | j | j	     qi WqY Wn  | |  _  n  |  j  S(   s  Return the set of initial transitions allowing entry to the automata through this state.

        These are structurally-permitted transitions only, and must be
        filtered based on the symbol that might trigger the
        transition.  The results are not filtered based on counter
        value, since this value is used to determine how the
        containing automaton might be entered.  Consequently the
        return value is the empty set unless this is an initial state.

        The returned set is closed under entry to sub-automata,
        i.e. it is guaranteed that each transition includes a
        consuming state even if it requires a multi-element chain of
        transitions into subautomata to reach one.N(
   t!   _State__automatonEntryTransitionsR   R!   t
   Transitiont   setR.   t   appendt   initialTransitionst   chainTot   makeEnterAutomatonTransition(   R
   t   transitionst   xitt   sat   saxit(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_automatonEntryTransitions   s    	'c         C   s   |  j  S(   sS   Return the update instructions that must be satisfied for this to be a final state.(   R"   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_finalUpdate  s    c         C   sv   |  j  d k	 s t  t } g  } | d k r9 |  j  } n  x0 | D]( } | j sX t } n  | j | j  q@ W| | f S(   sF  Return the set of candidate transitions to enter a sub-automaton of this state.

        @param sub_automata: A subset of the sub-automata of this
        state which should contribute to the result.  If C{None}, all
        sub-automata are used.

        @return: A pair C{(nullable, transitions)} where C{nullable}
        is C{True} iff there is at least one sub-automaton that is in
        an accepting state on entry, and C{transitions} is a list of
        L{Transition} instances describing how to reach some state in
        a sub-automaton via a consumed symbol.
        N(   R.   R   R)   t   Truet   nullablet   Falset   extendR7   (   R
   t   sub_automatat   is_nullableR:   R<   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   subAutomataInitialTransitions  s    		c         C   s&   |  j  d k r t St j | |  j   S(   s:  C{True} iff this state is an accepting state for the automaton.

        @param counter_values: Counter values that further validate
        whether the requirements of the automaton have been met.

        @return: C{True} if this is an accepting state and the
        counter values relevant at it are satisfied.N(   R"   R   RB   t   UpdateInstructiont	   Satisfies(   R
   t   counter_values(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   isAccepting  s    c         C   s   |  j  S(   s
  Definitions of viable transitions from this state.

        The transition set of a state is a set of L{Transition} nodes
        identifying a state reachable in a single step from this
        state, and a set of counter updates that must apply if the
        transition is taken.

        These transitions may not in themselves consume a symbol.  For
        example, if the destination state represents a match of an
        L{unordered catenation of terms<All>}, then secondary
        processing must be done to traverse into the automata for
        those terms and identify transitions that include a symbol
        consumption.

        @note: Although conceptually the viable transitions are a set,
        this implementation maintains them in a list so that order is
        preserved when automata processing becomes non-deterministic.
        PyXB is careful to build the transition list so that the
        states are attempted in the order in which they appear in the
        schema that define the automata.
        (   t   _State__transitionSet(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_transitionSet+  s    c         C   sS   g  |  _  t   } x: | D]2 } | | k r | j |  |  j  j |  q q Wd S(   s  Method invoked during automaton construction to set the
        legal transitions from the state.

        The set of transitions cannot be defined until all states that
        appear in it are available, so the creation of the automaton
        requires that the association of the transition set be
        delayed.  (Though described as a set, the transitions are a
        list where order reflects priority.)

        @param transition_set: a list of pairs where the first
        member is the destination L{State} and the second member is the
        set of L{UpdateInstruction}s that apply when the automaton
        transitions to the destination state.N(   RK   R5   t   addR6   (   R
   t   transition_sett   seenR;   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   _set_transitionSetD  s    		c         C   s/   t  |  j t  r" |  j j |  S|  j | k S(   s3  Return C{True} iff the symbol matches for this state.

        This may be overridden by subclasses when matching by
        equivalence does not work.  Alternatively, if the symbol
        stored in this node is a subclass of L{SymbolMatch_mixin}, then
        its match method will be used.  Otherwise C{symbol} matches
        only if it is equal to the L{symbol} of this state.

        @param symbol: A candidate symbol corresponding to the
        expression symbol for this state.

        @return: C{True} iff C{symbol} is a match for this state.
        (   t
   isinstanceR    R   R   (   R
   R   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   Z  s    c         C   s   d t  |   f S(   Ns   S.%x(   t   id(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __str__l  s    c         C   s   g  } | j  t t |  j   |  j d  k	 r d t |  j  k rS | j d  q | j d d j t d   |  j    n  d j |  S(   Ni    s   Final (no conditions)s   Final if %st    c         S   s   t  |  j  S(   N(   t   strt   counterCondition(   t   _ui(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   <lambda>v  s    s   
(	   RC   t   mapRU   RK   R"   R   t   lenR6   t   join(   R
   t   rv(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   _facTexto  s    ,N('   R   R   R   R   RB   R	   R'   t   _State__get_automatonR+   R   R*   R    t   _State__get_symbolR   R#   t!   _State__get_isUnorderedCatenationt   isUnorderedCatenationR.   t   _State__get_subAutomataR1   t   subAutomataR!   t   _State__get_isInitialt	   isInitialR3   t%   _State__get_automatonEntryTransitionst   automatonEntryTransitionsR"   t   _State__get_finalUpdatet   finalUpdateRF   RJ   RK   t   _State__get_transitionSett   transitionSetRP   R   RS   R]   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR      sD   														t   CounterConditionc           B   s   e  Z d  Z d	 Z d   Z e e  Z d	 Z d   Z	 e e	  Z
 d	 Z d   Z e e  Z d	 d  Z d   Z d   Z d   Z d   Z RS(
   s   A counter condition is a range limit on valid counter values.

    Instances of this class serve as keys for the counters that
    represent the configuration of a FAC.  The instance also maintains
    a pointer to application-specific L{metadata}.c         C   s   |  j  S(   sQ   The minimum legal value for the counter.

        This is a non-negative integer.(   t   _CounterCondition__min(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt	   __get_min  s    c         C   s   |  j  S(   s   The maximum legal value for the counter.

        This is a positive integer, or C{None} to indicate that the
        counter is unbounded.(   t   _CounterCondition__max(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt	   __get_max  s    c         C   s   |  j  S(   sJ   A pointer to application metadata provided when the condition was created.(   t   _CounterCondition__metadata(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_metadata  s    c         C   s   | |  _  | |  _ | |  _ d S(   s   Create a counter condition.

        @param min: The value for L{min}
        @param max: The value for L{max}
        @param metadata: The value for L{metadata}
        N(   Rm   Ro   Rq   (   R
   t   mint   maxt   metadata(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	     s    		c         C   s'   t  |  j  t  |  j  At  |  j  AS(   N(   t   hashRm   Ro   Rq   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __hash__  s    c         C   s@   | d  k	 o? |  j | j k o? |  j | j k o? |  j | j k S(   N(   R   Rm   Ro   Rq   (   R
   t   other(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __eq__  s    c         C   s   |  j  |  S(   N(   Ry   (   R
   Rx   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __ne__  s    c         C   s2   d t  |   |  j |  j d  k	 r* |  j p- d f S(   Ns   C.%x{%s,%s}t    (   RR   Rs   Rt   R   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRS     s    N(   R   R   R   R   Rm   t   _CounterCondition__get_minR   Rs   Ro   t   _CounterCondition__get_maxRt   Rq   t   _CounterCondition__get_metadataRu   R	   Rw   Ry   Rz   RS   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRl   y  s   						RG   c           B   s   e  Z d  Z d Z d   Z e e  Z d Z d   Z	 e e	  Z
 d Z d Z d   Z d   Z e d    Z d   Z e d    Z d   Z d	   Z d
   Z d   Z RS(   sS  An update instruction pairs a counter with a mutation of that
    counter.

    The instruction is executed during a transition from one state to
    another, and causes the corresponding counter to be incremented or
    reset.  The instruction may only be applied if doing so does not
    violate the conditions of the counter it affects.c         C   s   |  j  S(   s   A reference to the L{CounterCondition} identifying the
        counter to be updated.

        The counter condition instance is used as a key to the
        dictionary maintaining current counter values.(   t$   _UpdateInstruction__counterCondition(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_counterCondition  s    c         C   s   |  j  S(   sK   C{True} if the counter is to be incremented; C{False} if it is to be reset.(   t   _UpdateInstruction__doIncrement(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_doIncrement  s    c         C   s0   | |  _  | |  _ | j |  _ | j |  _ d S(   s  Create an update instruction.

        @param counter_condition: A L{CounterCondition} identifying a
        minimum and maximum value for a counter, and serving as a map
        key for the value of the corresponding counter.

        @param do_increment: C{True} if the update is to increment
        the value of the counter; C{False} if the update is to reset
        the counter.
        N(   R   R   Rs   t   _UpdateInstruction__minRt   t   _UpdateInstruction__max(   R
   t   counter_conditiont   do_increment(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	     s    	c         C   sY   | |  j  } |  j r8 |  j d k	 r8 | |  j k r8 t S|  j rU | |  j k  rU t St S(   sk  Implement a component of definition 5 from B{HOV09}.

        The update instruction is satisfied by the counter values if
        its action may be legitimately applied to the value of its
        associated counter.

        @param counter_values: A map from  L{CounterCondition}s to
        non-negative integers

        @return:  C{True} or C{False}
        N(   R   R   R   R   RB   R   R@   (   R
   RI   t   value(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   satisfiedBy  s    	
c         C   s(   x! | D] } | j  |  s t Sq Wt S(   sc  Return C{True} iff the counter values satisfy the update
        instructions.

        @param counter_values: A map from L{CounterCondition} to
        integer counter values

        @param update_instructions: A set of L{UpdateInstruction}
        instances

        @return: C{True} iff all instructions are satisfied by the
        values and limits.(   R   RB   R@   (   t   clsRI   t   update_instructionst   psi(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRH     s    c         C   s[   |  j  |  s! t |  |   n  | |  j } |  j rD | d 7} n d } | | |  j <d S(   s   Apply the update instruction to the provided counter values.

        @param counter_values: A map from L{CounterCondition} to
        integer counter values.  This map is updated in-place.i   N(   R   R   R   R   (   R
   RI   R   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   apply  s    	c         C   s"   x | D] } | j  |  q Wd S(   s[  Apply the update instructions to the counter values.

        @param update_instructions: A set of L{UpdateInstruction}
        instances.

        @param counter_values: A map from L{CounterCondition}
        instances to non-negative integers.  This map is updated
        in-place by applying each instruction in
        C{update_instructions}.N(   R   (   R   R   RI   R   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   Apply  s    c         C   s   t  |  j  t  |  j  AS(   N(   Rv   R   R   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRw   "  s    c         C   s.   | d  k	 o- |  j | j k o- |  j | j k S(   N(   R   R   R   (   R
   Rx   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRy   %  s    c         C   s   |  j  |  S(   N(   Ry   (   R
   Rx   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRz   *  s    c         C   s    d |  j  r d p d |  j f S(   Ns   %s %st   inct   reset(   R   R   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRS   -  s    N(   R   R   R   R   R   t(   _UpdateInstruction__get_counterConditionR   RV   R   t#   _UpdateInstruction__get_doIncrementt   doIncrementR   R   R	   R   t   classmethodRH   R   R   Rw   Ry   Rz   RS   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRG     s$   								R4   c           B   s   e  Z d  Z d Z d   Z e e  Z d Z d   Z	 e e	  Z
 d Z d   Z e e  Z d Z d   Z e e  Z d d  Z d   Z d   Z d   Z d d	  Z d
   Z d   Z d   Z d   Z d   Z d   Z RS(   s)   Representation of a FAC state transition.c         C   s   |  j  S(   s!   The transition destination state.(   t   _Transition__destination(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_destination4  s    c         C   s   |  j  S(   sI   The set of counter updates that are applied when the transition is taken.(   t   _Transition__updateInstructions(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_updateInstructions:  s    c         C   s   |  j  S(   si   The next transition to apply in this chain.

        C{None} if this is the last transition in the chain.(   t   _Transition__nextTransition(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_nextTransition@  s    c         C   s   |  j  S(   sD  A directive relating to changing automaton layer on transition.

        C{None} indicates this transition is from one state to another
        within a single automaton.

        An instance of L{Configuration} is a transition on completion
        of a subautomaton back to the configuration in the parent
        automaton.  The L{destination} is the state in the parent automaton.

        An instance of L{Automaton} requires creation of a
        sub-configuration and initial entry into the automaton.  The
        L{destination} is the state in the sub-automaton.
        (   t   _Transition__layerLink(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_layerLinkH  s    c         C   s=   | |  _  t | t  s' t |  } n  | |  _ | |  _ d S(   sa  Create a transition to a state.

        @param destination: the state into which the transition is
        made

        @param update_instructions: A iterable of L{UpdateInstruction}s
        denoting the changes that must be made to counters as a
        consequence of taking the transition.

        @keyword layer_link: The value for L{layerLink}.N(   R   RQ   t   listR   R   (   R
   t   destinationR   t
   layer_link(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	   Y  s
    		c         C   sH   |  j  j d k	 r, |  j s d S|  j j   S|  j d k sA t  |  j  S(   sC   Return the state in this transition chain that must match a symbol.N(   R   Rc   R   R   t   consumingStateR)   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   j  s    	c         C   s   |  j    j S(   s<   Return the L{symbol<State.symbol>} of the L{consumingState}.(   R   R   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   consumedSymbolv  s    c         C   s   t  |  j t  r t St  |  j t  r4 |  j } n  |  j j | j k sO t  | j |   sb t	 S|  j
 r{ |  j
 j |  St S(   s  Check the transition update instructions against
        configuration counter values.

        This implementation follows layer changes, updating the
        configuration used as counter value source as necessary.

        @param configuration: A L{Configuration} instance containing
        counter data against which update instruction satisfaction is
        checked.

        @return: C{True} iff all update instructions along the
        transition chain are satisfied by their relevant
        configuration.(   RQ   R   t	   AutomatonR@   t   ConfigurationR   R*   R)   t	   satisfiesRB   R   R   (   R
   R   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   z  s    	c         C   s   |  j  } t | t  rC | d k	 r1 | | } n  | j |  } n! t | t  rd | j |  } n  t j |  j	 | j
    | j |  j | d k  |  j d k r | S|  j j | |  S(   s  Apply the transitition to a configuration.

        This updates the configuration counter values based on the
        update instructions, and sets the new configuration state.

        @note: If the transition involves leaving a sub-automaton or
        creating a new sub-automaton, the returned configuration
        structure will be different from the one passed in.  You
        should invoke this as::

          cfg = transition.apply(cfg)

        @param configuration: A L{Configuration} of an executing automaton

        @param clone_map: A map from L{Configuration} to
        L{Configuration} reflecting the replacements made when the
        configuration for which the transition was calculated was
        subsequently cloned into the C{configuration} passed into this
        method.  This is only necessary when the transition includes
        layer transitions.

        @return: The resulting configuration
        N(   R   RQ   R   R   t   leaveAutomatonR   t   enterAutomatonRG   R   t   updateInstructionst   _get_counterValuest
   _set_stateR   R   R   (   R
   R   t	   clone_mapR   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR     s    	c         C   sA   |  j  s t  t |   |  j |  j d |  j } | | _  | S(   s
  Duplicate the state and chain the duplicate to a successor
        transition.

        This returns a new transition which applies the operation for
        this transition, then proceeds to apply the next transition in
        the chain.

        @note: The node that is invoking this must not have successor
        transitions.

        @param next_transition: A L{Transition} node describing a
        subsequent transition.

        @return: a clone of this node, augmented with a link to
        C{next_transition}.R   (   R   R)   R   R   R   R   (   R
   t   next_transitiont   head(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR8     s    $	c         C   sX   |  j  d k s t  |  j d k s* t  t |   |  j |  j  } |  j j | _  | S(   s   Replicate the transition as a layer link into its automaton.

        This is used on initial transitions into sub-automata where a
        sub-configuration must be created and recorded.N(   R   R   R)   R   R   R   R   R*   (   R
   R   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR9     s
    c         C   sQ   t  |  j  } x! |  j D] } | t  |  N} q W| t  |  j  At  |  j  AS(   N(   Rv   R   R   R   R   (   R
   R\   t   ui(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRw     s    c         C   sR   | d  k	 oQ |  j | j k oQ |  j | j k oQ |  j | j k oQ |  j | j k S(   N(   R   R   R   R   R   (   R
   Rx   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRy     s
    c         C   s   |  j  |  S(   N(   Ry   (   R
   Rx   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRz     s    c         C   s  g  } t  |  j t  r; | j d t |  j j  f  n/ t  |  j t  rj | j d t |  j   n  | j d |  j f  |  j   |  j k r | j d |  j j	 f  n  | j d d j
 t t |  j   f  |  j r| j d  | j t |  j   n  d j
 |  S(	   Ns	   from A%x s   in A%x s	   enter %s s   via %s s   with %ss    ; s   
	then R{   (   RQ   R   R   R6   RR   R*   R   R   R   R   R[   RY   RU   R   R   (   R
   R\   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRS     s    #)	N(   R   R   R   R   R   t   _Transition__get_destinationR   R   R   t#   _Transition__get_updateInstructionsR   R   t   _Transition__get_nextTransitiont   nextTransitionR   t   _Transition__get_layerLinkt	   layerLinkR	   R   R   R   R   R8   R9   Rw   Ry   Rz   RS   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR4   0  s0   							%					t   Configuration_ABCc           B   s    e  Z d  Z d   Z d   Z RS(   sT  Base class for something that represents an L{Automaton} in
    execution.

    For deterministic automata, this is generally a L{Configuration}
    which records the current automaton state along with its counter
    values.

    For non-deterministic automata, this is a L{MultiConfiguration}
    which records a set of L{Configuration}s.c         C   s    t  d t |   j f   d S(   s2  Return the acceptable L{Symbol}s given the current
        configuration.

        This method extracts the symbol from all candidate transitions
        that are permitted based on the current counter values.
        Because transitions are presented in a preferred order, the
        symbols are as well.s   %s.acceptableSymbolsN(   R   R   R   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR     s    c         C   s    t  d t |   j f   d S(   s  Execute an automaton transition using the given symbol.

        @param symbol: A symbol from the alphabet of the automaton's
        language.  This is a Python value that should be accepted by
        the L{SymbolMatch_mixin.match} method of a L{State.symbol}.
        It is not a L{Symbol} instance.

        @return: The new configuration resulting from the step.

        @raises AutomatonStepError: L{UnrecognizedSymbolError}
        when no transition compatible with C{symbol} is available, and
        L{NondeterministicSymbolError} if C{symbol} admits multiple
        transitions and the subclass does not support
        non-deterministic steps (see L{MultiConfiguration}).

        @warning: If the step entered or left a sub-automaton the
        return value will not be the configuration that was used to
        execute the step.  The proper pattern for using this method
        is::

           cfg = cfg.step(sym)

        s   %s.stepN(   R   R   R   (   R
   R   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   step  s    (   R   R   R   R   R   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR     s   		
R   c           B   s=  e  Z d  Z d Z d   Z d   Z e e  Z d Z	 d   Z
 d Z d   Z e e  Z d Z d   Z e e  Z d Z d   Z e e  Z d Z d   Z d   Z e e  Z d	   Z d
   Z d   Z d   Z d   Z d d  Z d   Z d   Z d   Z  d   Z! d d  Z" d d  Z# d   Z$ d   Z% RS(   s}   The state of an L{Automaton} in execution.

    This combines a state node of the automaton with a set of counter
    values.c         C   s   |  j  S(   s   The state of the configuration.

        This is C{None} to indicate an initial state, or one of the underlying automaton's states.(   t   _Configuration__state(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_state3  s    c         C   sz   | |  j  k r d S| r. d |  _ d |  _ n  | |  _  | rv | j d k	 rv |  j d k sa t  t | j  |  _ n  d S(   s   Internal state transition interface.

        @param state: the new destination state

        @param is_layer_change: C{True} iff the transition inducing
        the state change involves a layer change.
        N(   R   R   t    _Configuration__subConfigurationt   _Configuration__subAutomataRc   R)   R   (   R
   t   statet   is_layer_change(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   8  s    		c         C   s   |  j  S(   N(   t   _Configuration__counterValues(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   Y  s    c         C   s   |  j  S(   N(   t   _Configuration__automaton(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR(   ]  s    c         C   s   |  j  S(   s  Reference to configuration being executed in a sub-automaton.

        C{None} if no sub-automaton is active, else a reference to a
        configuration that is being executed in a sub-automaton.

        Sub-configurations are used to match sub-terms in an
        L{unordered catenation<All>} term.  A configuration may have
        at most one sub-configuration at a time, and the configuration
        will be removed and possibly replaced when the term being
        processed completes.(   R   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_subConfigurationb  s    c         C   s   |  j  S(   s:  Reference to the configuration for which this is a
        sub-configuration.

        C{None} if no super-automaton is active, else a reference to a
        configuration that is being executed in a super-automaton.

        The super-configuration relation persists for the lifetime of
        the configuration.(   t"   _Configuration__superConfiguration(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_superConfigurationq  s    	c         C   s   |  j  S(   ss  A set of automata that must be satisfied before the current state can complete.

        This is used in unordered catenation.  Each sub-automaton
        represents a term in the catenation.  When the configuration
        enters a state with sub-automata, a set containing references
        to those automata is assigned to this attribute.
        Subsequently, until all automata in the state are satisfied,
        transitions can only occur within an active sub-automaton, out
        of the active sub-automaton if it is in an accepting state,
        and into a new sub-automaton if no sub-automaton is active.
        (   R   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR/   ~  s    c         C   s   t  |  |  _ d  S(   N(   R   R   (   R
   R0   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR1     s    c         C   s4   |  j  d k	 s t  t |  j  j t   d |  j  S(   s  Create a transition back to the containing configuration.

        This is done when a configuration is in an accepting state and
        there are candidate transitions to other states that must be
        considered.  The transition does not consume a symbol.R   N(   R   R   R)   R4   R   R5   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   makeLeaveAutomatonTransition  s    c         C   s"   | j  |  k s t  d |  _ |  S(   s   Execute steps to leave a sub-automaton.

        @param sub_configuration: The configuration associated with
        the automata that has completed.

        @return: C{self}N(   R   R)   R   R   (   R
   t   sub_configuration(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR     s    	c         C   s\   |  j  d k s t  |  j d k	 s* t  |  j j |  t |  |  _  |  |  j  _ |  j  S(   s  Execute steps to enter a new automaton.

        The new automaton is removed from the set of remaining
        automata for the current state, and a new configuration
        created.  No transition is made in that new configuration.

        @param automaton: The automaton to be entered

        @return: The configuration that executes the new automaton as
        a sub-configuration of C{self}.N(   R   R   R)   R   t   removeR   R   (   R
   R*   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR     s    c         C   s   t  j |  j | j  S(   N(   RG   RH   R   R   (   R
   t
   transition(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR     s    c         C   sP   |  j  } d  |  _ t t | j t | j  d   |  _ d  |  _ d  |  _	 d  S(   Ni   (   i   (
   R   R   R   t   dictt   zipt   counterConditionsRZ   R   R   R   (   R
   t   fac(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR     s
    		(	c   
         s    j  } g  }  d k r' d   } n  f d   }   f d   }   j d k rg | j | j  nB  j d k	 r   j j   r n t }   j r   j j	   j  \ } } | j t
 d   |   n  | rxs t |   j j  D]\   j   d k	 r| j   q  j j	   \ } } | j t
  f d   |   q W  j d k	 r  j   r  j      j j   }	 | j t
  f d   |	   qn  t t |   t |  k st  t t | t | |    S(   s  Return list of viable transitions on C{symbol}

        The transitions that are structurally permitted from this
        state, in order, filtering out those transitions where the
        update instruction is not satisfied by the configuration
        counter values and optionally those for which the symbol does
        not match.

        @param symbol: A symbol through which a transition from this
        state is intended.  A value of C{None} indicates that the set
        of transitions should ignore the symbol; candidates are still
        filtered based on the counter state of the configuration.

        @return: A list of L{Transition} instances permitted from the
        current configuration.  If C{symbol} is not C{None},
        transitions that would not accept the symbol are excluded.
        Any transition that would require an unsatisfied counter
        update is also excluded.  Non-deterministic automata may
        result in a lits with multiple members. c         S   s   t  S(   N(   R@   (   t   _xit(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRX     s    c            s   |  j    j    S(   N(   R   R   (   R   (   R   (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRX     s    c            s   |  j     S(   N(   R   (   R   (   R
   (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRX     s    c         S   s
   |  j    S(   N(   R9   (   R   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRX     s    c            s     j  |  j    S(   N(   R8   R9   (   R   (   R;   (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRX     s    c            s     j  |   S(   N(   R8   (   t   _sx(   t   lxit(    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRX     s    N(   R   R   R   RC   R7   R   RJ   R@   R   RF   RY   t   filterRk   R   R6   R   R   R   t   candidateTransitionsRZ   t	   frozensetR)   R   (
   R
   R   R   R:   t   match_filtert   update_filtert   include_localt   sub_initialt   _t   supxit(    (   R
   R   R;   R   sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR     s4    		#%$c         C   s#   g  |  j    D] } | j   ^ q S(   N(   R   R   (   R
   R   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR     s    c         C   sh   |  j  |  } d t |  k r3 t |  |   n  d t |  k  rW t |  |   n  | d j |   S(   Ni    i   (   R   RZ   R   R   R   (   R
   R   R:   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR     s    c         C   s   |  j  d k S(   s6   Return C{True} iff no transitions have ever been made.N(   R   R   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRe     s    c         C   s   |  j  d k	 r |  j d k	 r2 |  j j   r2 t S|  j d k	 ro t j t j	 t
 d   |  j  t  so t Sn  |  j  j |  j  S|  j j S(   s:   Return C{True} iff the automaton is in an accepting state.c         S   s   |  j  S(   N(   RA   (   t   _sa(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRX     s    N(   R   R   R   RJ   RB   R   t	   functoolst   reducet   operatort   and_RY   R@   R   R   RA   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRJ     s    'c         C   s    | |  _  | |  _ |  j   d  S(   N(   R   R   R   (   R
   R*   t   super_configuration(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	     s    		c         C   sY   | d k r i  } n  |  } x | j d k	 r9 | j } q W| j | d  } | j |   S(   sc  Clone a configuration and its descendents.

        This is used for parallel execution where a configuration has
        multiple candidate transitions and must follow all of them.
        It clones the entire chain of configurations through
        multiple layers.

        @param clone_map: Optional map into which the translation from
        the original configuration object to the corresponding cloned
        configuration object can be reconstructed, e.g. when applying
        a transition that includes automata exits referencing
        superconfigurations from the original configuration.
        N(   R   R   t   _clonet   get(   R
   R   t   root(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   clone$  s    	c         C   s   |  | k s t   t |   |  j  } | | |  <|  j | _ |  j j   | _ | | _ |  j d  k	 r |  j | _ |  j	 r |  j	 j
 | |  | _	 q n  | S(   N(   R)   R   R   R   R   t   copyR   R   R   R   R   (   R
   R   R   Rx   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   :  s    
		c         C   sI   d |  j  d j g  t j |  j  D] \ } } d | | f ^ q"  f S(   Ns   %s: %ss    ; s   %s=%u(   R   R[   R    t	   iteritemsR   (   R
   t   _ct   _v(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRS   G  s    N(&   R   R   R   R   R   t   _Configuration__get_stateR   R   R   R   R   R   t   _Configuration__get_automatonR*   R   t$   _Configuration__get_subConfigurationt   subConfigurationR   t&   _Configuration__get_superConfigurationt   superConfigurationR   t   _Configuration__get_subAutomataR1   Rc   R   R   R   R   R   R   R   R   Re   RJ   R	   R   R   RS   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   ,  sD   						
								B					t   MultiConfigurationc           B   s8   e  Z d  Z d Z d   Z d   Z d   Z d   Z RS(   s?  Support parallel execution of state machine.

    This holds a set of configurations, and executes each transition
    on each one.  Configurations which fail to accept a step are
    silently dropped; only if this results in no remaining
    configurations will L{UnrecognizedSymbolError} be raised.  If a
    step admits multiple valid transitions, a configuration is added
    for each one.

    See L{pyxb.binding.content.AutomatonConfiguration} for an
    alternative solution which holds actions associated with the
    transition until the non-determinism is resolved.c         C   s   | g |  _  d  S(   N(   t#   _MultiConfiguration__configurations(   R
   R   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	   Z  s    c         C   s1   g  } x$ |  j  D] } | j | j    q W| S(   N(   R   RC   R   (   R
   R   t   cfg(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   ]  s    c         C   s  g  } x |  j  D] } | j |  } d t |  k r: q d t |  k ri | j | d j |   q x< | D]4 } i  } | j |  } | j | j | |   qp Wq Wd t |  k r t |  |   n  t t |   t |  k s t  | |  _  |  S(   Ni    i   (	   R   R   RZ   R6   R   R   R   R   R)   (   R
   R   t   next_configsR   R:   R   R   t   ccfg(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   c  s     !$	c         C   s_   g  } xR |  j  D]G } | } x | j d k	 r: | j } q W| j   r | j |  q q W| S(   s   Return the set of configurations that are in an accepting state.

        Note that some of the configurations may be within a
        sub-automaton; their presence in the return value is because
        the root configuration is also accepting.N(   R   R   R   RJ   R6   (   R
   t	   acceptingR   t   rcfg(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   acceptingConfigurationsv  s    N(	   R   R   R   R   R   R	   R   R   R   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   J  s   			R   c           B   s   e  Z d  Z d
 Z d   Z e e  Z d
 Z d   Z	 e e	  Z
 d
 Z d   Z e e  Z d
 Z d   Z e e  Z d
 Z d   Z e e  Z d
 Z d   Z e e  Z d
 d  Z d   Z d	   Z RS(   s   Representation of a Finite Automaton with Counters.

    This has all the standard FAC elements, plus links to other
    states/automata as required to support the nested automata
    construct used for matching unordered catenation terms.c         C   s   |  j  S(   s  The set of L{State}s in the automaton.

        These correspond essentially to marked symbols in the original
        regular expression, or L{element
        declarations<pyxb.xmlschema.structures.ElementDeclaration>} in
        an XML schema.

        @note: These are conceptually a set and are stored that way.
        When an L{Automaton} is constructed the incoming states should
        be passed as a list so the calculated initial transitions are
        executed in a deterministic order.(   t   _Automaton__states(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_states  s    c         C   s   |  j  S(   s   The set of L{CounterCondition}s in the automaton.

        These are marked positions in the regular expression, or
        L{particles<pyxb.xmlschema.structures.Particle>} in an XML
        schema, paired with their occurrence constraints.(   t   _Automaton__counterConditions(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_counterConditions  s    c         C   s   |  j  S(   s3   C{True} iff the automaton accepts the empty string.(   t   _Automaton__nullable(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_nullable  s    c         C   s   |  j  S(   sg  The set of transitions that may be made to enter the automaton.

        These are full transitions, including chains into subautomata
        if an initial state represents a node with sub-automata.

        @note: As with L{State.transitionSet}, the set is represented
        as a list to preserve priority when resolving
        non-deterministic matches.(   t   _Automaton__initialTransitions(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_initialTransitions  s    	c         C   s   |  j  S(   si   The L{State} instance for which this is a sub-automaton.

        C{None} if this is not a sub-automaton.(   t   _Automaton__containingState(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_containingState  s    c         C   s   |  j  S(   s8   The set of L{State} members which can terminate a match.(   t   _Automaton__finalStates(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_finalStates  s    c   	      C   s   t  |  |  _ x |  j D] } | j |   q Wt  |  |  _ | |  _ | |  _ g  } t   } xI | D]A } | j r | j | j	  n  | j
 d  k	 rg | j |  qg qg W| |  _ t  |  |  _ d  S(   N(   R   R   R+   R   R   R   R5   Re   RC   Rg   Ri   R   RM   R   R   (	   R
   t   statest   counter_conditionsRA   t   containing_statet   stR;   t   fnlt   s(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	     s    					c         C   s
   t  |   S(   s:   Return a new L{Configuration} instance for this automaton.(   R   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   newConfiguration  s    c      	   C   s  g  } | j  d d j t d   |  j    | j  d d j t t |  j    x |  j D] } | j d  k	 r_ xp t t | j   D]V } | j  d t |  | t	 | j |  f d j t | j |  j
 d    q Wq_ q_ W| j  d d j t t |  j    | j  d	 d
 j g  t d   |  j  D] } d | | j f ^ q6  | j  d d j t t |  j    | j  d  x. |  j D]# } | j  d | | j   f  qWd j |  S(   Ns
   sigma = %sRT   c         S   s   t  |  j  S(   N(   RU   R   (   t   _s(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRX     s    s   states = %ss   SA %s.%u is %x:
  s   
  s   
s   counters = %ss   initial = %ss    ; c         S   s   |  j  S(   N(   Re   (   R  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRX     s    s   %s on %ss   initial transitions:
%ss   States:s   %s: %s(   R6   R[   RY   R   RU   Rc   R   R   RZ   RR   t   splitR   R   R   R7   R]   (   R
   R\   R  t   iR  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRS     s    )&[&I&!N(   R   R   R   R   R   t   _Automaton__get_statesR   R   R   t!   _Automaton__get_counterConditionsR   R   t   _Automaton__get_nullableRA   R   t"   _Automaton__get_initialTransitionsR7   R   t   _Automaton__get_containingStatet   containingStateR   t   _Automaton__get_finalStatest   finalStatesR	   R  RS   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR     s,   				
			t   Nodec           B   s  e  Z d  Z d Z e Z e Z d   Z	 d   Z
 d Z d   Z e e  Z d Z d   Z e e  Z d   Z d Z d   Z e e  Z d   Z d Z d   Z e e  Z d	   Z d Z d
   Z e e  Z d   Z d   Z d   Z  d   Z! d Z" d   Z# e e#  Z$ d Z% d   Z& e e&  Z' e( d    Z) e( d    Z* e( d    Z+ d   Z, e- e. d d  Z/ d Z0 d   Z1 e e1  Z2 d   Z3 d   Z4 RS(   s%  Abstract class for any node in the term tree.

    In its original form a B{position} (C{pos}) is a tuple of
    non-negative integers comprising a path from a node in the term
    tree.  It identifies a node in the tree.  After the FAC has been
    constructed, only positions that are leaf nodes in the term tree
    remain, and the corresponding symbol value (Python instance) is
    used as the position.

    An B{update instruction} (C{psi}) is a map from positions to
    either L{Node.RESET} or L{Node.INCREMENT}.  It identifies actions
    to be taken on the counter states corresponding to the positions
    in its domain.

    A B{transition} is a pair containing a position and an update
    instruction.  It identifies a potential next node in the state and
    the updates that are to be performed if the transition is taken.

    A B{follow value} is a map from a position to a set of transitions
    that may originate from the pos.  This set is represented as a
    Python list since update instructions are dicts and cannot be
    hashed.
    c         K   s   | j  d  |  _ d S(   s   Create a FAC term-tree node.

        @keyword metadata: Any application-specific metadata retained in
        the term tree for transfer to the resulting automaton.Ru   N(   R   t   _Node__metadata(   R
   t   kw(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	     s    c         O   s&   | j  d |  j  t |   | |   S(   s0  Create a deep copy of the node.

        All term-tree--related attributes and properties are replaced
        with deep clones.  Other attributes are preserved.

        @param args: A tuple of arguments to be passed to the instance
        constructor.

        @param kw: A dict of keywords to be passed to the instance
        constructor.

        @note: Subclasses should pre-extend this method to augment the
        C{args} and C{kw} parameters as necessary to match the
        expectations of the C{__init__} method of the class being
        cloned.Ru   (   t
   setdefaultRu   R   (   R
   R   R  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR     s    c         C   s   |  j  S(   s;   Application-specific metadata provided during construction.(   R  (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRr   0  s    c         C   s.   |  j  d k r' t |  j    |  _  n  |  j  S(   s   The I{first} set for the node.

        This is the set of positions leading to symbols that can
        appear first in a string matched by an execution starting at
        the node.N(   t   _Node__firstR   R   t   _first(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_first6  s    c         C   s    t  d t |   j f   d S(   s   Abstract method that defines L{first} for the subclass.

        The return value should be an iterable of tuples of integers
        denoting paths from this node through the term tree to a
        symbol.s   %s.firstN(   R   R   R   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR  A  s    c         C   s.   |  j  d k r' t |  j    |  _  n  |  j  S(   s   The I{last} set for the node.

        This is the set of positions leading to symbols that can
        appear last in a string matched by an execution starting at
        the node.N(   t   _Node__lastR   R   t   _last(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt
   __get_lastJ  s    c         C   s    t  d t |   j f   d S(   s   Abstract method that defines L{last} for the subclass.

        The return value should be an iterable of tuples of integers
        denoting paths from this node through the term tree to a
        symbol.s   %s.lastN(   R   R   R   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR  U  s    c         C   s(   |  j  d k r! |  j   |  _  n  |  j  S(   s6   C{True} iff the empty string is accepted by this node.N(   t   _Node__nullableR   t	   _nullable(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   ^  s    c         C   s    t  d t |   j f   d S(   ss   Abstract method that defines L{nullable} for the subclass.

        The return value should be C{True} or C{False}.s   %s.nullableN(   R   R   R   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR  e  s    c         C   s(   |  j  d k r! |  j   |  _  n  |  j  S(   s   The I{follow} map for the node.N(   t   _Node__followR   t   _follow(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_followl  s    c         C   s    t  d t |   j f   d S(   s   Abstract method that defines L{follow} for the subclass.

        The return value should be a map from tuples of integers (positions)
        to a list of transitions, where a transition is a position and
        an update instruction.s	   %s.followN(   R   R   R   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR  s  s    c         C   s1   d |  _ d |  _ d |  _ d |  _ d |  _ d S(   sj  Reset any term-tree state associated with the node.

        Any change to the structure of the term tree in which the node
        appears invalidates memoized first/follow sets and related
        information.  This method clears all that data so it can be
        recalculated.  It does not clear the L{metadata} link, or any
        existing structural data.N(   R   R  R  R  R  t   _Node__counterPositions(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   {  s
    				c         C   s   |  j  d | | |  d S(   sV  Utility function for term tree processing.

        @param pre: a callable that, unless C{None}, is invoked at
        each node C{n} with parameters C{n}, C{pos}, and C{arg}, where
        C{pos} is the tuple of integers identifying the path from the
        node at on which this method was invoked to the node being
        processed.  The invocation occurs before processing any
        subordinate nodes.

        @param post: as with C{pre} but invocation occurs after
        processing any subordinate nodes.

        @param arg: a value passed to invocations of C{pre} and
        C{post}.N(    (   t   _walkTermTree(   R
   t   pret   postt   arg(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   walkTermTree  s    c         C   s    t  d t |   j f   d S(   s>   Abstract method implementing L{walkTermTree} for the subclass.s   %s.walkTermTreeN(   R   R   R   (   R
   t   positionR   R!  R"  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s    c         C   s>   |  j  d k r7 i  } |  j d   d |  | |  _  n  |  j  S(   s/   A map from positions to nodes in the term tree.c         S   s   | j  | |   S(   N(   R  (   t   _nt   _pt   _a(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRX     s    N(   t   _Node__posNodeMapR   R#  (   R
   t   pnm(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_posNodeMap  s
    c         C   sU   |  j  d k rN i  } x* t j |  j  D] \ } } | | | <q( W| |  _  n  |  j  S(   s4   A map from nodes to their position in the term tree.N(   t   _Node__nodePosMapR   R    R   t
   posNodeMap(   R
   t   npmt   pt   n(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_nodePosMap  s    c         C   s!   t  g  | D] } | | ^ q
  S(   s&   Implement definition 11.1 in B{HOV09}.(   R   (   R   t   post   pos_sett   _mp(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   _PosConcatPosSet  s    c         C   s8   i  } x+ t  j |  D] \ } } | | | | <q W| S(   s%   Implement definition 11.2 in B{HOV09}(   R    R   (   R   R1  R   R\   t   qt   v(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   _PosConcatUpdateInstruction  s    c         C   sD   g  } x7 | D]/ \ } } | j  | | |  j | |  f  q W| S(   s%   Implement definition 11.3 in B{HOV09}(   R6   R7  (   R   R1  RN   t   tsR5  R   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   _PosConcatTransitionSet  s    'c         C   s9   | | k r t  |  |   n  | j   | j |  d  S(   N(   R   R   RM   (   R
   t   nodeR1  t   visited_nodes(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __resetAndValidate  s    
c            s  |  j  |  j d  t    i  } xi |  j D]^   |  j j    } t | t  sV t	  | | k sh t	   | j
 | j | j  |   <q) Wt t j |   } i   xCt j |  j  D]/  |  j j    } t | t  s t	  |  k s t	    |  j k } d  }	 d   k r"| j s1  |  j k ryt   }	 x< t | j |  j     D] } |	 j t | t   qVWn   | j d | d |	 d t | t     <t | t  r    j t      f d   | j    q q Wt t j    }
 x t j |  j  D] \ } }  | } g  } x | D]x \ } }  | } t   } x@ t j |  D]/ \ } } | j t | | |  j | k   qfW| j  t! | |   q7W| j" |  qWt# |
 | |  j d | S(   NR$   R%   R&   c            s   |  j     d   S(   NR   (   t   buildAutomaton(   R  (   t   ctr_cond_ctort	   state_mapt
   state_ctorR1  (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRX     s    R   (    ($   R#  t   _Node__resetAndValidateR   R5   t   counterPositionsR,  R   RQ   t   NumericalConstraintR)   Rs   Rt   Ru   R   R    t
   itervaluest   iterkeyst   followt   LeafNodet   firstRA   t   lastRY   t   counterSubPositionsRM   RG   RB   t   AllR1   t   termsR   t	   INCREMENTR6   R4   RP   R   (   R
   R@  R>  R   t   counter_mapt   ncit   counterst   symR$   R%   R   t   sposRN   t   srct   phit   dposR   t   dstt   uisett   countert   action(    (   R1  R?  R>  R@  sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR=    sD    #$	".6

	'c         C   sD   |  j  d k r= g  } |  j d   d |  t |  |  _  n  |  j  S(   s   Implement definition 13.1 from B{HOV09}.

        The return value is the set of all positions leading to
        L{NumericalConstraint} nodes for which either the minimum
        value is not 1 or the maximum value is not unbounded.c         S   s:   t  |  t  o9 d |  j k s- |  j d  k	 o9 | j |  S(   Ni   (   RQ   RC  Rs   Rt   R   R6   (   R%  R&  R'  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRX     s    N(   R  R   R#  R   (   R
   t   cpos(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_counterPositions  s    
c         C   sM   t    } x7 |  j D], } | | t |   k r | j |  q q Wt |  S(   s   Implement definition 13.2 from B{HOV09}.

        This is the subset of L{counterPositions} that occur along the
        path to C{pos}.(   R5   RB  RZ   RM   R   (   R
   R1  R\   RZ  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRJ    s
    	c      
   C   s  g  } | j  d t |   f  t t j |  j   } | j  d d j t t t |  j j	 |     | j  d d j t t |  j
    | j  d d j t t |  j    | j  d d j t t |  j    x8 |  j
 D]- } | j  d |  j | j t |  f  q Wx | D] } x |  j | D] \ } } |  j | } g  } xO t j |  D]> \ }	 }
 | j  d |
 |  j k rd	 pd
 t |	  f  qaW| j  d t |  | j t |  d j |  f  q2WqWd j |  S(   s   Obtain a description of the FAC in text format.

        This is a diagnostic tool, returning first, last, and follow
        maps using positions.s   r	= %ss   sym(r)	= %sRT   s   first(r)	= %ss   last(r)	= %ss   C	= %ss   qI(%s) -> %ss   %s %sR   t   rsts   %s -%s-> %s ; %ss    ; s   
(   R6   RU   R   R    RE  RF  R[   RY   R,  R   RH  RI  RB  Ru   R   RM  (   R
   R\   R   R1  RR  RU  RN   RV  t   uvt   ct   u(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   _facToString   s"    2&&&+6=N(5   R   R   R   R   t   _PrecedenceRB   t   RESETR@   RM  R	   R   R  t   _Node__get_metadataR   Ru   R  t   _Node__get_firstRH  R  R  t   _Node__get_lastRI  R  R  t   _Node__get_nullableRA   R  R  t   _Node__get_followRF  R  R   R#  R  R(  t   _Node__get_posNodeMapR,  R+  t   _Node__get_nodePosMapt
   nodePosMapR   R4  R7  R9  RA  R   Rl   R=  R  t   _Node__get_counterPositionsRB  RJ  R`  (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    sX   																			4		t   MultiTermNodec           B   sD   e  Z d  Z d Z d   Z e e  Z d   Z d   Z	 d   Z
 RS(   s6   Intermediary for nodes that have multiple child nodes.c         C   s   |  j  S(   s1   The set of subordinate terms of the current node.(   t   _MultiTermNode__terms(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   __get_terms;  s    c         O   s#   t  t |   j |   | |  _ d S(   s   Term that collects an ordered sequence of terms.

        The terms are provided as arguments.  All must be instances of
        a subclass of L{Node}.N(   R   Rl  R	   Rm  (   R
   RL  R  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	   @  s    c         C   s+   t  d   |  j  } t t |   j |   S(   Nc         S   s
   |  j    S(   N(   R   (   R  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRX   I  s    (   RY   Rm  R   Rl  R   (   R
   t   cterms(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   H  s    c         C   s   | d  k	 r | |  | |  n  xA t t |  j   D]* } |  j | j | | f | | |  q5 W| d  k	 r | |  | |  n  d  S(   N(   R   R   RZ   Rm  R  (   R
   R$  R   R!  R"  R^  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR  L  s    (N(   R   R   R   R   Rm  t   _MultiTermNode__get_termsR   RL  R	   R   R  (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRl  7  s   			RG  c           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s0   Intermediary for nodes that have no child nodes.c         C   s   d g S(   N(    (    (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR  V  s    c         C   s   d g S(   N(    (    (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR  X  s    c         C   s   t  S(   N(   RB   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR  Z  s    c         C   s   i t    d 6S(   N(    (   R   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR  \  s    c         C   sB   | d  k	 r | |  | |  n  | d  k	 r> | |  | |  n  d  S(   N(   R   (   R
   R$  R   R!  R"  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR  _  s    (   R   R   R   R  R  R  R  R  (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRG  T  s   				RC  c           B   s   e  Z d  Z d Z d Z d   Z e e  Z d Z	 d   Z
 e e
  Z d Z d   Z e e  Z d d d  Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z RS(   sn   A term with a numeric range constraint.

    This corresponds to a "particle" in the XML Schema content model.ic         C   s   |  j  S(   N(   t   _NumericalConstraint__min(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRn   m  s    c         C   s   |  j  S(   N(   t   _NumericalConstraint__max(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRp   r  s    c         C   s   |  j  S(   N(   t   _NumericalConstraint__term(   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt
   __get_termw  s    i    i   c         K   s5   t  t |   j |   | |  _ | |  _ | |  _ d S(   s  Term with a numerical constraint.

        @param term: A term, the number of appearances of which is
        constrained in this term.
        @type term: L{Node}

        @keyword min: The minimum number of occurrences of C{term}.
        The value must be non-negative.

        @keyword max: The maximum number of occurrences of C{term}.
        The value must be positive (in which case it must also be no
        smaller than C{min}), or C{None} to indicate an unbounded
        number of occurrences.N(   R   RC  R	   Rs  Rq  Rr  (   R
   R   Rs   Rt   R  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	   {  s    		c         C   s%   t  t |   j |  j |  j |  j  S(   N(   R   RC  R   Rs  Rq  Rr  (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR     s    c         C   s!   g  |  j  j D] } d | ^ q S(   Ni    (   i    (   Rs  RH  (   R
   t   _fc(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s    c         C   s!   g  |  j  j D] } d | ^ q S(   Ni    (   i    (   Rs  RI  (   R
   t   _lc(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s    c         C   s   d |  j  k p |  j j S(   Ni    (   Rq  Rs  RA   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s    c   
      C   s)  i  } d } t  |  j j  } x t j |  j j  D] \ } } |  j | |  | | | <| | k r4 | j |  x |  j j D] } | | } i  } x+ |  j j	 |  D] }	 |  j
 | | |	 <q Wd |  j k s |  j d  k	 r |  j | d <n  | | | j | | f  q Wq4 q4 W| s%t  | S(   Ni    i   (   i    (    (   R5   Rs  RI  R    R   RF  R9  R   RH  RJ  Rb  Rs   Rt   R   RM  R6   R)   (
   R
   R\   t   ppt   last_r1R5  RN   t   sq1t   q1R   t   p1(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s"    "
&c         C   s_   | d  k	 r | |  | |  n  |  j j | d | | |  | d  k	 r[ | |  | |  n  d  S(   Ni    (   i    (   R   Rs  R  (   R
   R$  R   R!  R"  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s
    c         C   st   t  |  j  } |  j j |  j k  r5 d | d } n  | d |  j f 7} |  j d  k	 rl | d |  j 7} n  | d S(   Nt   (t   )s   ^(%u,s   %u(   RU   Rs  Ra  Rq  Rr  R   (   R
   R\   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRS     s    N(   R   R   R   Ra  R   Rq  t   _NumericalConstraint__get_minR   Rs   Rr  t   _NumericalConstraint__get_maxRt   Rs  t   _NumericalConstraint__get_termR   R	   R   R  R  R  R  R  RS   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRC  e  s&   									t   Choicec           B   sJ   e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   so   A term that may be any one of a set of terms.

    This term matches if any one of its contained terms matches.ic         O   s   t  t |   j | |   d S(   s   Term that selects one of a set of terms.

        The terms are provided as arguments.  All must be instances of
        a subclass of L{Node}.N(   R   R  R	   (   R
   RL  R  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	     s    c         C   s^   t    } xN t t |  j   D]7 } | j g  |  j | j D] } | f | ^ q<  q W| S(   N(   R5   R   RZ   RL  t   updateRH  (   R
   R\   R^  Ru  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s    	5c         C   s^   t    } xN t t |  j   D]7 } | j g  |  j | j D] } | f | ^ q<  q W| S(   N(   R5   R   RZ   RL  R  RI  (   R
   R\   R^  Rv  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s    	5c         C   s%   x |  j  D] } | j r
 t Sq
 Wt S(   N(   RL  RA   R@   RB   (   R
   t   t(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s    	c         C   sw   i  } xj t  t |  j   D]S } xJ t j |  j | j  D]/ \ } } | f } |  j | |  | | | <q< Wq W| S(   N(   R   RZ   RL  R    R   RF  R9  (   R
   R\   R^  R5  RN   Rw  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s    &	"c         C   sj   g  } xT |  j  D]I } | j |  j k  rF | j d t |  d  q | j t |   q Wd j |  S(   NR|  R}  t   +(   RL  Ra  R6   RU   R[   (   R
   t   eltsR  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRS     s    (
   R   R   R   Ra  R	   R  R  R  R  RS   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s   					t   Sequencec           B   sJ   e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   s,   A term that is an ordered sequence of terms.ic         O   s   t  t |   j | |   d S(   s   Term that collects an ordered sequence of terms.

        The terms are provided as arguments.  All must be instances of
        a subclass of L{Node}.N(   R   R  R	   (   R
   RL  R  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	     s    c         C   s}   t    } d } xg | t |  j  k  rx |  j | } | j g  | j D] } | f | ^ qD  | j sk Pn  | d 7} q W| S(   Ni    i   (   R5   RZ   RL  R  RH  RA   (   R
   R\   R^  R  Ru  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s    	*	c         C   s   t    } t |  j  d } x^ d | k r| |  j | } | j g  | j D] } | f | ^ qH  | j so Pn  | d 8} q W| S(   Ni   i    (   R5   RZ   RL  R  RI  RA   (   R
   R\   R^  R  Rv  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s    	*	c         C   s%   x |  j  D] } | j s
 t Sq
 Wt S(   N(   RL  RA   RB   R@   (   R
   R  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s    	c         C   s|  i  } xj t  t |  j   D]S } | f } xA t j |  j | j  D]& \ } } |  j | |  | | | <qE Wq Wxt  t |  j  d  D] } |  j | } | f } x | j D] } i  } x( | j |  D] } |  j	 | | | <q W| }	 x} |	 d t |  j  k  ro|	 d 7}	 |  j |	 }
 x9 |
 j
 D]. } |	 f | } | | | j | | f  q-W|
 j s Pq q Wq Wq W| S(   Ni   (   R   RZ   RL  R    R   RF  R9  RI  RJ  Rb  RH  R6   RA   (   R
   R\   R^  Rw  R5  RN   R  R   R{  t   nct   ntRy  Rz  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s,    	&" 	
	c         C   sj   g  } xT |  j  D]I } | j |  j k  rF | j d t |  d  q | j t |   q Wd j |  S(   NR|  R}  t   .(   RL  Ra  R6   RU   R[   (   R
   R  R  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRS   1  s    (
   R   R   R   Ra  R	   R  R  R  R  RS   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR    s   					RK  c           B   s>   e  Z d  Z d Z d   Z d   Z e d    Z d   Z RS(   s   A term that is an unordered sequence of terms.

    Note that the inheritance structure for this node is unusual.  It
    has multiple children when it is treated as a term tree, but is
    considered a leaf node when constructing an automaton.
    i    c         O   s   t  t |   j | |   d S(   s   Term that collects an unordered sequence of terms.

        The terms are provided as arguments.  All must be instances of
        a subclass of L{Node}.N(   R   RK  R	   (   R
   RL  R  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	   D  s    c         C   s%   x |  j  D] } | j s
 t Sq
 Wt S(   N(   RL  RA   RB   R@   (   R
   R  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR  K  s    	c         G   s   d t  |  k r | d Sg  } xe t t  |   D]Q } | | } t d   | |  | | d  } | j t | |  j |     q3 Wt |   S(   s:  Create a term tree that implements unordered catenation of
        the terms.

        This expansion results in a standard choice/sequence term
        tree, at the cost of quadratic state expansion because terms
        are L{cloned<Node.clone>} as required to satisfy the tree
        requirements of the term tree.

        @param terms: The tuple of terms that are elements of an
        accepted sequence.

        @return: A term tree comprising a choice between sequences
        that connect each term to the unordered catenation of the
        remaining terms.i   i    c         S   s
   |  j    S(   N(   R   (   R  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRX   f  s    (   RZ   R   RY   R6   R  t   CreateTermTreeR  (   R   RL  t	   disjunctsR  R/  t   rem(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR  Q  s    
"#c         C   sC   t  j d  t  j d  j g  |  j D] } t |  ^ q%  d S(   Ns   &(t   ,R}  (   R    R_  R[   RL  RU   (   R
   t   _t(    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRS   j  s    (	   R   R   R   Ra  R	   R  R   R  RS   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRK  :  s   		t   Symbolc           B   s/   e  Z d  Z d Z d   Z d   Z d   Z RS(   sV   A leaf term that is a symbol.

    The symbol is represented by the L{metadata} field.i    c         K   s$   | | d <t  t |   j |   d  S(   NRu   (   R   R  R	   (   R
   R   R  (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR	   t  s    
c         C   s   t  t |   j |  j  S(   N(   R   R  R   Ru   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR   x  s    c         C   s   t  |  j  S(   N(   RU   Ru   (   R
   (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyRS   {  s    (   R   R   R   Ra  R	   R   RS   (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyR  m  s
   		($   R   R   R   t   loggingt
   pyxb.utilsR    t   pyxb.utils.six.movesR   t	   getLoggerR   t   log_t	   ExceptionR   R   R   R   R   R   t   objectR   R   Rl   RG   R4   R   R   R   R   R  Rl  RG  RC  R  R  RK  R  (    (    (    sC   /data/av2000/b2b/venv/lib/python2.7/site-packages/pyxb/utils/fac.pyt   <module>:   s>   	8/ =h IX1L3