V!\c@s dZdZddlZddlZddlZddlZddlmZddlm Z dfdYZ dfd YZ d e fd YZ d e fd YZ dfdYZdee fdYZdee fdYZdfdYZdefdYZdefdYZdefdYZdefdYZdefdYZd efd!YZd"efd#YZd$efd%YZd&efd'YZd(efd)YZd*efd+YZd,eejd-d.Z d/Z!dS(0s 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() trestructuredtextiN(tutils(t ErrorOutputt StateMachinecBseZdZedZdZdddddZddZddZ dZ d Z d Z dd Z d Zd ZdZdZddZdZedZddZdZdZdZdZdZdZdZRS(s 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. cCsnd|_d|_d|_d|_||_||_||_i|_|j |g|_ t |_ dS(s+ 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). iiN( tNonet input_linest input_offsettlinet line_offsettdebugt initial_statet current_statetstatest add_statest observersRt_stderr(tselft state_classesR R ((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt__init__s           cCs1x!|jjD]}|jqWd|_dS(s9Remove circular references to objects no longer required.N(R tvaluestunlinkR(Rtstate((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRsicCs|jt|tr%||_nt|d||_||_d|_|pX|j|_|jr|j d|jdj |jfIJnd }g}|j }y|jr|j dIJn|j |\}} |j| xtryyp|j|jrC|jj|j\} } |j d| | |jfIJn|j|||\}} } WnQtk r|jr|j d|jjIJn|j|} |j| PnX|j| Wntk r#} |j| jdf}|jr|j d |jj|dfIJqqntk r} |j| jd} t| jd krgd }n| jd f}|jr|j d | |dfIJqnXd }|j | }qWWn |jr|jnnXg|_|S( s 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. tsourceiu5 StateMachine.run: input_lines (line_offset=%s): | %su | s! StateMachine.run: bof transitionu4 StateMachine.run: line (source=%r, offset=%r): | %ss$ StateMachine.run: %s.eof transitionisE StateMachine.run: TransitionCorrection to state "%s", transition %s.is@ StateMachine.run: StateCorrection to state "%s", transition %s.N(t runtime_initt isinstancet StringListRRRR R R RtjoinRt get_statetboftextendtTruet next_linetinfoRt check_linetEOFErrort __class__t__name__teoftTransitionCorrectiont previous_linetargstStateCorrectiontlenterrorR(RRRtcontextt input_sourceR t transitionstresultsRtresultRtoffsett next_statet exception((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pytruns                        cCs|rP|jrD||jkrD|jd|j||jfIJn||_ny|j|jSWn tk rt|jnXdS(s 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. sJ StateMachine.get_state: Changing state from "%s" to "%s" (input line %s).N(R R Rtabs_line_numberR tKeyErrortUnknownStateError(RR2((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRs   icCsfzTy&|j|7_|j|j|_Wn tk rKd|_tnX|jSWd|jXdS(s9Load `self.line` with the `n`'th next line and return it.N(RRRt IndexErrorRR"tnotify_observers(Rtn((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyR.s    cCs6y|j|jdj SWntk r1dSXdS(s3Return 1 if the next line is blank or non-existant.iN(RRtstripR8(R((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pytis_next_line_blank;s cCs|jt|jdkS(s0Return 1 if the input is at or past end-of-file.i(RR*R(R((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pytat_eofBscCs |jdkS(s8Return 1 if the input is at or before beginning-of-file.i(R(R((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pytat_bofFscCsN|j|8_|jdkr*d|_n|j|j|_|j|jS(s=Load `self.line` with the `n`'th previous line and return it.iN(RRRRR9(RR:((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyR'Js   cCsgzUy'||j|_|j|j|_Wn tk rLd|_tnX|jSWd|jXdS(s?Jump to absolute line offset `line_offset`, load and return it.N(RRRRR8RR"R9(RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt goto_lineTs    cCs|jj||jS(s<Return source of line at absolute line offset `line_offset`.(RRR(RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt get_sourceascCs|j|jS(s;Return line offset of current line, from beginning of file.(RR(R((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pytabs_line_offsetescCs|j|jdS(s5Return line number of current line (counting from 1).i(RR(R((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyR5iscCs|dkr|j}n||jd}y&|jj|\}}|d}WnTtk r|j||j\}}||dfStk rd\}}nX||fS(s\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. iN(NN(RRRRR t TypeErrortget_source_and_lineR8(RtlinenoR1tsrct srcoffsettsrcline((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRCms    cCs|jj|jdddd|dt||jj|jdddd|dd|jj|jdt||dS( NitRsinternal padding after R1sinternal padding before ii(RtinsertRR*R(RRR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt insert_inputs   cCsxy7|jj|j|}|jt|d|SWn:tk rs}|jd}|jt|dnXdS(s 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). iiN(Rtget_text_blockRRR*tUnexpectedIndentationErrorR((Rt flush_lefttblockterr((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRKs  c Cs|dkr|j}nd}|jrG|jd|jj|fIJnx|D]m}|j|\}}}|j|j} | rN|jr|jd||jjfIJn|| ||SqNW|jr|jd|jjIJn|j ||SdS(s 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. s5 StateMachine.check_line: state="%s", transitions=%r.s@ StateMachine.check_line: Matched transition "%s" in state "%s".s1 StateMachine.check_line: No match in state "%s".N( Rttransition_orderR RR#R$R.tmatchRtno_match( RR,RR.tstate_correctiontnametpatterntmethodR2RQ((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyR!s*      cCsD|j}||jkr't|n|||j|j|R'R?R@RAR5RCRJRKR!RZR RR+RbRdR9(((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRus4  / `          ,     tStatecBseZdZdZdZdZdZedZ dZ dZ dZ dZ dZdZddZd Zd Zd Zd Zd ZRS(sv 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. cCsg|_i|_|j||_||_|jdkrO|jj|_n|jdkri|jgd6|jj d6|_ndS(s Initialize a `State` object; make & add initial transitions. Parameters: - `statemachine`: the controlling `StateMachine` object. - `debug`: a boolean; produce verbose output if true. RR N( RPR.tadd_initial_transitionst state_machineR t nested_smRR#tnested_sm_kwargsR$(RRjR ((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRVs    cCsdS(s{ Initialize this `State` before running the state machine; called from `self.state_machine.run()`. N((R((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRzscCs d|_dS(s9Remove circular references to objects no longer required.N(RRj(R((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRscCs8|jr4|j|j\}}|j||ndS(s>Make and add transitions listed in `self.initial_transitions`.N(tinitial_transitionstmake_transitionstadd_transitions(RtnamesR.((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRis cCskxG|D]?}||jkr+t|n||krt|qqW||jd*|jj|dS(s" 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`. iN(R.tDuplicateTransitionErrortUnknownTransitionErrorRPtupdate(RRpR.RT((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRos   cCs?||jkrt|n|g|jd*||j|eZdZeedZeedZeeedZRS(sq `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. cCs|j}|jj|j||\}}}|rP|jt|dnx/|r|dj r|j|d7}qSW||||fS(s 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. ii(RARt get_indentedRRR*R;t trim_start(Rt until_blankt strip_indentR1tindentedtindentt blank_finish((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyR&s   cCs|j}|jj|j||d|\}}}|jt|dx/|r~|dj r~|j|d7}qPW|||fS(s 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. t block_indentii(RARRRRR*R;R(RRRRR1RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pytget_known_indented@s   cCs|j}|jj|j||d|\}}}|jt|d|rx2|r|dj r|j|d7}qVWn||||fS(s 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. t first_indentii(RARRRRR*R;R(RRRRt strip_topR1RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pytget_first_known_indented^s   (R$ReRfRgRRRR(((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRs  tStateWScBsyeZdZd Zd Zd Zd Zidd6dd6Zd Z e dZ dZ dZ dZd Zd ZRS( s 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. s *$tblanks +RcCstj||||jdkr1|j|_n|jdkrO|j|_n|jdkrm|j|_n|jdkr|j|_ndS(s Initialize a `StateSM` object; extends `State.__init__()`. Check for indent state machine attributes, set defaults if not set. N( RhRt indent_smRRktindent_sm_kwargsRltknown_indent_smtknown_indent_sm_kwargs(RRjR ((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRscCsgtj||jdkr(i|_n|jj|j|j|j\}}|j||dS(s Add whitespace-specific transitions before those defined in subclass. Extends `State.add_initial_transitions()`. N( RhRiRwRRst ws_patternsRntws_initial_transitionsRo(RRpR.((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRis  cCs|j|||S(s9Handle blank lines. Does nothing. Override in subclasses.(R(RRQR,R2((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRsc CsX|jj\}}}}|jd|j|j}|j|d|} ||| fS(s Handle an indented text block. Extend or override in subclasses. Recursively run the registered state machine for indented blocks (`self.indent_sm`). R R(RjRRR RR4( RRQR,R2RRRRtsmR/((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRsc Cs^|jj|j\}}}|jd|j|j}|j|d|}|||fS(s 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(RjRtendRR RR4( RRQR,R2RRRRR/((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt known_indents ! c Cs^|jj|j\}}}|jd|j|j}|j|d|}|||fS(s0 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(RjRRRR RR4( RRQR,R2RRRRR/((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pytfirst_known_indents ! N(sblanksindent(R$ReRfRRRRRRRRgRRiRRRR(((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRs      t_SearchOverridecBseZdZdZRS(s 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|j|jS(s Return the result of a regular expression search. Overrides `StateMachine.match()`. Parameter `pattern`: `re` compiled regular expression. (tsearchR(RRU((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRQs(R$ReRfRQ(((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyR s tSearchStateMachinecBseZdZRS(s@`StateMachine` which uses `re.search()` instead of `re.match()`.(R$ReRf(((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyR$stSearchStateMachineWScBseZdZRS(sB`StateMachineWS` which uses `re.search()` instead of `re.match()`.(R$ReRf(((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyR)stViewListcBseZdZd*d*d*d*d*dZdZdZdZdZdZ dZ dZ d Z d Z d Zd Zd ZdZdZdZdZdZdZdZeZdZdZd*ddZd*ddZddZddZddZdZ d Z!d!Z"d"Z#d#Z$d$Z%d%Z&d&Z'd'Z(d(Z)d)Z*RS(+s> 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. cCsg|_g|_||_||_t|trP|j|_|j|_n^|dk rt||_|r}||_qgtt |D]}||f^q|_nt |jt |jkst ddS(Ns data mismatch( tdatatitemstparentt parent_offsetRRRtlisttrangeR*tAssertionError(RtinitlistRRRRti((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRBs       1cCs t|jS(N(tstrR(R((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt__str__]scCsd|jj|j|jfS(Ns%s(%s, items=%s)(R#R$RR(R((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt__repr__`s cCs|j|j|kS(N(Rt_ViewList__cast(Rtother((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt__lt__dscCs|j|j|kS(N(RR(RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt__le__escCs|j|j|kS(N(RR(RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt__eq__fscCs|j|j|kS(N(RR(RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt__ne__gscCs|j|j|kS(N(RR(RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt__gt__hscCs|j|j|kS(N(RR(RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt__ge__iscCst|j|j|S(N(tcmpRR(RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt__cmp__jscCst|tr|jS|SdS(N(RRR(RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt__castlscCs ||jkS(N(R(Rtitem((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt __contains__rscCs t|jS(N(R*R(R((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt__len__sscCst|tjru|jdks-td|j|j|j|j !d|j |j|j !d|d|jpqdS|j|SdS(Niscannot handle slice with strideRRRi(Ni( Rttypest SliceTypetstepRRR#RtstarttstopR(RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt __getitem__ys cCst|tjr|jdks-tdt|tsKtdn|j|j|j |j +|j |j |j |j +t |jt |j kstd|j r||j |j pd|j|j pt ||j+qn-||j|<|j r||j ||j= 0.N(R*RR8RRR(RR:((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRs    cCsl|t|jkr7td|t|jfn|dkrRtdn|j| 3|j| 3dS(sU Remove items from the end of the list, without touching the parent. sCSize of trim too large; can't trim %s items from a list of size %s.isTrim size must be >= 0.N(R*RR8R(RR:((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyttrim_ends  cCs|j|}||=dS(N(R(RRR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRcscCs|jj|S(N(Rtcount(RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRscCs|jj|S(N(RR(RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRscCs'|jj|jjd|_dS(N(RtreverseRRR(R((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyR s  cGsot|j|j}|j|g|D]}|d^q)|_g|D]}|d^qI|_d|_dS(Nii(tzipRRtsortRR(RR(ttmptentry((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRs    cCsXy|j|SWnBtk rS|t|jkrM|j|dddfSnXdS(s%Return source & offset for index `i`.iiN(RR8R*RR(RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyR s  cCs|j|dS(sReturn source for index `i`.i(R (RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyR scCs|j|dS(sReturn offset for index `i`.i(R (RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyR1$scCs d|_dS(s-Break link between this list and parent list.N(RR(R((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt disconnect(sccs>x7t|j|jD] \}\}}|||fVqWdS(s8Return iterator yielding (source, offset, value) tuples.N(RRR(RR]RR1((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pytxitems,s(cCs$x|jD]}d|GHq WdS(s=Print the list in `grep` format (`source:offset:value` lines)s%s:%d:%sN(R(RR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pytpprint1sN(+R$ReRfRRRRRRRRRRRRRRRRRRRRRt__rmul__RRR`RIRRRRcRRRRR RR1RRR(((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyR.sR                                 RcBsbeZdZdejdZedZdeedddZ edZ dZ dZ RS( s*A `ViewList` with string-specific methods.icCs5g|j||!D]}||^q|j||+dS(s 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. N(R(RtlengthRRR((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyt trim_left;scCs|}t|j}x||kr|j|}|jsAPn|r|ddkr|j|\}}t|||!||dn|d7}qW|||!S(s 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). it i(R*RR;R RL(RRRMRtlastRRR1((s9/tmp/pip-install-usGedi/docutils/docutils/statemachine.pyRKDs  cCs|}|}|dk r-|dkr-|}n|dk rF|d7}nt|j}x||krF|j|} | r| ddks|dk r| | jr||ko|j|dj } Pn| j} | s|r9d} Pq9nI|dkr9t| t| } |dkr'| }q9t|| }n|d7}qXWd} |||!} |dk r| r| jd|| jdis@    g