Files
old-parkingkoncept/parkingkonceptvenv/lib/python3.7/site-packages/docutils/__pycache__/statemachine.cpython-37.pyc

720 lines
48 KiB
Plaintext
Raw Normal View History

2019-11-17 12:44:16 +01:00
B
<00>[<5B>]<5D><><00>@s<>dZdZddlZddlZddlZddlZddlmZddlm Z Gdd<07>d<07>Z
Gdd <09>d <09>Z Gd
d <0B>d e
<EFBFBD>Z Gd d <0A>d e <0B>Z Gdd<0F>d<0F>ZGdd<11>dee
<EFBFBD>ZGdd<13>dee <0C>ZGdd<15>d<15>ZGdd<17>de<11>ZGdd<19>de<13>ZGdd<1B>de<14>ZGdd<1D>de<14>ZGdd<1F>de<14>ZGd d!<21>d!e<14>ZGd"d#<23>d#e<14>ZGd$d%<25>d%e<14>ZGd&d'<27>d'e<14>ZGd(d)<29>d)e<13>ZGd*d+<2B>d+e<13>Zd,d-e<03>d.<2E>fd/d0<64>Zd1d2<64>Z dS)3a
A finite state machine specialized for regular-expression-based text filters,
this module defines the following classes:
- `StateMachine`, a state machine
- `State`, a state superclass
- `StateMachineWS`, a whitespace-sensitive version of `StateMachine`
- `StateWS`, a state superclass for use with `StateMachineWS`
- `SearchStateMachine`, uses `re.search()` instead of `re.match()`
- `SearchStateMachineWS`, uses `re.search()` instead of `re.match()`
- `ViewList`, extends standard Python lists.
- `StringList`, string-specific ViewList.
Exception classes:
- `StateMachineError`
- `UnknownStateError`
- `DuplicateStateError`
- `UnknownTransitionError`
- `DuplicateTransitionError`
- `TransitionPatternNotFound`
- `TransitionMethodNotFound`
- `UnexpectedIndentationError`
- `TransitionCorrection`: Raised to switch to another transition.
- `StateCorrection`: Raised to switch to another state & transition.
Functions:
- `string2lines()`: split a multi-line string into a list of one-line strings
How To Use This Module
======================
(See the individual classes, methods, and attributes for details.)
1. Import it: ``import statemachine`` or ``from statemachine import ...``.
You will also need to ``import re``.
2. Derive a subclass of `State` (or `StateWS`) for each state in your state
machine::
class MyState(statemachine.State):
Within the state's class definition:
a) Include a pattern for each transition, in `State.patterns`::
patterns = {'atransition': r'pattern', ...}
b) Include a list of initial transitions to be set up automatically, in
`State.initial_transitions`::
initial_transitions = ['atransition', ...]
c) Define a method for each transition, with the same name as the
transition pattern::
def atransition(self, match, context, next_state):
# do something
result = [...] # a list
return context, next_state, result
# context, next_state may be altered
Transition methods may raise an `EOFError` to cut processing short.
d) You may wish to override the `State.bof()` and/or `State.eof()` implicit
transition methods, which handle the beginning- and end-of-file.
e) In order to handle nested processing, you may wish to override the
attributes `State.nested_sm` and/or `State.nested_sm_kwargs`.
If you are using `StateWS` as a base class, in order to handle nested
indented blocks, you may wish to:
- override the attributes `StateWS.indent_sm`,
`StateWS.indent_sm_kwargs`, `StateWS.known_indent_sm`, and/or
`StateWS.known_indent_sm_kwargs`;
- override the `StateWS.blank()` method; and/or
- override or extend the `StateWS.indent()`, `StateWS.known_indent()`,
and/or `StateWS.firstknown_indent()` methods.
3. Create a state machine object::
sm = StateMachine(state_classes=[MyState, ...],
initial_state='MyState')
4. Obtain the input text, which needs to be converted into a tab-free list of
one-line strings. For example, to read text from a file called
'inputfile'::
input_string = open('inputfile').read()
input_lines = statemachine.string2lines(input_string)
5. Run the state machine on the input text and collect the results, a list::
results = sm.run(input_lines)
6. Remove any lingering circular references::
sm.unlink()
Zrestructuredtext<78>N)<01>utils)<01> ErrorOutputc@s<>eZdZdZd6dd<04>Zdd<06>Zd7d d
<EFBFBD>Zd8d d <0C>Zd9dd<0F>Zdd<11>Z dd<13>Z
dd<15>Z d:dd<17>Z dd<19>Z dd<1B>Zdd<1D>Zdd<1F>Zd;d d!<21>Zd"d#<23>Zd<d$d%<25>Zd=d&d'<27>Zd(d)<29>Zd*d+<2B>Zd,d-<2D>Zd.d/<2F>Zd0d1<64>Zd2d3<64>Zd4d5<64>ZdS)><3E> StateMachinea<65>
A finite state machine for text filters using regular expressions.
The input is provided in the form of a list of one-line strings (no
newlines). States are subclasses of the `State` class. Transitions consist
of regular expression patterns and transition methods, and are defined in
each state.
The state machine is started with the `run()` method, which returns the
results of processing in a list.
FcCsLd|_d|_d|_d|_||_||_||_i|_|<00>|<01>g|_ t
<EFBFBD>|_ dS)a+
Initialize a `StateMachine` object; add state objects.
Parameters:
- `state_classes`: a list of `State` (sub)classes.
- `initial_state`: a string, the class name of the initial state.
- `debug`: a boolean; produce verbose output if true (nonzero).
Nr<00><><EFBFBD><EFBFBD><EFBFBD>) <0C> input_lines<65> input_offset<65>line<6E> line_offset<65>debug<75> initial_state<74> current_state<74>states<65>
add_states<EFBFBD> observersr<00>_stderr)<04>self<6C> state_classesr r
<00>r<00>;/tmp/pip-install-u_6_z2pz/docutils/docutils/statemachine.py<70>__init__<5F>s 
zStateMachine.__init__cCs*xt|j<01><02><00>D] }|<01><03>qWd|_dS)z9Remove circular references to objects no longer required.N)<04>listr <00>values<65>unlink)r<00>staterrrr<00>s zStateMachine.unlinkrNc
Csn|<00><00>t|t<02>r||_nt||d<01>|_||_d|_|p<|j|_|jrft d|jd<04>
|j<03>f|j d<05>d}g}|<00> <0C>}<08>y<>|jr<>t d|j d<05>|<08> |<03>\}} |<07>| <09><00>x<>y<EFBFBD>yR|<00><0F>|jr<>|j<03>|j<05>\}
} t d|
| |jf|j d<05>|<00>|||<06>\}} } WnJtk
<EFBFBD>rH|j<08>r.t d |jj|j d<05>|<08>|<03>} |<07>| <09>PYn X|<07>| <09>Wn<>tk
<EFBFBD>r<>} z@|<00><18>| jd
f}|j<08>r<>t d |jj|d
f|j d<05>w<>Wdd} ~ XYn~tk
<EFBFBD>r.} zZ|<00><18>| jd
} t| j<19>d k<02>r<>d}n | jd f}|j<08>rt d | |d
f|j d<05>Wdd} ~ XYnXd}|<00> | <0C>}q<>WWn|j<08>r\|<00><1C><00>YnXg|_|S)a<>
Run the state machine on `input_lines`. Return results (a list).
Reset `self.line_offset` and `self.current_state`. Run the
beginning-of-file transition. Input one line at a time and check for a
matching transition. If a match is found, call the transition method
and possibly change the state. Store the context returned by the
transition method to be passed on to the next transition matched.
Accumulate the results returned by the transition methods in a list.
Run the end-of-file transition. Finally, return the accumulated
results.
Parameters:
- `input_lines`: a list of strings without newlines, or `StringList`.
- `input_offset`: the line offset of `input_lines` from the beginning
of the file.
- `context`: application-specific storage.
- `input_source`: name or path of source of `input_lines`.
- `initial_state`: name of initial state.
)<01>sourcerz5
StateMachine.run: input_lines (line_offset=%s):
| %sz
| )<01>fileNz!
StateMachine.run: bof transitionz4
StateMachine.run: line (source=%r, offset=%r):
| %sz$
StateMachine.run: %s.eof transitionrzE
StateMachine.run: TransitionCorrection to state "%s", transition %s.<2E>z@
StateMachine.run: StateCorrection to state "%s", transition %s.)<1E> runtime_init<69>
isinstance<EFBFBD>
StringListrrr r r r
<00>print<6E>joinr<00> get_state<74>bof<6F>extend<6E> next_line<6E>infor<00>
check_line<EFBFBD>EOFError<6F> __class__<5F>__name__<5F>eof<6F>TransitionCorrection<6F> previous_line<6E>args<67>StateCorrection<6F>len<65>errorr)rrr<00>contextZ input_sourcer <00> transitions<6E>resultsr<00>resultr<00>offset<65>
next_state<EFBFBD> exceptionrrr<00>run<75>s<>
 
 

 
 (zStateMachine.runcCsh|r8|jr2||jkr2td|j||<00><03>f|jd<02>||_y |j|jStk
rbt|j<01><01>YnXdS)z<>
Return current state object; set it first if `next_state` given.
Parameter `next_state`: a string, the name of the next state.
Exception: `UnknownStateError` raised if `next_state` unknown.
zJ
StateMachine.get_state: Changing state from "%s" to "%s" (input line %s).)rN)r
r r <00>abs_line_numberrr <00>KeyError<6F>UnknownStateError)rr7rrrr"s zStateMachine.get_statercCsVzFy |j|7_|j|j|_Wntk
r@d|_t<04>YnX|jS|<00><05>XdS)z9Load `self.line` with the `n`'th next line and return it.N)r rr<00>
IndexErrorr(<00>notify_observers)r<00>nrrrr%.s
zStateMachine.next_linecCs0y|j|jd<00><02> Stk
r*dSXdS)z3Return 1 if the next line is blank or non-existant.rN)rr <00>stripr=)rrrr<00>is_next_line_blank;szStateMachine.is_next_line_blankcCs|jt|j<02>dkS)z0Return 1 if the input is at or past end-of-file.r)r r0r)rrrr<00>at_eofBszStateMachine.at_eofcCs
|jdkS)z8Return 1 if the input is at or before beginning-of-file.r)r )rrrr<00>at_bofFszStateMachine.at_bofcCs<|j|8_|jdkr d|_n|j|j|_|<00><03>|jS)z=Load `self.line` with the `n`'th previous line and return it.rN)r rrr>)rr?rrrr-Js 
zStateMachine.previous_linecCsTzDy||j|_|j|j|_Wntk
r>d|_t<05>YnX|jS|<00><06>XdS)z?Jump to absolute line offset `line_offset`, load and return it.N)rr rrr=r(r>)rr rrr<00> goto_lineTs 
zStateMachine.goto_linecCs|j<00>||j<00>S)z<Return source of line at absolute line offset `line_offset`.)rrr)rr rrr<00>
get_sourceaszStateMachine.get_sourcecCs |j|jS)z;Return line offset of current line, from beginning of file.)r r)rrrr<00>abs_line_offseteszStateMachine.abs_line_offsetcCs|j|jdS)z5Return line number of current line (counting from 1).r)r r)rrrrr:iszStateMachine.abs_line_numbercCs<>|dkr|j}n||jd}y|j<02>|<02>\}}|d}WnJtk
rj|<00>||j<00>\}}||dfStk
r<EFBFBD>d\}}YnX||fS)a\Return (source, line) tuple for current or given line number.
Looks up the source and line number in the `self.input_lines`
StringList instance to count for included source files.
If the optional argument `lineno` is given, convert it from an
absolute line number to the corresponding (source, line) pair.
Nr)NN)r rrr&<00> TypeError<6F>get_source_and_liner=)r<00>linenor6<00>srcZ srcoffsetZsrclinerrrrHms   z StateMachine.get_source_and_linecCs^|jj|jddd|t|<01>d<04>|jj|jddd|dd<04>|j<00>|jdt||<02><02>dS)Nr<00>zinternal padding after )rr6zinternal padding before r<00>)r<00>insertr r0r)rrrrrr<00> insert_input<75>s zStateMachine.insert_inputc
Csly&|j<00>|j|<01>}|<00>t|<02>d<00>|Stk
rf}z"|jd}|<00>t|<02>d<00><00>Wdd}~XYnXdS)z<>
Return a contiguous block of text.
If `flush_left` is true, raise `UnexpectedIndentationError` if an
indented line is encountered before the text block ends (with a blank
line).
rrN)r<00>get_text_blockr r%r0<00>UnexpectedIndentationErrorr.)r<00>
flush_left<EFBFBD>block<63>errrrrrO<00>s

