Thread: [Docstring-checkins] CVS: dps/dps statemachine.py,1.10,1.11
Status: Pre-Alpha
Brought to you by:
goodger
From: David G. <go...@us...> - 2001-11-13 03:07:11
|
Update of /cvsroot/docstring/dps/dps In directory usw-pr-cvs1:/tmp/cvs-serv12903/dps/dps Modified Files: statemachine.py Log Message: - Added 'stripindent' optional argument to 'getindented', 'getknownindented', and 'getfirstknownindented' methods of StateWS, and to 'extractindented' function. Index: statemachine.py =================================================================== RCS file: /cvsroot/docstring/dps/dps/statemachine.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** statemachine.py 2001/09/17 03:56:25 1.10 --- statemachine.py 2001/11/13 03:07:09 1.11 *************** *** 722,741 **** return context, '', [] # neither blank line nor indented ! def getindented(self, uptoblank=0): """ Return a indented lines of text and info. Extract an indented block where the indent is unknown for all lines. - Stop extracting at the first blank line If `uptoblank` is set to - true (1). 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. """ offset = self.abslineoffset() indented, indent, blankfinish = extractindented( ! self.inputlines[self.lineoffset:], uptoblank) if indented: self.nextline(len(indented) - 1) # advance to last indented line --- 722,744 ---- return context, '', [] # neither blank line nor indented ! def getindented(self, uptoblank=0, stripindent=1): """ Return a indented lines of text and info. Extract an indented block where the indent is unknown for all lines. ! :Parameters: ! - `uptoblank`: Stop collecting at the first blank line if true (1). ! - `stripindent`: Strip common leading indent if true (1, 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. """ offset = self.abslineoffset() indented, indent, blankfinish = extractindented( ! self.inputlines[self.lineoffset:], uptoblank, stripindent) if indented: self.nextline(len(indented) - 1) # advance to last indented line *************** *** 747,767 **** return indented, indent, offset, blankfinish ! def getknownindented(self, indent, uptoblank=0): """ Return an indented block and info. Extract an indented block where the indent is known for all lines. - Stop extracting at the first blank line If `uptoblank` is set to - true (1). Return: - - - the indented block, - - its first line offset from BOF, and - - whether or not it finished with a blank line. - Starting with the current line, extract the entire text block with at ! least `indent` indentation. Strip off `indent` indentation (which must ! be whitespace, except for the first line) from each line. ! Parameter `indent`: the number of indent columns/characters. """ offset = self.abslineoffset() --- 750,772 ---- return indented, indent, offset, blankfinish ! def getknownindented(self, indent, uptoblank=0, stripindent=1): """ 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. ! - `uptoblank`: Stop collecting at the first blank line if true (1). ! - `stripindent`: Strip `indent` characters of indentation if true ! (1, default). ! ! :Return: ! - the indented block, ! - its first line offset from BOF, and ! - whether or not it finished with a blank line. """ offset = self.abslineoffset() *************** *** 774,778 **** blankfinish = 1 break ! indented.append(line[indent:]) else: blankfinish = 1 --- 779,786 ---- blankfinish = 1 break ! if stripindent: ! indented.append(line[indent:]) ! else: ! indented.append(line) else: blankfinish = 1 *************** *** 786,808 **** return indented, offset, blankfinish ! def getfirstknownindented(self, indent, uptoblank=0): """ 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. Stop extracting at the first blank ! line If `uptoblank` is set to true (1). Return: ! - the indented block, ! - its indent, ! - its first line offset from BOF, and ! - whether or not it finished with a blank line. ! Parameter `indent`: the first line's indent (# of columns/characters). """ offset = self.abslineoffset() indented = [self.line[indent:]] indented[1:], indent, blankfinish = extractindented( ! self.inputlines[self.lineoffset + 1:], uptoblank) self.nextline(len(indented) - 1) # advance to last indented line while indented and not indented[-1].strip(): --- 794,820 ---- return indented, offset, blankfinish ! def getfirstknownindented(self, indent, uptoblank=0, stripindent=1): """ 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). ! - `uptoblank`: Stop collecting at the first blank line if true (1). ! - `stripindent`: Strip `indent` characters of indentation if true ! (1, default). ! :Return: ! - the indented block, ! - its indent, ! - its first line offset from BOF, and ! - whether or not it finished with a blank line. """ offset = self.abslineoffset() indented = [self.line[indent:]] indented[1:], indent, blankfinish = extractindented( ! self.inputlines[self.lineoffset + 1:], uptoblank, stripindent) self.nextline(len(indented) - 1) # advance to last indented line while indented and not indented[-1].strip(): *************** *** 990,1013 **** return [s.expandtabs(tabwidth) for s in astring.splitlines()] ! def extractindented(lines, uptoblank=0): """ Extract and return a list of indented lines of text. ! Given a list of one-line strings without newlines (`lines`), collect all ! lines with indentation, determine the minimum indentation, remove the ! minimum indentation from all indented lines, and return them. All lines up ! to but not including the first unindented line will be returned. Stop ! collecting at the first blank line If `uptoblank` is set to true (1) :Parameters: ! ! - `lines`: . :Return: ! ! - a list of indented lines with mininum indent removed; ! - the amount of the indent; ! - whether or not the block finished with a blank line or at the end of ! `lines`. """ source = [] --- 1002,1024 ---- return [s.expandtabs(tabwidth) for s in astring.splitlines()] ! def extractindented(lines, uptoblank=0, stripindent=1): """ Extract and return a list of indented lines of text. ! Collect all lines with indentation, determine the minimum indentation, ! remove the minimum indentation from all indented lines (unless ! `stripindent` is false), and return them. All lines up to but not ! including the first unindented line will be returned. :Parameters: ! - `lines`: a list of one-line strings without newlines. ! - `uptoblank`: Stop collecting at the first blank line if true (1). ! - `stripindent`: Strip common leading indent if true (1, default). :Return: ! - a list of indented lines with mininum indent removed; ! - the amount of the indent; ! - whether or not the block finished with a blank line or at the end of ! `lines`. """ source = [] *************** *** 1033,1037 **** blankfinish = 1 # block ends at end of lines if indent: ! return [s[indent:] for s in source], indent, blankfinish else: return [], 0, blankfinish --- 1044,1050 ---- blankfinish = 1 # block ends at end of lines if indent: ! if stripindent: ! source = [s[indent:] for s in source] ! return source, indent, blankfinish else: return [], 0, blankfinish |