[Docstring-checkins] CVS: dps/dps statemachine.py,1.9,1.10
Status: Pre-Alpha
Brought to you by:
goodger
From: David G. <go...@us...> - 2001-09-17 03:56:28
|
Update of /cvsroot/docstring/dps/dps In directory usw-pr-cvs1:/tmp/cvs-serv11631/dps/dps Modified Files: statemachine.py Log Message: - Added 'uptoblank' 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.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** statemachine.py 2001/09/13 02:15:35 1.9 --- statemachine.py 2001/09/17 03:56:25 1.10 *************** *** 722,733 **** return context, '', [] # neither blank line nor indented ! def getindented(self): """ ! Return an indented block and info. Extract an indented block where the indent is unknown for all lines. ! Return: ! - the indented block, - its indent, - its first line offset from BOF, and --- 722,734 ---- 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 *************** *** 736,740 **** offset = self.abslineoffset() indented, indent, blankfinish = extractindented( ! self.inputlines[self.lineoffset:]) if indented: self.nextline(len(indented) - 1) # advance to last indented line --- 737,741 ---- offset = self.abslineoffset() indented, indent, blankfinish = extractindented( ! self.inputlines[self.lineoffset:], uptoblank) if indented: self.nextline(len(indented) - 1) # advance to last indented line *************** *** 746,755 **** return indented, indent, offset, blankfinish ! def getknownindented(self, indent): """ Return an indented block and info. Extract an indented block where the indent is known for all lines. ! Return: - the indented block, --- 747,757 ---- 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, *************** *** 769,772 **** --- 771,777 ---- blankfinish = not indented[-1].strip() and len(indented) > 1 break + if uptoblank and line.strip(): + blankfinish = 1 + break indented.append(line[indent:]) else: *************** *** 781,790 **** return indented, offset, blankfinish ! def getfirstknownindented(self, indent): """ 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. Return: - the indented block, --- 786,796 ---- 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, *************** *** 798,802 **** indented = [self.line[indent:]] indented[1:], indent, blankfinish = extractindented( ! self.inputlines[self.lineoffset + 1:]) self.nextline(len(indented) - 1) # advance to last indented line while indented and not indented[-1].strip(): --- 804,808 ---- 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(): *************** *** 984,1000 **** return [s.expandtabs(tabwidth) for s in astring.splitlines()] ! def extractindented(lines): """ ! Extract and return a continuous indented block. ! 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. ! ! Parameter `lines`: a list of one-line strings without newlines. ! Return: - a list of indented lines with mininum indent removed; - the amount of the indent; --- 990,1009 ---- 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; *************** *** 1009,1014 **** blankfinish = len(source) and not source[-1].strip() break - source.append(line) stripped = line.lstrip() if not stripped: # blank line continue --- 1018,1026 ---- blankfinish = len(source) and not source[-1].strip() break stripped = line.lstrip() + if uptoblank and not stripped: # blank line + blankfinish = 1 + break + source.append(line) if not stripped: # blank line continue |