Ported [7461] to trunk

This commit is contained in:
junglecow 2006-11-18 15:12:47 +00:00
parent c3e24dfa76
commit 5b96b90a2d
2 changed files with 19 additions and 3 deletions

View File

@ -131,7 +131,7 @@ class Dispatcher(PlugIn):
try: try:
self.Stream.Parse(data) self.Stream.Parse(data)
# end stream:stream tag received # end stream:stream tag received
if self.Stream and self.Stream._NodeBuilder__depth == 0: if self.Stream and self.Stream.has_received_endtag():
self._owner.Connection.disconnect() self._owner.Connection.disconnect()
return 0 return 0
except ExpatError: except ExpatError:
@ -142,6 +142,7 @@ class Dispatcher(PlugIn):
if len(self._pendingExceptions) > 0: if len(self._pendingExceptions) > 0:
_pendingException = self._pendingExceptions.pop() _pendingException = self._pendingExceptions.pop()
raise _pendingException[0], _pendingException[1], _pendingException[2] raise _pendingException[0], _pendingException[1], _pendingException[2]
if len(data) == 0: return '0'
return len(data) return len(data)
def RegisterNamespace(self, xmlns, order='info'): def RegisterNamespace(self, xmlns, order='info'):

View File

@ -290,6 +290,8 @@ class NodeBuilder:
self.Parse = self._parser.Parse self.Parse = self._parser.Parse
self.__depth = 0 self.__depth = 0
self.__last_depth = 0
self.__max_depth = 0
self._dispatch_depth = 1 self._dispatch_depth = 1
self._document_attrs = None self._document_attrs = None
self._mini_dom=initial_node self._mini_dom=initial_node
@ -326,7 +328,7 @@ class NodeBuilder:
ns=attr[:sp] # ns=attr[:sp] #
attrs[self.namespaces[ns]+attr[sp+1:]]=attrs[attr] attrs[self.namespaces[ns]+attr[sp+1:]]=attrs[attr]
del attrs[attr] # del attrs[attr] #
self.__depth += 1 self._inc_depth()
self.DEBUG(DBG_NODEBUILDER, "DEPTH -> %i , tag -> %s, attrs -> %s" % (self.__depth, tag, `attrs`), 'down') self.DEBUG(DBG_NODEBUILDER, "DEPTH -> %i , tag -> %s, attrs -> %s" % (self.__depth, tag, `attrs`), 'down')
if self.__depth == self._dispatch_depth: if self.__depth == self._dispatch_depth:
if not self._mini_dom : if not self._mini_dom :
@ -354,7 +356,7 @@ class NodeBuilder:
self._ptr = self._ptr.parent self._ptr = self._ptr.parent
else: else:
self.DEBUG(DBG_NODEBUILDER, "Got higher than dispatch level. Stream terminated?", 'stop') self.DEBUG(DBG_NODEBUILDER, "Got higher than dispatch level. Stream terminated?", 'stop')
self.__depth -= 1 self._dec_depth()
self.last_is_data = 0 self.last_is_data = 0
if self.__depth == 0: self.stream_footer_received() if self.__depth == 0: self.stream_footer_received()
@ -387,6 +389,19 @@ class NodeBuilder:
""" Method called when stream just closed. """ """ Method called when stream just closed. """
self.check_data_buffer() self.check_data_buffer()
def has_received_endtag(self, level=0):
""" Return True if at least one end tag was seen (at level) """
return self.__depth <= level and self.__max_depth > level
def _inc_depth(self):
self.__last_depth = self.__depth
self.__depth += 1
self.__max_depth = max(self.__depth, self.__max_depth)
def _dec_depth(self):
self.__last_depth = self.__depth
self.__depth -= 1
def XML2Node(xml): def XML2Node(xml):
""" Converts supplied textual string into XML node. Handy f.e. for reading configuration file. """ Converts supplied textual string into XML node. Handy f.e. for reading configuration file.
Raises xml.parser.expat.parsererror if provided string is not well-formed XML. """ Raises xml.parser.expat.parsererror if provided string is not well-formed XML. """