zStateMachine.get_text_blockc
Cs<>|dkr|j}d}|jr2td|jj|f|jd<03>x<>|D]P}|j|\}}}|<06>|j<08>} | r8|jr|td||jjf|jd<03>|| ||<08>Sq8W|jr<>td|jj|jd<03>|<02> ||<03>SdS)a<>
Examine one line of input for a transition match & execute its method.
Parameters:
- `context`: application-dependent storage.
- `state`: a `State` object, the current state.
- `transitions`: an optional ordered list of transition names to try,
instead of ``state.transition_order``.
Return the values returned by the transition method:
- context: possibly modified from the parameter `context`;
- next state name (`State` subclass name);
- the result output of the transition, a list.
When there is no match, ``state.no_match()`` is called and its return
value is returned.
Nz5
StateMachine.check_line: state="%s", transitions=%r.)rz@
StateMachine.check_line: Matched transition "%s" in state "%s".z1
StateMachine.check_line: No match in state "%s".)
<EFBFBD>transition_orderr
r r)r*rr3<00>matchr<00>no_match)
rr2rr3Zstate_correction<6F>name<6D>pattern<72>methodr7rUrrrr'<00>s*
 zStateMachine.check_linecCs.|j}||jkrt|<02><01>|||j<03>|j|<dS)z<>
