PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB`  Ɵ[c@sdZdefdYZdddYZddlZddlZejddkZd Zd Z d Z d Z d Z dZ dZedkrendS(s1This module implements a Finite State Machine (FSM). In addition to state this FSM also maintains a user defined "memory". So this FSM can be used as a Push-down Automata (PDA) since a PDA is a FSM + memory. The following describes how the FSM works, but you will probably also need to see the example function to understand how the FSM is used in practice. You define an FSM by building tables of transitions. For a given input symbol the process() method uses these tables to decide what action to call and what the next state will be. The FSM has a table of transitions that associate: (input_symbol, current_state) --> (action, next_state) Where "action" is a function you define. The symbols and states can be any objects. You use the add_transition() and add_transition_list() methods to add to the transition table. The FSM also has a table of transitions that associate: (current_state) --> (action, next_state) You use the add_transition_any() method to add to this transition table. The FSM also has one default transition that is not associated with any specific input_symbol or state. You use the set_default_transition() method to set the default transition. When an action function is called it is passed a reference to the FSM. The action function may then access attributes of the FSM such as input_symbol, current_state, or "memory". The "memory" attribute can be any object that you want to pass along to the action functions. It is not used by the FSM itself. For parsing you would typically pass a list to be used as a stack. The processing sequence is as follows. The process() method is given an input_symbol to process. The FSM will search the table of transitions that associate: (input_symbol, current_state) --> (action, next_state) If the pair (input_symbol, current_state) is found then process() will call the associated action function and then set the current state to the next_state. If the FSM cannot find a match for (input_symbol, current_state) it will then search the table of transitions that associate: (current_state) --> (action, next_state) If the current_state is found then the process() method will call the associated action function and then set the current state to the next_state. Notice that this table lacks an input_symbol. It lets you define transitions for a current_state and ANY input_symbol. Hence, it is called the "any" table. Remember, it is always checked after first searching the table for a specific (input_symbol, current_state). For the case where the FSM did not match either of the previous two cases the FSM will try to use the default transition. If the default transition is defined then the process() method will call the associated action function and then set the current state to the next_state. This lets you define a default transition as a catch-all case. You can think of it as an exception handler. There can be only one default transition. Finally, if none of the previous cases are defined for an input_symbol and current_state then the FSM will raise an exception. This may be desirable, but you can always prevent this just by defining a default transition. Noah Spurrier 20020822 PEXPECT LICENSE This license is approved by the OSI and FSF as GPL-compatible. http://opensource.org/licenses/isc-license.txt Copyright (c) 2012, Noah Spurrier PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. t ExceptionFSMcBs eZdZdZdZRS(s This is the FSM Exception class.cCs ||_dS(N(tvalue(tselfR((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pyt__init__[scCsdt|jS(NsExceptionFSM: (tstrR(R((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pyt__str__^s(t__name__t __module__t__doc__RR(((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pyRWs tFSMcBsteZdZd dZdZd d dZd d dZd d dZdZ dZ dZ d Z RS( s*This is a Finite State Machine (FSM). cCsXi|_i|_d|_d|_||_|j|_d|_d|_||_ dS(sThis creates the FSM. You set the initial state here. The "memory" attribute is any object that you want to pass along to the action functions. It is not used by the FSM. For parsing you would typically pass a list to be used as a stack. N( tstate_transitionststate_transitions_anytNonetdefault_transitiont input_symbolt initial_statet current_statet next_statetactiontmemory(RRR((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pyRfs        cCs|j|_d|_dS(sThis sets the current_state to the initial_state and sets input_symbol to None. The initial state was set by the constructor __init__(). N(RRR R(R((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pytresetzs cCs2|dkr|}n||f|j||f (action, next_state) The action may be set to None in which case the process() method will ignore the action and only set the next_state. The next_state may be set to None in which case the current state will be unchanged. You can also set transitions for a list of symbols by using add_transition_list(). N(R R (RRtstateRR((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pytadd_transitions  cCs@|dkr|}nx$|D]}|j||||qWdS(sThis adds the same transition for a list of input symbols. You can pass a list or a string. Note that it is handy to use string.digits, string.whitespace, string.letters, etc. to add transitions that match character classes. The action may be set to None in which case the process() method will ignore the action and only set the next_state. The next_state may be set to None in which case the current state will be unchanged. N(R R(Rtlist_input_symbolsRRRR((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pytadd_transition_lists   cCs,|dkr|}n||f|j| (action, next_state) That is, any input symbol will match the current state. The process() method checks the "any" state associations after it first checks for an exact match of (input_symbol, current_state). The action may be set to None in which case the process() method will ignore the action and only set the next_state. The next_state may be set to None in which case the current state will be unchanged. N(R R (RRRR((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pytadd_transition_anys  cCs||f|_dS(sThis sets the default transition. This defines an action and next_state if the FSM cannot find the input symbol and the current state in the transition list and if the FSM cannot find the current_state in the transition_any list. This is useful as a final fall-through state for catching errors and undefined states. The default transition can be removed by setting the attribute default_transition to None. N(R (RRR((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pytset_default_transitions cCs|||f|jkr&|j||fS||jkr@|j|S|jdk rV|jStdt|t|fdS(snThis returns (action, next state) given an input_symbol and state. This does not modify the FSM state, so calling this method has no side effects. Normally you do not call this method directly. It is called by process(). The sequence of steps to check for a defined transition goes from the most specific to the least specific. 1. Check state_transitions[] that match exactly the tuple, (input_symbol, state) 2. Check state_transitions_any[] that match (state) In other words, match a specific state and ANY input_symbol. 3. Check if the default_transition is defined. This catches any input_symbol and any state. This is a handler for errors, undefined states, or defaults. 4. No transition was defined. If we get here then raise an exception. s"Transition is undefined: (%s, %s).N(R R R R RR(RRR((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pytget_transitions cCse||_|j|j|j\|_|_|jdk rL|j|n|j|_d|_dS(sThis is the main method that you call to process input. This may cause the FSM to change state and call an action. This method calls get_transition() to find the action and next_state associated with the input_symbol and current_state. If the action is None then the action is not called and only the current state is changed. This method processes one complete input symbol. You can process a list of symbols (or a string) by calling process_list(). N(RRRRRR (RR((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pytprocesss $ cCs"x|D]}|j|qWdS(spThis takes a list and sends each element to process(). The list may be a string or any iterable object. N(R(Rt input_symbolsts((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pyt process_lists N( RRRR RRRRRRRRR(((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pyR as   ! iNiicCs|jj|jdS(N(RtappendR(tfsm((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pytBeginBuildNumberscCs0|jj}||j}|jj|dS(N(RtpopRR (R!R((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pyt BuildNumbers cCs)|jj}|jjt|dS(N(RR#R tint(R!R((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pytEndBuildNumberscCs|jj}|jj}|jdkrD|jj||nr|jdkrj|jj||nL|jdkr|jj||n&|jdkr|jj||ndS(Nt+t-t*t/(RR#RR (R!tartal((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pyt DoOperator!scCst|jjGHdS(N(RRR#(R!((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pytDoEqual-scCsdGHt|jGHdS(NsThat does not compute.(RR(R!((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pytError0scCstdg}|jtd|jdd d|jddtd|jtj dt d|jtj dt d|jtj dt d|jddtdd GHdGHdGHdGHdGHd GHtrtntd }|j|d S( sThis is where the example starts and the FSM state transitions are defined. Note that states are strings (such as 'INIT'). This is not necessary, but it makes the example easier to read. tINITt=tBUILDING_NUMBERs+-*/sEnter an RPN Expression.s.Numbers may be integers. Operators are * / + -s4Use the = sign to evaluate and print the expression.s For example: s 167 3 2 2 * * * 1 - =s> N((R RR/RR RR.RtstringtdigitsR"R$t whitespaceR&R-tPY3tinputt raw_inputR(tftinputstr((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pytmain4s t__main__((Rt ExceptionRR tsysR3t version_infoR6R"R$R&R-R.R/R;R(((s,/tmp/pip-build-ViqJzN/pexpect/pexpect/FSM.pytUs