[Python-checkins] CVS: python/dist/src/Lib sgmllib.py,1.20,1.21

Fred L. Drake python-dev@python.org
2000年6月29日 11:51:02 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv28314
Modified Files:
	sgmllib.py 
Log Message:
[Old patch that hadn't been checked in.]
get_starttag_text(): New method.
 Return the text of the most recently parsed start tag, from
 the '<' to the '>' or '/'. Not really useful for structure
 processing, but requested for Web-related use. May also be
 useful for being able to re-generate the input from the parse
 events, but there's no equivalent for end tags.
attrfind: Be a little more forgiving of unquoted attribute values.
Index: sgmllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sgmllib.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -r1.20 -r1.21
*** sgmllib.py	2000年06月28日 14:48:01	1.20
--- sgmllib.py	2000年06月29日 18:50:59	1.21
***************
*** 38,42 ****
 '[%s]*([a-zA-Z_][-.a-zA-Z_0-9]*)' % string.whitespace
 + ('([%s]*=[%s]*' % (string.whitespace, string.whitespace))
! + r'(\'[^\']*\'|"[^"]*"|[-a-zA-Z0-9./:+*%?!\(\)_#=~]*))?')
 
 
--- 38,42 ----
 '[%s]*([a-zA-Z_][-.a-zA-Z_0-9]*)' % string.whitespace
 + ('([%s]*=[%s]*' % (string.whitespace, string.whitespace))
! + r'(\'[^\']*\'|"[^"]*"|[-a-zA-Z0-9./:+*%?!&$\(\)_#=~]*))?')
 
 
***************
*** 208,214 ****
--- 208,220 ----
 j = match.end(0)
 return j-i
+ 
+ __starttag_text = None
+ def get_starttag_text(self):
+ return self.__starttag_text
 
 # Internal -- handle starttag, return length or -1 if not terminated
 def parse_starttag(self, i):
+ self.__starttag_text = None
+ start_pos = i
 rawdata = self.rawdata
 if shorttagopen.match(rawdata, i):
***************
*** 221,227 ****
 return -1
 tag, data = match.group(1, 2)
 tag = string.lower(tag)
- self.finish_shorttag(tag, data)
 k = match.end(0)
 return k
 # XXX The following should skip matching quotes (' or ")
--- 227,235 ----
 return -1
 tag, data = match.group(1, 2)
+ self.__starttag_text = '<%s/' % tag
 tag = string.lower(tag)
 k = match.end(0)
+ self.finish_shorttag(tag, data)
+ self.__starttag_text = rawdata[start_pos:match.end(1) + 1]
 return k
 # XXX The following should skip matching quotes (' or ")
***************
*** 256,259 ****
--- 264,268 ----
 if rawdata[j] == '>':
 j = j+1
+ self.__starttag_text = rawdata[start_pos:j]
 self.finish_starttag(tag, attrs)
 return j

AltStyle によって変換されたページ (->オリジナル) /