Initialize & add a `state_class` (`State` subclass) object.
Exception: `DuplicateStateError` raised if `state_class` was already
added.
N)r*r <00>DuplicateStateErrorr
)r<00> state_classZ statenamerrr<00> add_state<74>s
zStateMachine.add_statecCsx|D]}|<00>|<02>qWdS)zE
Add `state_classes` (a list of `State` subclasses).
N)r\)rrr[rrrr<00>s
zStateMachine.add_statescCs$xt|j<01><02><00>D] }|<01><03>qWdS)z+
Initialize `self.states`.
N)rr rr)rrrrrr<00>szStateMachine.runtime_initcCsXt<00>\}}}}}td||f|jd<02>td|<00><03>|jd<02>td|||f|jd<02>dS)zReport error details.z%s: %s)rz input line %szmodule %s, line %s, function %sN)<04>_exception_datar rr:)r<00>type<70>value<75>moduler<00>functionrrrr1<00>s
zStateMachine.errorcCs|j<00>|<01>dS)z<>
The `observer` parameter is a function or bound method which takes two
arguments, the source and offset of the current line.
N)r<00>append)r<00>observerrrr<00>attach_observer<65>szStateMachine.attach_observercCs|j<00>|<01>dS)N)r<00>remove)rrcrrr<00>detach_observer<65>szStateMachine.detach_observerc CsHxB|jD]8}y|j<01>|j<03>}Wntk
r6d}YnX||<02>qWdS)N)NN)rrr&r r=)rrcr&rrrr>s  
zStateMachine.notify_observers)F)rNNN)N)r)r)N)F)N)r*<00>
__module__<EFBFBD> __qualname__<5F>__doc__rrr9r"r%rArBrCr-rDrErFr:rHrNrOr'r\rrr1rdrfr>rrrrrus4 
/
`


 


, rc@s<>eZdZdZdZdZdZdZddd<05>Zdd<07>Z dd <09>Z
d
d <0B>Z d d <0A>Z dd<0F>Z dd<11>Zddd<13>Zdd<15>Zdd<17>Zdd<19>Zdd<1B>Zdd<1D>ZdS) <20>Stateav
State superclass. Contains a list of transitions, and transition methods.
Transition methods all have the same signature. They take 3 parameters:
- An `re` match object. ``match.string`` contains the matched input line,
``match.start()`` gives the start index of the match, and
``match.end()`` gives the end index.
- A context object, whose meaning is application-defined (initial value
``None``). It can be used to store any information required by the state
machine, and the retured context is passed on to the next transition
method unchanged.
- The name of the next state, a string, taken from the transitions list;
normally it is returned unchanged, but it may be altered by the
transition method if necessary.
Transition methods all return a 3-tuple:
- A context object, as (potentially) modified by the transition method.
- The next state name (a return value of ``None`` means no state change).
- The processing result, a list, which is accumulated by the state
machine.
Transition methods may raise an `EOFError` to cut processing short.
There are two implicit transitions, and corresponding transition methods
are defined: `bof()` handles the beginning-of-file, and `eof()` handles
the end-of-file. These methods have non-standard signatures and return
values. `bof()` returns the initial context and results, and may be used
to return a header string, or do any other processing needed. `eof()`
should handle any remaining context and wrap things up; it returns the
final processing result.
Typical applications need only subclass `State` (or a subclass), set the
`patterns` and `initial_transitions` class attributes, and provide
corresponding transition methods. The default object initialization will
take care of constructing the list of transitions.
NFcCsVg|_i|_|<00><02>||_||_|jdkr4|jj|_|jdkrR|jg|jjd<02>|_dS)z<>
Initialize a `State` object; make & add initial transitions.
Parameters:
- `statemachine`: the controlling `StateMachine` object.
- `debug`: a boolean; produce verbose output if true.
N)rr ) rTr3<00>add_initial_transitions<6E> state_machiner
<00> nested_smr)<00>nested_sm_kwargsr*)rrlr
rrrrVs
 


zState.__init__cCsdS)z{
Initialize this `State` before running the state machine; called from
`self.state_machine.run()`.
Nr)rrrrrzszState.runtime_initcCs
d|_dS)z9Remove circular references to objects no longer required.N)rl)rrrrr<00>sz State.unlinkcCs&|jr"|<00>|j<00>\}}|<00>||<02>dS)z>Make and add transitions listed in `self.initial_transitions`.N)<03>initial_transitions<6E>make_transitions<6E>add_transitions)r<00>namesr3rrrrk<00>s zState.add_initial_transitionscCsNx.|D]&}||jkrt|<03><01>||krt|<03><01>qW||jdd<02><|j<00>|<02>dS)a"
Add a list of transitions to the start of the transition list.
Parameters:
- `names`: a list of transition names.
- `transitions`: a mapping of names to transition tuples.
Exceptions: `DuplicateTransitionError`, `UnknownTransitionError`.
Nr)r3<00>DuplicateTransitionError<6F>UnknownTransitionErrorrT<00>update)rrrr3rWrrrrq<00>s

 zState.add_transitionscCs0||jkrt|<01><01>|g|jdd<02><||j|<dS)z<>
Add a transition to the start of the transition list.
Parameter `transition`: a ready-made transition 3-tuple.
Exception: `DuplicateTransitionError`.
Nr)r3rsrT)rrWZ
transitionrrr<00>add_transition<6F>s
zState.add_transitioncCs2y|j|=|j<01>|<01>Wnt|<01><01>YnXdS)z^
Remove a transition by `name`.
Exception: `UnknownTransitionError`.
N)r3rTrert)rrWrrr<00>remove_transition<6F>s
zState.remove_transitioncCs<>|dkr|jj}y"|j|}t|d<02>s0t<04>|<03>}Wn(tk
rZtd|jj|f<00><01>YnXyt||<01>}Wn(t k
r<EFBFBD>t
d|jj|f<00><01>YnX|||fS)a<>
Make & return a transition tuple based on `name`.
This is a convenience function to simplify transition creation.
Parameters:
- `name`: a string, the name of the transition pattern & method. This
`State` object must have a method called '`name`', and a dictionary
`self.patterns` containing a key '`name`'.
- `next_state`: a string, the name of the next `State` object for this
transition. A value of ``None`` (or absent) implies no state change
(i.e., continue with the same state).
Exceptions: `TransitionPatternNotFound`, `TransitionMethodNotFound`.
NrUz%s.patterns[%r]z%s.%s) r)r*<00>patterns<6E>hasattr<74>re<72>compiler;<00>TransitionPatternNotFound<6E>getattr<74>AttributeError<6F>TransitionMethodNotFound)rrWr7rXrYrrr<00>make_transition<6F>s

zState.make_transitioncCsltd<01>}g}i}xR|D]J}t|<05>|kr@|<00>|<05>||<|<03>|<05>q|j|<05>||d<|<03>|d<00>qW||fS)z<>
Return a list of transition names and a transition mapping.
Parameter `name_list`: a list, where each entry is either a transition
name string, or a 1- or 2-tuple (transition name, optional next state
name).
rKr)r^r<>rb)r<00> name_listZ
stringtyperrr3Z namestaterrrrp<00>s
  zState.make_transitionscCs
|dgfS)a'
Called when there is no match from `StateMachine.check_line()`.
Return the same values returned by transition methods:
- context: unchanged;
- next state name: ``None``;
- empty result list.
Override in subclasses to catch this event.
Nr)rr2r3rrrrV<00>s zState.no_matchcCs|gfS)z<>
Handle beginning-of-file. Return unchanged `context`, empty result.
Override in subclasses.
Parameter `context`: application-defined storage.
r)rr2rrrr#<00>sz State.bofcCsgS)z<>
Handle end-of-file. Return empty result.
Override in subclasses.
Parameter `context`: application-defined storage.
r)rr2rrrr+sz State.eofcCs
||gfS)z<>
A "do nothing" transition method.
Return unchanged `context` & `next_state`, empty result. Useful for
simple state changes (actionless transitions).
r)rrUr2r7rrr<00>nopsz State.nop)F)N)r*rgrhrirxrormrnrrrrkrqrvrwr<>rprVr#r+r<>rrrrrj s$'
$ 
!

rjc@s.eZdZdZd dd<05>Zd dd<07>Zd dd <09>Zd
S)<0E>StateMachineWSaq
`StateMachine` subclass specialized for whitespace recognition.
There are three methods provided for extracting indented text blocks:
- `get_indented()`: use when the indent is unknown.
- `get_known_indented()`: use when the indent is known for all lines.
- `get_first_known_indented()`: use when only the first line's indent is
known.
FTcCsh|<00><00>}|j<01>|j||<02>\}}}|r6|<00>t|<04>d<00>x$|rZ|d<00><06>sZ|<04><07>|d7}q8W||||fS)a
Return a block of indented lines of text, and info.
Extract an indented block where the indent is unknown for all lines.
:Parameters:
- `until_blank`: Stop collecting at the first blank line if true.
- `strip_indent`: Strip common leading indent if true (default).
:Return:
- the indented block (a list of lines of text),
- its indent,
- its first line offset from BOF, and
- whether or not it finished with a blank line.
rr)rFr<00> get_indentedr r%r0r@<00>
trim_start)r<00> until_blank<6E> strip_indentr6<00>indented<65>indent<6E> blank_finishrrrr<>&s zStateMachineWS.get_indentedcCsf|<00><00>}|jj|j|||d<01>\}}}|<00>t|<05>d<00>x$|rZ|d<00><06>sZ|<05><07>|d7}q8W|||fS)a<>
Return an indented block and info.
Extract an indented block where the indent is known for all lines.
Starting with the current line, extract the entire text block with at
least `indent` indentation (which must be whitespace, except for the
first line).
:Parameters:
- `indent`: The number of indent columns/characters.
- `until_blank`: Stop collecting at the first blank line if true.
- `strip_indent`: Strip `indent` characters of indentation if true
(default).
:Return:
- the indented block,
- its first line offset from BOF, and
- whether or not it finished with a blank line.
)<01> block_indentrr)rFrr<>r r%r0r@r<>)rr<>r<>r<>r6r<>r<>rrr<00>get_known_indented@s z!StateMachineWS.get_known_indentedcCsl|<00><00>}|jj|j|||d<01>\}}}|<00>t|<06>d<00>|r`x$|r^|d<00><06>s^|<06><07>|d7}q<W||||fS)a<>
Return an indented block and info.
Extract an indented block where the indent is known for the first line
and unknown for all other lines.
:Parameters:
- `indent`: The first line's indent (# of columns/characters).
- `until_blank`: Stop collecting at the first blank line if true
(1).
- `strip_indent`: Strip `indent` characters of indentation if true
(1, default).
- `strip_top`: Strip blank lines from the beginning of the block.
:Return:
- the indented block,
- its indent,
- its first line offset from BOF, and
- whether or not it finished with a blank line.
)<01> first_indentrr)rFrr<>r r%r0r@r<>)rr<>r<>r<>Z strip_topr6r<>r<>rrr<00>get_first_known_indented^s z'StateMachineWS.get_first_known_indentedN)FT)FT)FTT)r*rgrhrir<>r<>r<>rrrrr<>s
 

