B Ðñ¢d?áã@s¨dZddlmZdZddlZddlZddlZddlmZddl m Z ej dkrRe Z Gdd „d eƒZGd d „d eƒZGd d „d eƒZGdd„deƒZGdd„deƒZGdd„deeƒZGdd„deeƒ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ƒZ Gd*d+„d+eƒZ!Gd,d-„d-eƒZ"d.d/e #d0¡fd1d2„Z$d3d4„Z%dS)5a 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() é)Úprint_functionÚrestructuredtextN)Úutils)Ú ErrorOutput)érc@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_classesrr ©rúszStateMachine.is_next_line_blankcCs|jt|jƒdkS)z0Return 1 if the input is at or past end-of-file.r)r r2r )rrrrÚat_eofEszStateMachine.at_eofcCs |jdkS)z8Return 1 if the input is at or before beginning-of-file.r)r )rrrrÚat_bofIszStateMachine.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 r r r@)rrArrrr/Ms  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)r r r r r?r*r@)rr rrrÚ goto_lineWs  zStateMachine.goto_linecCs|j ||j¡S)zMake and add transitions listed in `self.initial_transitions`.N)Úinitial_transitionsÚmake_transitionsÚadd_transitions)rÚnamesr5rrrrm„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)r5ÚDuplicateTransitionErrorÚUnknownTransitionErrorrVÚupdate)rrtr5rYrrrrs‹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)r5rurV)rrYZ transitionrrrÚadd_transitionžs zState.add_transitioncCs2y|j|=|j |¡Wnt|ƒ‚YnXdS)z^ Remove a transition by `name`. Exception: `UnknownTransitionError`. N)r5rVrgrv)rrYrrrÚremove_transition«s zState.remove_transitioncCs¨|dkr|jj}y,|j|}t|dƒs:t |¡}|j|<Wn(tk rdtd|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`. NrWz%s.patterns[%r]z%s.%s) r+r,ÚpatternsÚhasattrÚreÚcompiler=ÚTransitionPatternNotFoundÚgetattrÚAttributeErrorÚTransitionMethodNotFound)rrYr9rZr[rrrÚmake_transition·s  zState.make_transitioncCsjtdƒ}g}i}xP|D]H}t||ƒr>| |¡||<| |¡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). rMr)r`r r‚rd)rÚ name_listZ stringtypertr5Z namestaterrrrrØ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)rr4r5rrrrXìs zState.no_matchcCs|gfS)z± Handle beginning-of-file. Return unchanged `context`, empty result. Override in subclasses. Parameter `context`: application-defined storage. r)rr4rrrr%úsz State.bofcCsgS)z– Handle end-of-file. Return empty result. Override in subclasses. Parameter `context`: application-defined storage. r)rr4rrrr-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)rrWr4r9rrrÚnopsz State.nop)F)N)r,rirjrkrzrqrorprrrrmrsrxryr‚rrrXr%r-r„rrrrrls$' $  !  rlc@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)rHr Ú get_indentedr r'r2rBÚ trim_start)rÚ until_blankÚ strip_indentr8Ú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)rHr r†r r'r2rBr‡)rr‹rˆr‰r8rŠ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ú Ysz%ViewList.__init__..z data mismatch) ÚdataÚitemsÚparentÚ parent_offsetr r¡ÚlistÚranger2ÚAssertionError)rÚinitlistrr¦r§r¨r)rrrAs  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__cózViewList.__lt__cCs|j| |¡kS)N)r¥r°)rr±rrrÚ__le__dr³zViewList.__le__cCs|j| |¡kS)N)r¥r°)rr±rrrÚ__eq__er³zViewList.__eq__cCs|j| |¡kS)N)r¥r°)rr±rrrÚ__ne__fr³zViewList.__ne__cCs|j| |¡kS)N)r¥r°)rr±rrrÚ__gt__gr³zViewList.__gt__cCs|j| |¡kS)N)r¥r°)rr±rrrÚ__ge__hr³zViewList.__ge__cCs |j}| |¡}||k||kS)N)r¥r°)rr±ZmineZyoursrrrÚ__cmp__js zViewList.__cmp__cCst|tƒr|jS|SdS)N)r r¡r¥)rr±rrrÚ__castps zViewList.__castcCs ||jkS)N)r¥)rÚitemrrrÚ __contains__vr³zViewList.__contains__cCs t|jƒS)N)r2r¥)rrrrÚ__len__wr³zViewList.__len__cCs^t|tƒrP|jdkstdƒ‚|j|j|j|j…|j|j|j…||jpJdd�S|j|SdS)N)Nrzcannot handle slice with strider)r¦r§r¨) r ÚsliceÚstepr«r+r¥ÚstartÚstopr¦)rr£rrrÚ __getitem__}s  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) r r¾r¿r«r¡rIr¥rÀrÁr¦r2r§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¨rIr¿r«rÀrÁr2)rr£rrrÚ __delitem__–szViewList.__delitem__cCs4t|tƒr(|j|j|j|j|jd�Stdƒ‚dS)N)r¦z!adding non-ViewList to a ViewList)r r¡r+r¥r¦rI)rr±rrrÚ__add__¤s zViewList.__add__cCs4t|tƒr(|j|j|j|j|jd�Stdƒ‚dS)N)r¦z!adding ViewList to a non-ViewList)r r¡r+r¥r¦rI)rr±rrrÚ__radd__«s zViewList.__radd__cCs(t|tƒr|j|j7_ntdƒ‚|S)Nz!argument to += must be a ViewList)r r¡r¥rI)rr±rrrÚ__iadd__²s zViewList.__iadd__cCs|j|j||j|d�S)N)r¦)r+r¥r¦)rrArrrÚ__mul__¹szViewList.__mul__cCs |j|9_|j|9_|S)N)r¥r¦)rrArrrÚ__imul__¾szViewList.__imul__cCsRt|tƒstdƒ‚|jr2|j t|jƒ|j|¡|j |j¡|j  |j ¡dS)Nz(extending a ViewList with a non-ViewList) r r¡rIr§rOr2r¥r¨r&r¦)rr±rrrr&Ãs  zViewList.extendrcCsX|dkr| |¡n@|jr8|j t|jƒ|j|||¡|j |¡|j ||f¡dS)N)r&r§rOr2r¥r¨rdr¦)rr»rr8rrrrdË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) r r¡rIr¥r¦r§r2rOr¨)rr£r»rr8ÚindexrrrrOÕs zViewList.insertrcCsH|jr0t|jƒ|t|jƒ}|j ||j¡|j |¡|j |¡S)N)r§r2r¥Ú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)r2r¥r?r¦r§r¨)rrArrrr‡í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)r2r¥r?r¦)rrArrrÚtrim_endûszViewList.trim_endcCs| |¡}||=dS)N)rÊ)rr»rÊrrrrgs 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.reversecGsBtt|j|jƒf|žŽ}dd„|Dƒ|_dd„|Dƒ|_d|_dS)NcSsg|] }|d‘qS)rr)r¢Úentryrrrr¤sz!ViewList.sort..cSsg|] }|d‘qS)rr)r¢rÏrrrr¤s)ÚsortedÚzipr¥r¦r§)rr0ÚtmprrrÚsortsz ViewList.sortcCsJy |j|Stk rD|t|jƒkr>|j|dddfS‚YnXdS)z%Return source & offset for index `i`.rrN)r¦r?r2r¥)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£rrrr8'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¦)rrarr8rrrÚ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")rr rrrÚpprint4szViewList.pprint)NNNNN)Nr)Nr)r)r)r)+r,rirjrkrr®r¯r²r´rµr¶r·r¸r¹r°r¼r½rÂrÃrÄrÅrÆrÇrÈÚ__rmul__rÉr&rdrOrËr‡rÌrgrÍrÊrÎrÓr(rr8rÔrÕrÖrrrrr¡-sR       r¡c@sNeZdZdZdejfdd„Zddd„Zdd d „Zdd d „Z dd„Z dd„Z d S)r!z*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¤Dsz(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)r2r¥rBr(rR)rrÀrSršÚlastr rr8rrrrQGs     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À)r2r¥rBÚlstripÚminrÙ)rrÀrˆr‰r�r�r‹ršrÛr rŒÚstrippedZ line_indentrTrrrr†\sB       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ˆk�r |k�r&nn‡fdd„|jDƒ|_|S)Nrcsg|]}|ˆd…‘qS)Nr)r¢r )r‹rrr¤ªsz+StringList.get_2D_block..) rªr2r¥rZcolumn_indicesr?ÚrstriprÝrÜ) rÚtopÚleftÚbottomÚrightr‰rTr£Úcir r)r‹rÚ get_2D_block˜s$      "zStringList.get_2D_blockcCsxtj}xltt|jƒƒD]Z}|j|}t|tƒrg}x,|D]$}| |¡||ƒdkr8| |¡q8Wd |¡|j|<qWdS)zƒ Pad all double-width characters in self by appending `pad_char` to each. For East Asian language support. ZWFrMN) Ú unicodedataÚeast_asian_widthrªr2r¥r Úunicoderdr#)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ªr2r¥Úreplace)rÚoldrér£rrrrì½szStringList.replace)F)rFTNN)T) r,rirjrkÚsysÚmaxsizerÙrQr†rårërìrrrrr!:s  ; r!c@s eZdZdS)ÚStateMachineErrorN)r,rirjrrrrrðÃsrðc@s eZdZdS)r>N)r,rirjrrrrr>Äsr>c@s eZdZdS)r\N)r,rirjrrrrr\Åsr\c@s eZdZdS)rvN)r,rirjrrrrrvÆsrvc@s eZdZdS)ruN)r,rirjrrrrruÇsruc@s eZdZdS)r~N)r,rirjrrrrr~Èsr~c@s eZdZdS)r�N)r,rirjrrrrr�Ésr�c@s eZdZdS)rRN)r,rirjrrrrrRÊsrRc@seZdZdZdS)r.z‡ Raise from within a transition method to switch to another transition. Raise with one argument, the new transition name. N)r,rirjrkrrrrr.Ísr.c@seZdZdZdS)r1zª 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,rirjrkrrrrr1Ösr1é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`raÚ tracebackÚcoderrrr_ôs  r_)&rkÚ __future__rÚ __docformat__rîr|ræZdocutilsrZdocutils.utils.error_reportingrÚ version_infor­rèÚobjectrrlr…r‘r�rŸr r¡r!Ú Exceptionrðr>r\rvrur~r�rRr.r1r}rør_rrrrÚisP    g