self.elements = [] #this will contain a list of elements and their start/end indices
self.open_elements = [] #this holds info on open elements while we wait for their close
self.content = ""
self.elements = [] #this will contain a list of elements and their start/end indices
self.open_elements = [] #this holds info on open elements while we wait for their close
self.content = ""
- def startElement (self,name,attrs):
- if name=='foobar': return # we require an outer wrapper, which we promptly ignore.
+ def startElement(self, name, attrs):
+ if name == 'foobar': return # we require an outer wrapper, which we promptly ignore.
self.open_elements.append({'name':name,
'attrs':attrs.copy(),
'start':len(self.content),
})
self.open_elements.append({'name':name,
'attrs':attrs.copy(),
'start':len(self.content),
})
- def endElement (self, name):
- if name=='foobar': return # we require an outer wrapper, which we promptly ignore.
+ def endElement(self, name):
+ if name == 'foobar': return # we require an outer wrapper, which we promptly ignore.
# append a (start,end), name, attrs
self.elements.append(((e['start'], #start position
# append a (start,end), name, attrs
self.elements.append(((e['start'], #start position
"""A simple class for dealing with marked up strings. When we are sliced, we return
valid marked up strings, preserving markup."""
"""A simple class for dealing with marked up strings. When we are sliced, we return
valid marked up strings, preserving markup."""
self.handler = simpleHandler()
xml.sax.parseString((u"<foobar>%s</foobar>" % string).encode('utf-8'), self.handler)
self.raw = self.handler.content
self.handler = simpleHandler()
xml.sax.parseString((u"<foobar>%s</foobar>" % string).encode('utf-8'), self.handler)
self.raw = self.handler.content
- def __getitem__ (self, n):
- return self.__getslice__(n,n+1)
+ def __getitem__(self, n):
+ return self.__getslice__(n, n + 1)
# only include relevant elements
if not e or e > len(self.raw): e = len(self.raw)
elements = filter(lambda tp: (tp[0][1] >= s and # end after the start...
# only include relevant elements
if not e or e > len(self.raw): e = len(self.raw)
elements = filter(lambda tp: (tp[0][1] >= s and # end after the start...