B “äî\áã@sŽdZdZddlZddlZddlZddlZddlmZddlm Z Gdd„dƒZ Gdd „d ƒZ Gd d „d e ƒZ Gd d „d e ƒZ Gdd„dƒZGdd„dee ƒZGdd„dee ƒZGdd„dƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGd d!„d!eƒZGd"d#„d#eƒZGd$d%„d%eƒZGd&d'„d'eƒZGd(d)„d)eƒZGd*d+„d+eƒZd,d-e d.¡fd/d0„Zd1d2„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éN)Úutils)Ú ErrorOutputc@sàeZdZdZd6dd„Zdd„Zd7d d „Zd8d d „Zd9dd„Zdd„Z dd„Z dd„Z d:dd„Z dd„Z dd„Zdd„Zdd„Zd;d d!„Zd"d#„ZdÚ StateMachinea´ 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|_| |¡g|_ t ƒ|_ 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éÿÿÿÿ) Ú input_linesÚ input_offsetÚlineÚ line_offsetÚdebugÚ initial_stateÚ current_stateÚstatesÚ add_statesÚ observersrÚ_stderr)ÚselfÚ state_classesr r ©rú9/tmp/pip-build-uw_ogi45/docutils/docutils/statemachine.pyÚ__init__ƒs  zStateMachine.__init__cCs*xt|j ¡ƒD] }| ¡qWd|_dS)z9Remove circular references to objects no longer required.N)Úlistr ÚvaluesÚunlink)rÚstaterrrr²s zStateMachine.unlinkrNc Csn| ¡t|tƒr||_nt||d|_||_d|_|p<|j|_|jrft d|jd  |j¡f|j dd}g}|  ¡}yÌ|jrŽt d|j d|  |¡\}} | | ¡x˜y¬yR| ¡|jrè|j |j¡\} } t d| | |jf|j d| |||¡\}} } WnJtk rH|jr.t d |jj|j d| |¡} | | ¡PYn X| | ¡WnØtk r¶} z@| ¡| jd f}|jr¤t d |jj|d f|j dwªWdd} ~ XYn~tk r.} zZ| ¡| jd } t| jƒd krðd}n | jd f}|jrt d | |d f|j dWdd} ~ XYnXd}|  | ¡}qªWWn|jr\| ¡‚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. )Úsourcerz5 StateMachine.run: input_lines (line_offset=%s): | %sz | )Ú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.éz@ StateMachine.run: StateCorrection to state "%s", transition %s.)Ú runtime_initÚ isinstanceÚ StringListrrr r r r ÚprintÚjoinrÚ get_stateÚbofÚextendÚ next_lineÚinforÚ check_lineÚEOFErrorÚ __class__Ú__name__ÚeofÚTransitionCorrectionÚ previous_lineÚargsÚStateCorrectionÚlenÚerrorr)rrrÚcontextZ input_sourcer Ú transitionsÚresultsrÚresultrÚoffsetÚ next_stateÚ exceptionrrrÚrun¸s„         (zStateMachine.runcCsh|r8|jr2||jkr2td|j|| ¡f|jd||_y |j|jStk rbt|jƒ‚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 Úabs_line_numberrr ÚKeyErrorÚUnknownStateError)rr7rrrr"s zStateMachine.get_statercCsVzFy |j|7_|j|j|_Wntk r@d|_t‚YnX|jS| ¡XdS)z9Load `self.line` with the `n`'th next line and return it.N)r rrÚ IndexErrorr(Únotify_observers)rÚnrrrr%.s zStateMachine.next_linecCs0y|j|jd ¡ Stk r*dSXdS)z3Return 1 if the next line is blank or non-existant.rN)rr Ústripr=)rrrrÚis_next_line_blank;szStateMachine.is_next_line_blankcCs|jt|jƒdkS)z0Return 1 if the input is at or past end-of-file.r)r r0r)rrrrÚat_eofBszStateMachine.at_eofcCs |jdkS)z8Return 1 if the input is at or before beginning-of-file.r)r )rrrrÚat_bofFszStateMachine.at_bofcCs<|j|8_|jdkr d|_n|j|j|_| ¡|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‚YnX|jS| ¡XdS)z?Jump to absolute line offset `line_offset`, load and return it.N)rr rrr=r(r>)rr rrrÚ goto_lineTs  zStateMachine.goto_linecCs|j ||j¡S)zs   zStateMachine.notify_observers)F)rNNN)N)r)r)N)F)N)r*Ú __module__Ú __qualname__Ú__doc__rrr9r"r%rArBrCr-rDrErFr:rHrNrOr'r\rrr1rdrfr>rrrrrus4  / `       , rc@sŒeZdZdZdZdZdZdZddd„Zdd„Z dd „Z d d „Z d d „Z dd„Z dd„Zddd„Zdd„Zdd„Zdd„Zdd„Zdd„ZdS) Ú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|_| ¡||_||_|jdkr4|jj|_|jdkrR|jg|jjdœ|_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Úadd_initial_transitionsÚ state_machiner Ú nested_smr)Ú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)rrrrrsz State.unlinkcCs&|jr"| |j¡\}}| ||¡dS)z>Make and add transitions listed in `self.initial_transitions`.N)Úinitial_transitionsÚmake_transitionsÚadd_transitions)rÚnamesr3rrrrk…s zState.add_initial_transitionscCsNx.|D]&}||jkrt|ƒ‚||krt|ƒ‚qW||jdd…<|j |¡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ÚDuplicateTransitionErrorÚUnknownTransitionErrorrTÚupdate)rrrr3rWrrrrqŒs   zState.add_transitionscCs0||jkrt|ƒ‚|g|jdd…<||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Úadd_transitionŸs zState.add_transitioncCs2y|j|=|j |¡Wnt|ƒ‚YnXdS)z^ Remove a transition by `name`. Exception: `UnknownTransitionError`. N)r3rTrert)rrWrrrÚremove_transition¬s zState.remove_transitioncCsž|dkr|jj}y"|j|}t|dƒs0t |¡}Wn(tk rZtd|jj|fƒ‚YnXyt||ƒ}Wn(t k r’t d|jj|fƒ‚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*ÚpatternsÚhasattrÚreÚcompiler;ÚTransitionPatternNotFoundÚgetattrÚAttributeErrorÚTransitionMethodNotFound)rrWr7rXrYrrrÚmake_transition¸s  zState.make_transitioncCsltdƒ}g}i}xR|D]J}t|ƒ|kr@| |¡||<| |¡q|j|Ž||d<| |d¡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)rZ name_listZ stringtyperrr3Z namestaterrrrpÙ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í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#û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Únopsz State.nop)F)N)r*rgrhrirxrormrnrrrrkrqrvrwr€rprVr#r+rrrrrrj s$' $  !  rjc@s.eZdZdZd dd„Zd dd„Zd dd „Zd S)Ú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| ¡}|j |j||¡\}}}|r6| t|ƒd¡x$|rZ|d ¡sZ| ¡|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Ú get_indentedr r%r0r@Ú trim_start)rÚ until_blankÚ strip_indentr6ÚindentedÚindentÚ blank_finishrrrrƒ&s zStateMachineWS.get_indentedcCsf| ¡}|jj|j|||d\}}}| t|ƒd¡x$|rZ|d ¡sZ| ¡|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. )Ú block_indentrr)rFrrƒr r%r0r@r„)rrˆr…r†r6r‡r‰rrrÚget_known_indented@s z!StateMachineWS.get_known_indentedcCsl| ¡}|jj|j|||d\}}}| t|ƒd¡|r`x$|r^|d ¡s^| ¡|d7}qd?„Z!d@dA„Z"dBdC„Z#dDdE„Z$dFdG„Z%dHdI„Z&dJdK„Z'dLdM„Z(dNdO„Z)dPdQ„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ƒrD|jdd…|_|jdd…|_n:|dk r~t|ƒ|_|rb||_n‡fdd„tt|ƒƒDƒ|_t|jƒt|jƒksšt dƒ‚dS)Ncsg|] }ˆ|f‘qSrr)Ú.0Úi)rrrú Zsz%ViewList.__init__..z data mismatch) ÚdataÚitemsÚparentÚ parent_offsetrržrÚranger0ÚAssertionError)rÚinitlistrr£r¤r¥r)rrrBs  zViewList.__init__cCs t|jƒS)N)Ústrr¢)rrrrÚ__str__]szViewList.__str__cCsd|jj|j|jfS)Nz%s(%s, items=%s))r)r*r¢r£)rrrrÚ__repr__`szViewList.__repr__cCs|j| |¡kS)N)r¢Ú_ViewList__cast)rÚotherrrrÚ__lt__dózViewList.__lt__cCs|j| |¡kS)N)r¢r¬)rr­rrrÚ__le__er¯zViewList.__le__cCs|j| |¡kS)N)r¢r¬)rr­rrrÚ__eq__fr¯zViewList.__eq__cCs|j| |¡kS)N)r¢r¬)rr­rrrÚ__ne__gr¯zViewList.__ne__cCs|j| |¡kS)N)r¢r¬)rr­rrrÚ__gt__hr¯zViewList.__gt__cCs|j| |¡kS)N)r¢r¬)rr­rrrÚ__ge__ir¯zViewList.__ge__cCst|j| |¡ƒS)N)Úcmpr¢r¬)rr­rrrÚ__cmp__jr¯zViewList.__cmp__cCst|tƒr|jS|SdS)N)rržr¢)rr­rrrÚ__castls zViewList.__castcCs ||jkS)N)r¢)rÚitemrrrÚ __contains__rr¯zViewList.__contains__cCs t|jƒS)N)r0r¢)rrrrÚ__len__sr¯zViewList.__len__cCs^t|tƒrP|jdkstdƒ‚|j|j|j|j…|j|j|j…||jpJddS|j|SdS)N)Nrzcannot handle slice with strider)r£r¤r¥) rÚsliceÚstepr§r)r¢ÚstartÚstopr£)rr rrrÚ __getitem__ys  zViewList.__getitem__cCsÈt|tƒr¤|jdkstdƒ‚t|tƒs.tdƒ‚|j|j|j|j…<|j |j |j|j…<t |jƒt |j ƒksrtdƒ‚|j rÄ||j |jp†d|j |jp˜t |ƒ|j …<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Ú __setitem__‚s  , zViewList.__setitem__cCs¢y(|j|=|j|=|jr&|j||j=Wnttk rœ|jdksJtdƒ‚|j|j|j…=|j|j|j…=|jr˜|j|jp|d|j|jpŽt |ƒ|j…=YnXdS)Nzcannot handle slice with strider) r¢r£r¤r¥rGr¼r§r½r¾r0)rr rrrÚ __delitem__’szViewList.__delitem__cCs4t|tƒr(|j|j|j|j|jdStdƒ‚dS)N)r£z!adding non-ViewList to a ViewList)rržr)r¢r£rG)rr­rrrÚ__add__ s zViewList.__add__cCs4t|tƒr(|j|j|j|j|jdStdƒ‚dS)N)r£z!adding ViewList to a non-ViewList)rržr)r¢r£rG)rr­rrrÚ__radd__§s zViewList.__radd__cCs(t|tƒr|j|j7_ntdƒ‚|S)Nz!argument to += must be a ViewList)rržr¢rG)rr­rrrÚ__iadd__®s zViewList.__iadd__cCs|j|j||j|dS)N)r£)r)r¢r£)rr?rrrÚ__mul__µszViewList.__mul__cCs |j|9_|j|9_|S)N)r¢r£)rr?rrrÚ__imul__ºszViewList.__imul__cCsRt|tƒstdƒ‚|jr2|j t|jƒ|j|¡|j |j¡|j  |j ¡dS)Nz(extending a ViewList with a non-ViewList) rržrGr¤rMr0r¢r¥r$r£)rr­rrrr$¿s  zViewList.extendrcCsX|dkr| |¡n@|jr8|j t|jƒ|j|||¡|j |¡|j ||f¡dS)N)r$r¤rMr0r¢r¥rbr£)rr¸rr6rrrrbÇs  zViewList.appendcCsÈ|dkrnt|tƒstdƒ‚|j|j||…<|j|j||…<|jrÄt|jƒ|t|jƒ}|j ||j|¡nV|j ||¡|j |||f¡|jrÄt|jƒ|t|jƒ}|j ||j|||¡dS)Nz+inserting non-ViewList with no source given) rržrGr¢r£r¤r0rMr¥)rr r¸rr6ÚindexrrrrMÑs zViewList.insertrcCsH|jr0t|jƒ|t|jƒ}|j ||j¡|j |¡|j |¡S)N)r¤r0r¢Úpopr¥r£)rr rÇrrrrÈâs  z ViewList.poprcCsf|t|jƒkr&td|t|jƒfƒ‚n|dkr6tdƒ‚|jd|…=|jd|…=|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„és  zViewList.trim_startcCsV|t|jƒkr&td|t|jƒfƒ‚n|dkr6tdƒ‚|j| d…=|j| d…=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Útrim_end÷szViewList.trim_endcCs| |¡}||=dS)N)rÇ)rr¸rÇrrrres zViewList.removecCs |j |¡S)N)r¢Úcount)rr¸rrrrÊr¯zViewList.countcCs |j |¡S)N)r¢rÇ)rr¸rrrrÇr¯zViewList.indexcCs|j ¡|j ¡d|_dS)N)r¢Úreverser£r¤)rrrrrË s  zViewList.reversecGsFtt|j|jƒƒ}|j|Ždd„|Dƒ|_dd„|Dƒ|_d|_dS)NcSsg|] }|d‘qS)rr)rŸÚentryrrrr¡sz!ViewList.sort..cSsg|] }|d‘qS)rr)rŸrÌrrrr¡s)rÚzipr¢r£Úsortr¤)rr.ÚtmprrrrÎs  z ViewList.sortcCsJy |j|Stk rD|t|jƒkr>|j|dddfS‚YnXdS)z%Return source & offset for index `i`.rrN)r£r=r0r¢)rr rrrr&s  z ViewList.infocCs| |¡dS)zReturn source for index `i`.r)r&)rr rrrr szViewList.sourcecCs| |¡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Ú disconnect(szViewList.disconnectccs0x*t|j|jƒD]\}\}}|||fVqWdS)z8Return iterator yielding (source, offset, value) tuples.N)rÍr¢r£)rr_rr6rrrÚxitems,szViewList.xitemscCs"x| ¡D]}td|ƒq WdS)z=Print the list in `grep` format (`source:offset:value` lines)z%s:%d:%sN)rÑr )rrrrrÚ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ÅÚ__rmul__rÆr$rbrMrÈr„rÉrerÊrÇrËrÎr&rr6rÐrÑrÒrrrrrž.sR       ržc@sNeZdZdZdejfdd„Zddd„Zdd d „Zdd d „Z dd„Z dd„Z d S)rz*A `ViewList` with string-specific methods.rcs*‡fdd„|j||…Dƒ|j||…<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|]}|ˆd…‘qS)Nr)rŸr)Úlengthrrr¡Asz(StringList.trim_left..N)r¢)rrÔr½r—r)rÔrÚ trim_left;s zStringList.trim_leftFcCsz|}t|jƒ}x^||krl|j|}| ¡s,P|rb|ddkrb| |¡\}}t|||…||dƒ‚|d7}qW|||…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ú r)r0r¢r@r&rP)rr½rQr—Úlastrrr6rrrrODs     zStringList.get_text_blockTNcCsJ|}|}|dk r|dkr|}|dk r,|d7}t|jƒ}x°||krâ|j|} | r| ddksr|dk r| d|… ¡r||koŒ|j|d ¡ } P|  ¡} | s¨|rØd} Pn0|dkrØt| ƒt| ƒ} |dkrÎ| }n t|| ƒ}|d7}q8Wd} |||…} |dk r| r| jd|d…| jd<|r:|r:| j||dk d| |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@ÚlstripÚminrÕ)rr½r…r†rŠrŒrˆr—r×rr‰ÚstrippedZ line_indentrRrrrrƒYsB       zStringList.get_indentedc s*|||…}|‰xÜtt|jƒƒD]Ê}t |j|¡}y ||}Wn.tk rn|t|j|ƒt|ƒ7}YnXy ||}Wn.tk rª|t|j|ƒt|ƒ7}YnX|j|||… ¡|j|<} | r tˆt| ƒt|  ¡ƒƒ‰q W|r&dˆkr |kr&nn‡fdd„|jDƒ|_|S)Nrcsg|]}|ˆd…‘qS)Nr)rŸr)rˆrrr¡§sz+StringList.get_2D_block..) r¦r0r¢rZcolumn_indicesr=ÚrstriprÙrØ) rÚtopÚleftZbottomÚrightr†rRr Zcirr)rˆrÚ get_2D_block•s$      "zStringList.get_2D_blockcCsˆttdƒrtj}ndSxltt|jƒƒD]Z}|j|}t|tƒr&g}x,|D]$}| |¡||ƒdkrH| |¡qHWd  |¡|j|<q&WdS)zƒ Pad all double-width characters in self by appending `pad_char` to each. For East Asian language support. Úeast_asian_widthNZWFrK) ryÚ unicodedataràr¦r0r¢rr©rbr!)rZpad_charràr rÚnewÚcharrrrÚpad_double_widthªs      zStringList.pad_double_widthcCs4x.tt|jƒƒD]}|j| ||¡|j|<qWdS)z6Replace all occurrences of substring `old` with `new`.N)r¦r0r¢Úreplace)rÚoldrâr rrrrå½szStringList.replace)F)rFTNN)T) r*rgrhriÚsysÚmaxsizerÕrOrƒrßrärårrrrr7s  ; rc@s eZdZdS)ÚStateMachineErrorN)r*rgrhrrrrréÃsréc@s eZdZdS)r<N)r*rgrhrrrrr<Äsr<c@s eZdZdS)rZN)r*rgrhrrrrrZÅsrZc@s eZdZdS)rtN)r*rgrhrrrrrtÆsrtc@s eZdZdS)rsN)r*rgrhrrrrrsÇsrsc@s eZdZdS)r|N)r*rgrhrrrrr|Èsr|c@s eZdZdS)rN)r*rgrhrrrrrÉsrc@s eZdZdS)rPN)r*rgrhrrrrrPÊ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,Í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/Ösr/éFz[ ]cs&|r| d|¡}‡fdd„| ¡Dƒ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|]}| ˆ¡ ¡‘qSr)Ú expandtabsrÛ)rŸÚs)Ú tab_widthrrr¡ñsz string2lines..)ÚsubÚ splitlines)ZastringríZconvert_whitespaceÚ whitespacer)rírÚ string2linesàs rñcCs>t ¡\}}}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çÚexc_infoÚtb_nextÚtb_frameÚf_coder*Ú co_filenameÚ tb_linenoÚco_name)r^r_Ú tracebackÚcoderrrr]ós  r])!riZ __docformat__rçrzÚtypesráZdocutilsrZdocutils.utils.error_reportingrrrjr‚rŽršrœrržrÚ Exceptionrér<rZrtrsr|rrPr,r/r{rñr]rrrrÚisL  g