r<>c@s`eZdZdZdZdZdZdZddd<05>ZdZ ddd<08>Z
d d
<EFBFBD>Z d d <0C>Z d d<0E>Z dd<10>Zdd<12>ZdS)<14>StateWSa<53>
State superclass specialized for whitespace (blank lines & indents).
Use this class with `StateMachineWS`. The transitions 'blank' (for blank
lines) and 'indent' (for indented text blocks) are added automatically,
before any other transitions. The transition method `blank()` handles
blank lines and `indent()` handles nested indented blocks. Indented
blocks trigger a new state machine to be created by `indent()` and run.
The class of the state machine to be created is in `indent_sm`, and the
constructor keyword arguments are in the dictionary `indent_sm_kwargs`.
The methods `known_indent()` and `firstknown_indent()` are provided for
indented blocks where the indent (all lines' and first line's only,
respectively) is known to the transition method, along with the attributes
`known_indent_sm` and `known_indent_sm_kwargs`. Neither transition method
is triggered automatically.
Nz *$z +)<02>blankr<6B>FcCsZt<00>|||<02>|jdkr |j|_|jdkr2|j|_|jdkrD|j|_|jdkrV|j|_dS)z<>
Initialize a `StateSM` object; extends `State.__init__()`.
Check for indent state machine attributes, set defaults if not set.
N)rjr<00> indent_smrm<00>indent_sm_kwargsrn<00>known_indent_sm<73>known_indent_sm_kwargs)rrlr
rrrr<00>s



zStateWS.__init__cCsHt<00>|<00>|jdkri|_|j<02>|j<04>|<00>|j<06>\}}|<00>||<02>dS)z<>
Add whitespace-specific transitions before those defined in subclass.
Extends `State.add_initial_transitions()`.
N)rjrkrxru<00> ws_patternsrp<00>ws_initial_transitionsrq)rrrr3rrrrk<00>s

 zStateWS.add_initial_transitionscCs|<00>|||<03>S)z9Handle blank lines. Does nothing. Override in subclasses.)r<>)rrUr2r7rrrr<><00>sz StateWS.blankc
CsB|j<00><01>\}}}}|jfd|ji|j<04><02>}|j||d<02>} ||| fS)z<>
Handle an indented text block. Extend or override in subclasses.
Recursively run the registered state machine for indented blocks
(`self.indent_sm`).
r
)r)rlr<>r<>r
r<>r9)
rrUr2r7r<>r<>r r<><00>smr4rrrr<><00>szStateWS.indentc CsF|j<00>|<01><02><00>\}}}|jfd|ji|j<05><02>}|j||d<02>}|||fS)a
Handle a known-indent text block. Extend or override in subclasses.
Recursively run the registered state machine for known-indent indented
blocks (`self.known_indent_sm`). The indent is the length of the
match, ``match.end()``.
r
)r)rlr<><00>endr<64>r
r<>r9) rrUr2r7r<>r r<>r<>r4rrr<00> known_indent<6E>s

zStateWS.known_indentc CsF|j<00>|<01><02><00>\}}}|jfd|ji|j<05><02>}|j||d<02>}|||fS)a0
Handle an indented text block (first line's indent known).
Extend or override in subclasses.
Recursively run the registered state machine for known-indent indented
blocks (`self.known_indent_sm`). The indent is the length of the
match, ``match.end()``.
r
)r)rlr<>r<>r<>r
r<>r9) rrUr2r7r<>r r<>r<>r4rrr<00>first_known_indent<6E>s

zStateWS.first_known_indent)F)r*rgrhrir<>r<>r<>r<>r<>r<>rrkr<>r<>r<>r<>rrrrr<><00>s
 r<>c@seZdZdZdd<03>ZdS)<05>_SearchOverridea<65>
Mix-in class to override `StateMachine` regular expression behavior.
Changes regular expression matching, from the default `re.match()`
(succeeds only if the pattern matches at the start of `self.line`) to
`re.search()` (succeeds if the pattern matches anywhere in `self.line`).
When subclassing a `StateMachine`, list this class **first** in the
inheritance list of the class definition.
cCs |<01>|j<01>S)z<>
Return the result of a regular expression search.
Overrides `StateMachine.match()`.
Parameter `pattern`: `re` compiled regular expression.
)<02>searchr)rrXrrrrUsz_SearchOverride.matchN)r*rgrhrirUrrrrr<> s
r<>c@seZdZdZdS)<03>SearchStateMachinez@`StateMachine` which uses `re.search()` instead of `re.match()`.N)r*rgrhrirrrrr<>$sr<>c@seZdZdZdS)<03>SearchStateMachineWSzB`StateMachineWS` which uses `re.search()` instead of `re.match()`.N)r*rgrhrirrrrr<>)sr<>c@sPeZdZdZdRdd<04>Zdd<06>Zdd<08>Zd d
<EFBFBD>Zd d <0C>Zd d<0E>Z dd<10>Z
dd<12>Z dd<14>Z dd<16>Z dd<18>Zdd<1A>Zdd<1C>Zdd<1E>Zdd <20>Zd!d"<22>Zd#d$<24>Zd%d&<26>Zd'd(<28>Zd)d*<2A>ZeZd+d,<2C>Zd-d.<2E>ZdSd0d1<64>ZdTd2d3<64>ZdUd5d6<64>ZdVd8d9<64>ZdWd:d;<3B>Zd<d=<3D>Z d>d?<3F>Z!d@dA<64>Z"dBdC<64>Z#dDdE<64>Z$dFdG<64>Z%dHdI<64>Z&dJdK<64>Z'dLdM<64>Z(dNdO<64>Z)dPdQ<64>Z*dS)X<>ViewLista>
List with extended functionality: slices of ViewList objects are child
lists, linked to their parents. Changes made to a child list also affect
the parent list. A child list is effectively a "view" (in the SQL sense)
of the parent list. Changes to parent lists, however, do *not* affect
active child lists. If a parent list is changed, any active child lists
should be recreated.
The start and end of the slice can be trimmed using the `trim_start()` and
`trim_end()` methods, without affecting the parent list. The link between
child and parent lists can be broken by calling `disconnect()` on the
child list.
Also, ViewList objects keep track of the source & offset of each item.
This information is accessible via the `source()`, `offset()`, and
`info()` methods.
Ncs<>g|_g|_||_||_t|t<05>rD|jdd<00>|_|jdd<00>|_n:|dk r~t|<01>|_|rb||_n<1C>fdd<02>tt|<01><01>D<00>|_t|j<00>t|j<01>ks<>t d<03><01>dS)Ncsg|] }<01>|f<02>qSrr)<02>.0<EFBFBD>i)rrr<00>
<listcomp>Zsz%ViewList.__init__.<locals>.<listcomp>z data mismatch)
<EFBFBD>data<74>items<6D>parent<6E> parent_offsetrr<>r<00>ranger0<00>AssertionError)r<00>initlistrr<>r<>r<>r)rrrBs

zViewList.__init__cCs
t|j<01>S)N)<02>strr<72>)rrrr<00>__str__]szViewList.__str__cCsd|jj|j|jfS)Nz%s(%s, items=%s))r)r*r<>r<>)rrrr<00>__repr__`szViewList.__repr__cCs|j|<00>|<01>kS)N)r<><00>_ViewList__cast)r<00>otherrrr<00>__lt__d<00>zViewList.__lt__cCs|j|<00>|<01>kS)N)r<>r<>)rr<>rrr<00>__le__er<>zViewList.__le__cCs|j|<00>|<01>kS)N)r<>r<>)rr<>rrr<00>__eq__fr<>zViewList.__eq__cCs|j|<00>|<01>kS)N)r<>r<>)rr<>rrr<00>__ne__gr<>zViewList.__ne__cCs|j|<00>|<01>kS)N)r<>r<>)rr<>rrr<00>__gt__hr<>zViewList.__gt__cCs|j|<00>|<01>kS)N)r<>r<>)rr<>rrr<00>__ge__ir<>zViewList.__ge__cCst|j|<00>|<01><01>S)N)<03>cmpr<70>r<>)rr<>rrr<00>__cmp__jr<>zViewList.__cmp__cCst|t<01>r|jS|SdS)N)rr<>r<>)rr<>rrr<00>__castls
zViewList.__castcCs
||jkS)N)r<>)r<00>itemrrr<00> __contains__rr<>zViewList.__contains__cCs
t|j<01>S)N)r0r<>)rrrr<00>__len__sr<>zViewList.__len__cCs^t|t<01>rP|jdkstd<02><01>|j|j|j|j<07>|j|j|j<07>||jpJdd<04>S|j|SdS)N)Nrzcannot handle slice with strider)r<>r<>r<>) r<00>slice<63>stepr<70>r)r<><00>start<72>stopr<70>)rr<>rrr<00> __getitem__ys 
zViewList.__getitem__cCs<>t|t<01>r<>|jdkstd<02><01>t|t<04>s.td<03><01>|j|j|j|j<08><|j |j |j|j<08><t
|j<06>t
|j <09>ksrtd<04><01>|j r<>||j |jp<>d|j |jp<>t
|<00>|j <00><n ||j|<|j r<>||j ||j <dS)N)Nrzcannot handle slice with stridez(assigning non-ViewList to ViewList slicez data mismatchr) rr<>r<>r<>r<>rGr<>r<>r<>r<>r0r<>r<>)rr<>r<>rrr<00> __setitem__<5F>s

