Пример #1
0
 def _onStartElement(self, name, attrs):
     self._depth += 1
     if self._cur_stanza is None:
         tag_name = self._parse_tag_name(name)
         if tag_name in self.STANZA_TYPES:
             self._cur_stanza = (tag_name, self._depth)
         ExpatElementStream._onStartElement(self, name, attrs)
     else:
         return
Пример #2
0
 def _onStartElement(self, name, attrs):
     self._depth += 1
     if self._cur_stanza is None:
         tag_name = self._parse_tag_name(name)
         if tag_name in self.STANZA_TYPES:
             self._cur_stanza = (tag_name, self._depth)
         ExpatElementStream._onStartElement(self, name, attrs)
     else:
         return
Пример #3
0
 def _onEndElement(self, name):
     if self._cur_stanza is not None:
         if self._depth == self._cur_stanza[1]:
             self._depth -= 1
             self._cur_stanza = None
             ExpatElementStream._onEndElement(self, name)
         else:
             self._depth -= 1
             return
     else:
         self._depth -= 1
         ExpatElementStream._onEndElement(self, name)
Пример #4
0
 def _onEndElement(self, name):
     if self._cur_stanza is not None:
         if self._depth == self._cur_stanza[1]:
             self._depth -= 1
             self._cur_stanza = None
             ExpatElementStream._onEndElement(self, name)
         else:
             self._depth -= 1
             return
     else:
         self._depth -= 1
         ExpatElementStream._onEndElement(self, name)
Пример #5
0
def elementStream(shallow=False):
    """ Preferred method to construct an ElementStream

    Uses regular or 'shallow' Expat-based stream if available,
    and falls back to Sux if necessary.

    """
    try:
        if shallow:
            es = ShallowExpatElementStream()
        else:
            es = ExpatElementStream()
        return es
    except ImportError:
        if SuxElementStream is None:
            raise Exception("No parsers available :(")
        es = SuxElementStream()
        return es
Пример #6
0
 def __init__(self, *args, **kwargs):
     ExpatElementStream.__init__(self, *args, **kwargs)
     self._depth = 0
     self._cur_stanza = None
Пример #7
0
 def __init__(self, *args, **kwargs):
     ExpatElementStream.__init__(self, *args, **kwargs)
     self._depth = 0
     self._cur_stanza = None