コード例 #1
0
ファイル: esistools.py プロジェクト: alexhsamuel/pyhep
 def _handle_token(self, token, data):
     handler = self.getContentHandler()
     if token == '-':
         if data and handler:
             handler.characters(decode(data))
     elif token == ')':
         if handler:
             handler.endElement(decode(data))
     elif token == '(':
         if self._is_empty:
             self._empties[data] = 1
         if handler:
             handler.startElement(data, self._attributes)
         self._attrs.clear()
         self._is_empty = 0
     elif token == 'A':
         name, value = data.split(' ', 1)
         if value != "IMPLIED":
             type, value = value.split(' ', 1)
             self._attrs[name] = (decode(value), type)
     elif token == '&':
         # entity reference in SAX?
         pass
     elif token == '?':
         if handler:
             if ' ' in data:
                 target, data = data.split(None, 1)
             else:
                 target, data = data, ""
             handler.processingInstruction(target, decode(data))
     elif token == 'N':
         handler = self.getDTDHandler()
         if handler:
             handler.notationDecl(data, self._public_id, self._system_id)
         self._public_id = None
         self._system_id = None
     elif token == 'p':
         self._public_id = decode(data)
     elif token == 's':
         self._system_id = decode(data)
     elif token == 'e':
         self._is_empty = 1
     elif token == 'C':
         pass
     else:
         e = SAXParseException("unknown ESIS token in event stream",
                               None, self._locator)
         self.getErrorHandler().error(e)
コード例 #2
0
 def _handle_token(self, token, data):
     handler = self.getContentHandler()
     if token == '-':
         if data and handler:
             handler.characters(decode(data))
     elif token == ')':
         if handler:
             handler.endElement(decode(data))
     elif token == '(':
         if self._is_empty:
             self._empties[data] = 1
         if handler:
             handler.startElement(data, self._attributes)
         self._attrs.clear()
         self._is_empty = 0
     elif token == 'A':
         name, value = data.split(' ', 1)
         if value != "IMPLIED":
             type, value = value.split(' ', 1)
             self._attrs[name] = (decode(value), type)
     elif token == '&':
         # entity reference in SAX?
         pass
     elif token == '?':
         if handler:
             if ' ' in data:
                 target, data = data.split(None, 1)
             else:
                 target, data = data, ""
             handler.processingInstruction(target, decode(data))
     elif token == 'N':
         handler = self.getDTDHandler()
         if handler:
             handler.notationDecl(data, self._public_id, self._system_id)
         self._public_id = None
         self._system_id = None
     elif token == 'p':
         self._public_id = decode(data)
     elif token == 's':
         self._system_id = decode(data)
     elif token == 'e':
         self._is_empty = 1
     elif token == 'C':
         pass
     else:
         e = SAXParseException("unknown ESIS token in event stream", None,
                               self._locator)
         self.getErrorHandler().error(e)
コード例 #3
0
ファイル: handlers.py プロジェクト: srobertson/rambler
 def startElement(self, name, attrs):
     for handler in self._handlers:
         handler.startElement(name, attrs)