,
zViewList.__setitem__cCs<>y(|j|=|j|=|jr&|j||j=Wnttk
r<EFBFBD>|jdksJtd<01><01>|j|j|j<08>=|j|j|j<08>=|jr<>|j|jp|d|j|jp<>t |<00>|j<00>=YnXdS)Nzcannot handle slice with strider)
r<EFBFBD>r<>r<>r<>rGr<>r<>r<>r<>r0)rr<>rrr<00> __delitem__<5F>szViewList.__delitem__cCs4t|t<01>r(|j|j|j|j|jd<01>Std<02><01>dS)N)r<>z!adding non-ViewList to a ViewList)rr<>r)r<>r<>rG)rr<>rrr<00>__add__<5F>s
zViewList.__add__cCs4t|t<01>r(|j|j|j|j|jd<01>Std<02><01>dS)N)r<>z!adding ViewList to a non-ViewList)rr<>r)r<>r<>rG)rr<>rrr<00>__radd__<5F>s
zViewList.__radd__cCs(t|t<01>r|j|j7_ntd<01><01>|S)Nz!argument to += must be a ViewList)rr<>r<>rG)rr<>rrr<00>__iadd__<5F>s
zViewList.__iadd__cCs|j|j||j|d<01>S)N)r<>)r)r<>r<>)rr?rrr<00>__mul__<5F>szViewList.__mul__cCs |j|9_|j|9_|S)N)r<>r<>)rr?rrr<00>__imul__<5F>szViewList.__imul__cCsRt|t<01>std<01><01>|jr2|j<03>t|j<06>|j|<01>|j<06>|j<06>|j <09>|j <09>dS)Nz(extending a ViewList with a non-ViewList)
rr<>rGr<>rMr0r<>r<>r$r<>)rr<>rrrr$<00>s 
zViewList.extendrcCsX|dkr|<00>|<01>n@|jr8|j<01>t|j<04>|j|||<03>|j<04>|<01>|j<07>||f<02>dS)N)r$r<>rMr0r<>r<>rbr<>)rr<>rr6rrrrb<00>s  zViewList.appendcCs<>|dkrnt|t<01>std<01><01>|j|j||<01><|j|j||<01><|jr<>t|j<03>|t|j<03>}|j<05>||j|<02>nV|j<03>||<02>|j<04>|||f<02>|jr<>t|j<03>|t|j<03>}|j<05>||j|||<04>dS)Nz+inserting non-ViewList with no source given) rr<>rGr<>r<>r<>r0rMr<>)rr<>r<>rr6<00>indexrrrrM<00>s
zViewList.insertrcCsH|jr0t|j<02>|t|j<02>}|j<00>||j<00>|j<05>|<01>|j<02>|<01>S)N)r<>r0r<><00>popr<70>r<>)rr<>r<>rrrr<><00>s
 z ViewList.poprcCsf|t|j<01>kr&td|t|j<01>f<00><01>n|dkr6td<03><01>|jd|<01>=|jd|<01>=|jrb|j|7_dS)zW
