[Docstring-checkins] CVS: dps/dps utils.py,1.13,1.14
Status: Pre-Alpha
Brought to you by:
goodger
From: David G. <go...@us...> - 2002-02-12 02:16:30
|
Update of /cvsroot/docstring/dps/dps In directory usw-pr-cvs1:/tmp/cvs-serv30612/dps/dps Modified Files: utils.py Log Message: Factored ``extract_name_value`` out of ``extractattributes()``. Index: utils.py =================================================================== RCS file: /cvsroot/docstring/dps/dps/utils.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** utils.py 7 Feb 2002 02:00:45 -0000 1.13 --- utils.py 12 Feb 2002 02:16:27 -0000 1.14 *************** *** 199,235 **** 'input line not enclosed in "[" and "]"') line = line[1:-1].strip() ! while line: ! equals = line.find('=') ! if equals == -1: ! raise BadAttributeDataError('missing "="') ! elif equals == 0: raise BadAttributeDataError( ! 'missing attribute name before "="') ! attname = line[:equals] ! line = line[equals+1:] ! if not line: raise BadAttributeDataError( ! 'missing value after "%s="' % attname) ! if line[0] in '\'"': ! endquote = line.find(line[0], 1) ! if endquote == -1: ! raise BadAttributeDataError( ! 'attribute "%s" missing end quote (%s)' ! % (attname, line[0])) ! if len(line) > endquote + 1 and line[endquote + 1].strip(): ! raise BadAttributeDataError( ! 'attribute "%s" end quote (%s) not followed by ' ! 'whitespace' % (attname, line[0])) ! data = line[1:endquote] ! line = line[endquote+1:].lstrip() else: ! space = line.find(' ') ! if space == -1: ! data = line ! line = '' ! else: ! data = line[:space] ! line = line[space+1:].lstrip() ! attlist.append((attname.lower(), data)) return attlist --- 199,246 ---- 'input line not enclosed in "[" and "]"') line = line[1:-1].strip() ! attlist += extract_name_value(line) ! return attlist ! ! def extract_name_value(line): ! """ ! Return a list of (name, value) from a line of the form "name=value ...". ! ! :Raises: `BadAttributeDataError` for invalid attribute data (missing name, ! missing data, bad quotes, etc.). ! """ ! attlist = [] ! while line: ! equals = line.find('=') ! if equals == -1: ! raise BadAttributeDataError('missing "="') ! attname = line[:equals].strip() ! if equals == 0 or not attname: ! raise BadAttributeDataError( ! 'missing attribute name before "="') ! line = line[equals+1:].lstrip() ! if not line: ! raise BadAttributeDataError( ! 'missing value after "%s="' % attname) ! if line[0] in '\'"': ! endquote = line.find(line[0], 1) ! if endquote == -1: raise BadAttributeDataError( ! 'attribute "%s" missing end quote (%s)' ! % (attname, line[0])) ! if len(line) > endquote + 1 and line[endquote + 1].strip(): raise BadAttributeDataError( ! 'attribute "%s" end quote (%s) not followed by ' ! 'whitespace' % (attname, line[0])) ! data = line[1:endquote] ! line = line[endquote+1:].lstrip() ! else: ! space = line.find(' ') ! if space == -1: ! data = line ! line = '' else: ! data = line[:space] ! line = line[space+1:].lstrip() ! attlist.append((attname.lower(), data)) return attlist |