Remove items from the start of the list, without touching the parent.
zCSize of trim too large; can't trim %s items from a list of size %s.rzTrim size must be >= 0.N)r0r<>r=r<>r<>r<>)rr?rrrr<><00>s  zViewList.trim_startcCsV|t|j<01>kr&td|t|j<01>f<00><01>n|dkr6td<03><01>|j| d<04>=|j| d<04>=dS)zU
Remove items from the end of the list, without touching the parent.
zCSize of trim too large; can't trim %s items from a list of size %s.rzTrim size must be >= 0.N)r0r<>r=r<>)rr?rrr<00>trim_end<6E>szViewList.trim_endcCs|<00>|<01>}||=dS)N)r<>)rr<>r<>rrrres
zViewList.removecCs |j<00>|<01>S)N)r<><00>count)rr<>rrrr<>r<>zViewList.countcCs |j<00>|<01>S)N)r<>r<>)rr<>rrrr<>r<>zViewList.indexcCs|j<00><01>|j<02><01>d|_dS)N)r<><00>reverser<65>r<>)rrrrr<>
s

zViewList.reversecGsFtt|j|j<03><02>}|j|<01>dd<02>|D<00>|_dd<02>|D<00>|_d|_dS)NcSsg|] }|d<00>qS)rr)r<><00>entryrrrr<>sz!ViewList.sort.<locals>.<listcomp>cSsg|] }|d<00>qS)rr)r<>r<>rrrr<>s)r<00>zipr<70>r<><00>sortr<74>)rr.<00>tmprrrr<>s

z ViewList.sortcCsJy
|j|Stk
rD|t|j<03>kr>|j|dddfS<00>YnXdS)z%Return source & offset for index `i`.rrN)r<>r=r0r<>)rr<>rrrr&s 
z ViewList.infocCs|<00>|<01>dS)zReturn source for index `i`.r)r&)rr<>rrrr szViewList.sourcecCs|<00>|<01>dS)zReturn offset for index `i`.r)r&)rr<>rrrr6$szViewList.offsetcCs
d|_dS)z-Break link between this list and parent list.N)r<>)rrrr<00>
disconnect(szViewList.disconnectccs0x*t|j|j<02>D]\}\}}|||fVqWdS)z8Return iterator yielding (source, offset, value) tuples.N)r<>r<>r<>)rr_rr6rrr<00>xitems,szViewList.xitemscCs"x|<00><00>D]}td|<00>q
WdS)z=Print the list in `grep` format (`source:offset:value` lines)z%s:%d:%sN)r<>r )rrrrr<00>pprint1szViewList.pprint)NNNNN)Nr)Nr)r)r)r)+r*rgrhrirr<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<><00>__rmul__r<5F>r$rbrMr<>r<>r<>rer<>r<>r<>r<>r&rr6r<>r<>r<>rrrrr<>.sR
 




r<>c@sNeZdZdZdejfdd<04>Zddd<07>Zdd
d <0B>Zdd d <0A>Z dd<0F>Z
dd<11>Z d S)rz*A `ViewList` with string-specific methods.rcs*<00>fdd<02>|j||<03>D<00>|j||<03><dS)z<>
Trim `length` characters off the beginning of each item, in-place,
from index `start` to `end`. No whitespace-checking is done on the
trimmed text. Does not affect slice parent.
csg|]}|<01>d<00><00>qS)Nr)r<>r)<01>lengthrrr<>Asz(StringList.trim_left.<locals>.<listcomp>N)r<>)rr<>r<>r<>r)r<>r<00> trim_left;s
zStringList.trim_leftFcCsz|}t|j<01>}x^||krl|j|}|<05><02>s,P|rb|ddkrb|<00>|<03>\}}t|||<03>||d<00><03>|d7}qW|||<03>S)z<>
Return a contiguous block of text.
If `flush_left` is true, raise `UnexpectedIndentationError` if an
indented line is encountered before the text block ends (with a blank
line).
r<00> r)r0r<>r@r&rP)rr<>rQr<><00>lastrrr6rrrrODs



 zStringList.get_text_blockTNcCsJ|}|}|dk r|dkr|}|dk r,|d7}t|j<01>}x<>||kr<>|j|} | r<>| ddksr|dk r<>| d|<04><00><02>r<>||ko<>|j|d<00><02> }
P| <09><03>} | s<>|r<>d}
Pn0|dkr<>t| <09>t| <0B>} |dkr<>| }n
t|| <0C>}|d7}q8Wd}
|||<07>} |dk <09>r| <0A>r| jd|d<01>| jd<|<06>r:|<03>r:| j||dk d<05>| |<06>pDd|
fS)a<>
Extract and return a StringList of indented lines of text.
Collect all lines with indentation, determine the minimum indentation,
remove the minimum indentation from all indented lines (unless
`strip_indent` is false), and return them. All lines up to but not
including the first unindented line will be returned.
:Parameters:
- `start`: The index of the first line to examine.
- `until_blank`: Stop collecting at the first blank line if true.
- `strip_indent`: Strip common leading indent if true (default).
- `block_indent`: The indent of the entire block, if known.
- `first_indent`: The indent of the first line, if known.
:Return:
- a StringList of indented lines with mininum indent removed;
- the amount of the indent;
- a boolean: did the indented block finish with a blank line or EOF?
Nrrr<>)r<>)r0r<>r@<00>lstrip<69>minr<6E>)rr<>r<>r<>r<>r<>r<>r<>r<>rr<><00>strippedZ line_indentrRrrrr<>YsB



   zStringList.get_indentedc
s*|||<03>}|<04>x<>tt|j<02><01>D]<5D>}t<03>|j|<00>}y ||}Wn.tk
rn|t|j|<00>t|<08>7}YnXy ||}Wn.tk
r<EFBFBD>|t|j|<00>t|<08>7}YnX|j|||<04><00><06>|j|<} | r t<07>t| <09>t| <09><08><00><00><02>q W|<05>r&d<01>k<00>r |k<00>r&nn<16>fdd<03>|jD<00>|_|S)Nrcsg|]}|<01>d<00><00>qS)Nr)r<>r)r<>rrr<><00>sz+StringList.get_2D_block.<locals>.<listcomp>) r<>r0r<>rZcolumn_indicesr=<00>rstripr<70>r<>)
r<00>top<6F>leftZbottom<6F>rightr<74>rRr<><00>cirr)r<>r<00> get_2D_block<63>s$      "zStringList.get_2D_blockcCsxtj}xltt|j<04><01>D]Z}|j|}t|t<06>rg}x,|D]$}|<05>|<06>||<06>dkr8|<05>|<01>q8Wd<02>|<05>|j|<qWdS)z<>
Pad all double-width characters in self by appending `pad_char` to each.
For East Asian language support.
ZWFrKN) <09> unicodedata<74>east_asian_widthr<68>r0r<>rr<>rbr!)rZpad_charr<72>r<>r<00>new<65>charrrr<00>pad_double_width<74>s



 zStringList.pad_double_widthcCs4x.tt|j<02><01>D]}|j|<00>||<02>|j|<qWdS)z6Replace all occurrences of substring `old` with `new`.N)r<>r0r<><00>replace)r<00>oldr<64>r<>rrrr<><00>szStringList.replace)F)rFTNN)T) r*rgrhri<00>sys<79>maxsizer<65>rOr<>r<>r<>r<>rrrrr7s

;
rc@s eZdZdS)<02>StateMachineErrorN)r*rgrhrrrrr<><00>sr<>c@s eZdZdS)r<N)r*rgrhrrrrr<<00>sr<c@s eZdZdS)rZN)r*rgrhrrrrrZ<00>srZc@s eZdZdS)rtN)r*rgrhrrrrrt<00>srtc@s eZdZdS)rsN)r*rgrhrrrrrs<00>srsc@s eZdZdS)r|N)r*rgrhrrrrr|<00>sr|c@s eZdZdS)rN)r*rgrhrrrrr<00>src@s eZdZdS)rPN)r*rgrhrrrrrP<00>srPc@seZdZdZdS)r,z<>
Raise from within a transition method to switch to another transition.
Raise with one argument, the new transition name.
N)r*rgrhrirrrrr,<00>sr,c@seZdZdZdS)r/z<>
Raise from within a transition method to switch to another state.
Raise with one or two arguments: new state name, and an optional new
transition name.
N)r*rgrhrirrrrr/<00>sr/<00>Fz[ ]cs&|r|<03>d|<00>}<00>fdd<03>|<00><01>D<00>S)a<>
Return a list of one-line strings with tabs expanded, no newlines, and
trailing whitespace stripped.
Each tab is expanded with between 1 and `tab_width` spaces, so that the
next character's index becomes a multiple of `tab_width` (8 by default).
Parameters:
- `astring`: a multi-line string.
- `tab_width`: the number of columns between tab stops.
- `convert_whitespace`: convert form feeds and vertical tabs to spaces?
r<>csg|]}|<01><00><00><01><01><00>qSr)<02>
expandtabsr<EFBFBD>)r<><00>s)<01> tab_widthrrr<><00>sz string2lines.<locals>.<listcomp>)<02>sub<75>
splitlines)Zastringr<67>Zconvert_whitespace<63>
whitespacer)r<>r<00> string2lines<65>s r<>cCs>t<00><01>\}}}x|jr|j}qW|jj}|j||j|j|jfS)z<>
Return exception information:
- the exception's class name;
- the exception object;
- the name of the file containing the offending code;
- the line number of the offending code;
- the function name of the offending code.
) r<><00>exc_info<66>tb_next<78>tb_frame<6D>f_coder*<00> co_filename<6D> tb_lineno<6E>co_name)r^r_<00> traceback<63>coderrrr]<00>s

r])!riZ __docformat__r<5F>rz<00>typesr<73>ZdocutilsrZdocutils.utils.error_reportingrrrjr<>r<>r<>r<>r<>r<>r<00> Exceptionr<6E>r<rZrtrsr|rrPr,r/r{r<>r]rrrr<00><module>isL  g