示例#1
0
    def endElement(self, name):
        if not self._eat_tag:
            XMLFilterBase.endElement(self, name)

        if name == 'text' and self._catch_full_line:
            self._catch_full_line = False
        elif name == 'dialogue_act' and self._write_full_line:
            self._write_full_line = False
            if len(self._full_line) < self._da_line_len:
                self._whole_line.append("... (missing)")
                self.errorCallback()
            line = self._full_line[:self._da_line_len]
            del self._full_line[:self._da_line_len]
            self._da_line_len = 0
            line = u' '.join(line)

            writer = self.getContentHandler()
            writer.characters('\n' + ' '*self.TAG_INDENT)
            attrs = {'type': self.text_type}
            attrs.update(self._da_attrs)
            writer.startElement('parametrized_act', attrs)
            writer.characters('\n' + ' '*self.CHAR_INDENT)
            writer.characters(line)
            writer.characters('\n' + ' '*self.TAG_INDENT)
            writer.endElement('parametrized_act')
        elif name == 'utterance':
            if self._full_line and self._da_count != 0:
                self.errorCallback()
        elif name == 'parametrized_act':
            self._eat_tag = False
示例#2
0
    def startElement(self, name, attrs):
        if name == 'xcb':
            self.header.insert(0, attrs['header'])
        elif name == 'field':
            size = self.types.get(attrs['type'], 0)
            if self.struct is not None:
                self.totalsize += size
            elif self.union is not None:
                self.totalsize = max(self.totalsize, size)
            attrs = AttributesUnion(attrs, bytes=str(size))
        elif name == 'pad':
            assert self.union is None
            if self.struct is not None:
                self.totalsize += int(attrs['bytes'])
        elif name == 'xidtype':
            self.setTypeSize(attrs['name'], 4)
        elif name == 'typedef':
            self.setTypeSize(attrs['newname'], self.types[attrs['oldname']])
        elif name == 'struct' or name == 'union':
            assert self.struct is None and self.union is None
            setattr(self, name, attrs['name'])
            self.totalsize = 0

        if len(self.header) == 1 or name == 'xcb':
            XMLFilterBase.startElement(self, name, attrs)
示例#3
0
 def __init__(self, file):
     XMLFilterBase.__init__(self)
     self.generator = XMLGenerator(file, 'UTF-8')
     self.generator.startPrefixMapping(u'', u'http://www.eucalyptus.com/ns/reporting/export/2012-08-24/')
     self.replyData = StringIO()
     self.replyGenerator = XMLGenerator( self.replyData, 'UTF-8' )
     self.switchTarget( self.replyGenerator )
示例#4
0
	def startElement(self, name, attrs):
		if name == 'xcb':
			self.header.insert(0, attrs['header'])
		elif name == 'field':
			size = self.types.get(attrs['type'], 0)
			if self.struct is not None:
				self.totalsize += size
			elif self.union is not None:
				self.totalsize = max(self.totalsize, size)
			attrs = AttributesUnion(attrs, bytes=str(size))
		elif name == 'pad':
			assert self.union is None
			if self.struct is not None:
				self.totalsize += int(attrs['bytes'])
		elif name == 'xidtype':
			self.setTypeSize(attrs['name'], 4)
		elif name == 'typedef':
			self.setTypeSize(attrs['newname'], self.types[attrs['oldname']])
		elif name == 'struct' or name == 'union':
			assert self.struct is None and self.union is None
			setattr(self, name, attrs['name'])
			self.totalsize = 0

		if len(self.header) == 1 or name == 'xcb':
			XMLFilterBase.startElement(self, name, attrs)
示例#5
0
 def characters(self, text):
     if self.recording == "cell":
         self.cell.append(text)
     elif self.recording == "cell_active":
         self.cell_active.append(text)
     elif self.recording is None:
         XMLFilterBase.characters(self, text)
    def __init__(
            self, upstream, downstream, tag_name,
            layers_blacklist=None, layers_whitelist=None):
        XMLFilterBase.__init__(self, upstream)
        self._downstream = downstream
        self._accumulator = []

        assert layers_blacklist is not None or layers_whitelist is not None, \
            "either layers_blacklist OR layers_whitelist must be set"
        assert not (
            layers_blacklist is not None and
            layers_whitelist is not None), \
            "only either layers_blacklist OR layers_whitelist can be set"

        if layers_blacklist is not None:
            layers_blacklist = [layer.lower() for layer in layers_blacklist]
        if layers_whitelist is not None:
            layers_whitelist = [layer.lower() for layer in layers_whitelist]
        self.layers_blacklist = layers_blacklist
        self.layers_whitelist = layers_whitelist

        self.layers_path = []
        self.in_name = False
        self.tag_name = tag_name
        self.level = 0
示例#7
0
  def __init__ (self, upstream, SkipEvents = False):

    self.EventCounters = {}
    self.TotalEventCount = 0
    self.SkipEvents = SkipEvents
    self.NewEventType = True
    self.AccumulatingEventContent = False
    self.CurrentEventContent = ''
    self.StreamCopyEnabled = False

    # This buffer will be used to compile a copy of the incoming EDXML
    # stream that has all event data filtered out. We use this stripped
    # copy to do RelaxNG validation, as Python has no incremental XML
    # validator like for instance PHP does.
    self.DefinitionsXMLStringIO = StringIO()

    # And this is the XMLGenerator instance that we will use
    # to fill the buffer.
    self.DefinitionsXMLGenerator = XMLGenerator(self.DefinitionsXMLStringIO, 'utf-8')

    """EDXMLDefinitions instance"""
    self.Definitions = EDXMLDefinitions()

    # We want the EDXMLDefinitions instance to call our
    # error handler, so anyone who wishes to extend the EDXMLParser
    # class can reimplement it to handle all generated errors.
    self.Definitions.Error = self.Error

    XMLFilterBase.__init__(self, upstream)
    EDXMLBase.__init__(self)
示例#8
0
 def __init__(self, upstream, downstream):
     XMLFilterBase.__init__(self, upstream)
     self._downstream = downstream
     self._accumulator = []
     #self.padding_level = -1  # for pretty debug printing
     self.lightStack = [
     ]  # for storing the light array for each hollow, so it can be put at the end of the hollow definition as opposed to the start
    def __init__(self,
                 upstream,
                 downstream,
                 tag_name,
                 layers_blacklist=None,
                 layers_whitelist=None):
        XMLFilterBase.__init__(self, upstream)
        self._downstream = downstream
        self._accumulator: List[str] = []

        assert (layers_blacklist is not None or layers_whitelist is not None
                ), "either layers_blacklist OR layers_whitelist must be set"
        assert not (
            layers_blacklist is not None and layers_whitelist is not None
        ), "only either layers_blacklist OR layers_whitelist can be set"

        if layers_blacklist is not None:
            layers_blacklist = [layer.lower() for layer in layers_blacklist]
        if layers_whitelist is not None:
            layers_whitelist = [layer.lower() for layer in layers_whitelist]
        self.layers_blacklist = layers_blacklist
        self.layers_whitelist = layers_whitelist

        self.layers_path: List[_Layer] = []
        self.in_name = False
        self.tag_name = tag_name
        self.level = 0
示例#10
0
 def startElement(self, name, attrs):
     attnames = []
     if name == 'xcb':
         self.startScope(attrs['header'])
     elif name in [
             'struct', 'union', 'xidtype', 'enum', 'event', 'eventcopy',
             'error', 'errorcopy'
     ]:
         self.declareType(attrs['name'])
         attnames = ['name']
         if name.endswith('copy'):
             attnames.append('ref')
     elif name == 'typedef':
         self.declareType(attrs['newname'])
         attnames = ['oldname', 'newname']
     elif name == 'valueparam':
         attnames = ['value-mask-type']
     elif attrs.has_key('type'):
         attnames = ['type']
     newattrs = {}
     for attname in attnames:
         newattrs[attname] = self.getQualifiedType(attrs[attname])
     if newattrs:
         attrs = AttributesUnion(attrs, **newattrs)
     XMLFilterBase.startElement(self, name, attrs)
示例#11
0
 def startPrefixMapping(self, prefix, uri):
     if self.prefixes.has_key(prefix):
         if self.prefixesStack.has_key(prefix):
             self.prefixesStack[prefix].append(self.prefixes[prefix])
         else:
             self.prefixesStack[prefix] = [self.prefixes[prefix]]
     self.prefixes[prefix] = uri
     XMLFilterBase.startPrefixMapping(self, prefix, uri)
示例#12
0
 def __init__(self, parent=None, handlers=None, groups_of=1):
     XMLFilterBase.__init__(self, parent)
     if handlers is None:
         self.handlers = (ContentHandler() for i in count())
     self.handlers = iter(handlers)
     self.processed = 0
     self.groups_of = groups_of
     self.new_handler()
示例#13
0
 def startPrefixMapping(self, prefix, uri):
     if self.prefixes.has_key(prefix):
         if self.prefixesStack.has_key(prefix):
             self.prefixesStack[prefix].append(self.prefixes[prefix])
         else:
             self.prefixesStack[prefix] = [self.prefixes[prefix]]
     self.prefixes[prefix] = uri
     XMLFilterBase.startPrefixMapping(self, prefix, uri)
    def __init__(self, upstream, downstream, text_filter, manualOverride = False):
        XMLFilterBase.__init__(self, upstream)
        self._downstream = downstream
        self._accumulator = []
        self.text_filter = text_filter
        self.should_filter = False
	self.manualOverride = manualOverride # Set this to True if you want text_filter never to run
        return
示例#15
0
 def endPrefixMapping(self, prefix):
     if self.prefixesStack.has_key(prefix):
         self.prefixes[prefix] = self.prefixesStack[prefix][-1]
         del (self.prefixesStack[prefix][-1])
         if self.prefixesStack[prefix] == []:
             del (self.prefixesStack[prefix])
     else:
         del (self.prefixes[prefix])
     XMLFilterBase.endPrefixMapping(self, prefix)
示例#16
0
 def __init__(self, In, Out, turn_map):
     XMLFilterBase.__init__(self, In)
     self._turn_map = turn_map
     self.element_stack = []
     self.Out = Out
     self.last_waypoint = None
     self.in_rtept = False
     self.in_name = False
     self.in_cmt = False
示例#17
0
	def startElement(self, name, attrs):
		assert self.inimport is None
		if name == 'import':
			self.inimport = ""
			return
		XMLFilterBase.startElement(self, name, attrs)
		if name == 'xcb':
			seen[attrs['header']] = True
			self.ensure('xproto')
示例#18
0
 def characters(self, chars):
     words = self.createWords(chars)
     if self._catch_full_line:
         self._full_line.extend(words)
         self._whole_line.extend(words)
     if self._write_full_line:
         self._da_line_len += len(words)
     if not self._eat_tag:
         XMLFilterBase.characters(self, chars)
示例#19
0
 def endPrefixMapping(self, prefix):
     if self.prefixesStack.has_key(prefix):
         self.prefixes[prefix] = self.prefixesStack[prefix][-1]
         del(self.prefixesStack[prefix][-1])
         if self.prefixesStack[prefix] == []:
             del (self.prefixesStack[prefix])
     else:
         del(self.prefixes[prefix])
     XMLFilterBase.endPrefixMapping(self, prefix)
示例#20
0
 def startElement(self, name, attrs):
     if name == 'text' and attrs.get('type') == self._new_type:
         self._eat_tag = True
     else:
         self._eat_tag = False
     if name == 'text' and attrs.get('type') == self._after:
         self._write_tag = True
     if not self._eat_tag:
         XMLFilterBase.startElement(self, name, attrs)
示例#21
0
 def endElement(self, name):
     if name == "record":
         XMLFilterBase.endElement(self, name)
         self.processed += 1
         if self.processed % self.groups_of == 0:
             XMLFilterBase.endElement(self, "collection")
             XMLFilterBase.endPrefixMapping(self, "")
             XMLFilterBase.endDocument(self)
     elif name != "collection":
         XMLFilterBase.endElement(self, name)
示例#22
0
 def __init__(self, In, Out):
     XMLFilterBase.__init__(self, In)
     self.Out = Out
     self.in_coursepoint = False
     self.current_coursepoint = {'lat': None, 'lon': None, 'name': None}
     self.element_type = ""
     self.value = None
     self.coursepoints = []
     self.process_chars = False
     self.route_name = None
示例#23
0
	def __init__(self, upstream, downstream):
		XMLFilterBase.__init__(self, upstream)
		self._downstream = downstream
		self._accumulator = []
		#self.padding_level = -1  # for pretty debug printing
		self.current_element = None  # what element are we inside?
		self.passthrough = False  # allow current element through the filter?
		# Placeholders for the attributes for the builder and shape elements...
		self.builder_info = None
		self.shape_info = None
示例#24
0
文件: saxsplit2.py 项目: olac/olac
 def __init__(self, upstream, downstream, filename,chunksize = 100):
     XMLFilterBase.__init__(self, upstream)
     self.handlers = []
     self.pushHandler(downstream)
     self.filename = filename
     self.chunksize = int(chunksize)
     self.rec_count = 0
     self.chunknames = []
     self.tempdir = ''
     self.verbose = False
示例#25
0
    def endElement(self, name):
        if len(self.header) == 1 or name == 'xcb':
            XMLFilterBase.endElement(self, name)

        if name == 'xcb':
            self.header.pop(0)
        elif name == 'struct' or name == 'union':
            assert getattr(self, name) is not None
            self.setTypeSize(getattr(self, name), self.totalsize)
            setattr(self, name, None)
            del self.totalsize
示例#26
0
	def endElement(self, name):
		if len(self.header) == 1 or name == 'xcb':
			XMLFilterBase.endElement(self, name)

		if name == 'xcb':
			self.header.pop(0)
		elif name == 'struct' or name == 'union':
			assert getattr(self, name) is not None
			self.setTypeSize(getattr(self, name), self.totalsize)
			setattr(self, name, None)
			del self.totalsize
示例#27
0
    def endElement(self, name):
        if not self._eat_tag:
            XMLFilterBase.endElement(self, name)
        if name == 'text' and self._write_tag:
            self._write_tag = False

            writer = self.getContentHandler()
            writer.characters('\n' + ' '*self.TAG_INDENT)
            writer.startElement('text', {'type': self._new_type})
            if self._tags:
                line = self._tags.pop(0)
                writer.characters('\n' + ' '*self.CHAR_INDENT)
                writer.characters(line)
                writer.characters('\n' + ' '*self.TAG_INDENT)
            writer.endElement('text')
示例#28
0
    def startElement(self, name, attrs):
        if name == "record" and self.processed > 0 \
           and self.processed % self.groups_of == 0:

            self.new_handler()
            XMLFilterBase.startDocument(self)
            XMLFilterBase.startPrefixMapping(self, "", self.uri)
            XMLFilterBase.startElement(self, "collection", Attributes({}))
        if name != "collection":
            XMLFilterBase.startElement(self, name, attrs)
示例#29
0
 def startElement(self, name, attrs):
     if self.in_universe >= 0:
         self.in_universe += 1
     if name == "zml_file":
         if attrs.getValue("version") != "0.1":
             raise FilterError, "Only format 0.1 is supported in this handler."
         attrs = Attributes({"version": "0.2"})
     elif name == "model_object" and attrs["class"] == "Universe":
         self.in_universe = 0
     elif self.in_universe == 1:
         if name == "array" and attrs["label"] == "cell":
             self.recording = "cell"
             self.cell = []
         elif name == "array" and attrs["label"] == "cell_active":
             self.recording = "cell_active"
             self.cell_active = []
     if self.recording is None:
         XMLFilterBase.startElement(self, name, attrs)
    def __init__(
            self, upstream, downstream, tag_name,
            layers_blacklist=None, layers_whitelist=None):
        XMLFilterBase.__init__(self, upstream)
        self._downstream = downstream
        self._accumulator = []

        assert layers_blacklist is not None or layers_whitelist is not None, \
            "either layers_blacklist OR layers_whitelist must be set"
        assert not (
            layers_blacklist is not None and
            layers_whitelist is not None), \
            "only either layers_blacklist OR layers_whitelist can be set"
        self.layers_blacklist = layers_blacklist
        self.layers_whitelist = layers_whitelist

        self.layers_path = []
        self.in_name = False
        self.tag_name = tag_name
        self.level = 0
示例#31
0
	def startElement(self, name, attrs):
		attnames = []
		if name == 'xcb':
			self.startScope(attrs['header'])
		elif name in ['struct', 'union', 'xidtype', 'enum', 'event', 'eventcopy', 'error', 'errorcopy']:
			self.declareType(attrs['name'])
			attnames = ['name']
			if name.endswith('copy'):
				attnames.append('ref')
		elif name == 'typedef':
			self.declareType(attrs['newname'])
			attnames = ['oldname', 'newname']
		elif name == 'valueparam':
			attnames = ['value-mask-type']
		elif attrs.has_key('type'):
			attnames = ['type']
		newattrs = {}
		for attname in attnames:
			newattrs[attname] = self.getQualifiedType(attrs[attname])
		if newattrs:
			attrs = AttributesUnion(attrs, **newattrs)
		XMLFilterBase.startElement(self, name, attrs)
示例#32
0
    def startElement(self, name, attrs):
        if name == 'task':
            self._dialogue = attrs.get('dialog')
        elif name == 'turn':
            self._turn_no = int(attrs.get('number'))
        elif name == 'utterance':
            self._full_line = []
            self._da_line_len = 0
            self._da_count = 0
        elif name == 'text' and attrs.get('type') == self.text_type:
            self._full_line = []
            self._whole_line = []
            self._catch_full_line = True
        elif name == 'dialogue_act':
            self._write_full_line = True
            self._da_count += 1
            self._da_attrs = attrs.copy()
        elif name == 'parametrized_act' and attrs.get('type') == self.text_type:
            self._eat_tag = True

        if not self._eat_tag:
            XMLFilterBase.startElement(self, name, attrs)
示例#33
0
文件: gensimple.py 项目: zhou0/ibus
 def __init__(self,
              parser=None,
              downstream=None,
              iso639=None,
              denylist=None,
              author=None,
              first=False):
     XMLFilterBase.__init__(self, parser)
     self.__downstream = downstream
     self.__iso639 = iso639
     self.__denylist = denylist
     self.__author = author
     self.__first = first
     self.__is_layout = False
     self.__is_description = False
     self.__is_config_item = False
     self.__is_variant = False
     self.__is_iso639 = False
     self.__is_name = False
     self.__layout = ''
     self.__description = ''
     self.__variant = ''
     self.__list_iso639 = []
     self.__list_iso639_for_variant = []
示例#34
0
def test_filter_basic():
    result = StringIO()
    gen = XMLGenerator(result)
    filter = XMLFilterBase()
    filter.setContentHandler(gen)

    filter.startDocument()
    filter.startElement("doc", {})
    filter.characters("content")
    filter.ignorableWhitespace(" ")
    filter.endElement("doc")
    filter.endDocument()

    return result.getvalue() == start + "<doc>content </doc>"
示例#35
0
 def __init__(self, upstream, downstream, limit=200):
     XMLFilterBase.__init__(self, upstream)
     self._count = 0
     self._limit = limit
     self._downstream = downstream
示例#36
0
 def endElementNS(self, name, qname):
     XMLFilterBase.endElementNS(self, name, qname)
     namespace, element = name
     if namespace == u'http://www.eucalyptus.com/ns/reporting/export/2012-08-24/' and element == u'Export':
         self.switchTarget( self.replyGenerator )
示例#37
0
	def characters(self, content):
		if len(self.header) == 1:
			XMLFilterBase.characters(self, content)
示例#38
0
 def startElementNS(self, name, qname, attrs):
     namespace, element = name
     if namespace == u'http://www.eucalyptus.com/ns/reporting/export/2012-08-24/' and element == u'Export':
         self.switchTarget( self.generator )
     XMLFilterBase.startElementNS(self, name, qname, attrs)
示例#39
0
 def startDocument(self):
     self.generator.startDocument()
     XMLFilterBase.startDocument(self)
 def processingInstruction(self, target, body):
     self._complete_text_node()
     XMLFilterBase.processingInstruction(self, target, body)
     return
示例#41
0
 def __init__(self, upstream, downstream):
     XMLFilterBase.__init__(self, upstream)
     self._downstream=downstream
     self._accumulator=[]
示例#42
0
    def test_filter_basic(self):
        result = BytesIO()
        gen = XMLGenerator(result)
        filter = XMLFilterBase()
        filter.setContentHandler(gen)

        filter.startDocument()
        filter.startElement("doc", {})
        filter.characters("content")
        filter.ignorableWhitespace(" ")
        filter.endElement("doc")
        filter.endDocument()

        self.assertEqual(result.getvalue(), start + b"<doc>content </doc>")
示例#43
0
    def test_filter_basic(self):
        result = BytesIO()
        gen = XMLGenerator(result)
        filter = XMLFilterBase()
        filter.setContentHandler(gen)

        filter.startDocument()
        filter.startElement("doc", {})
        filter.characters("content")
        filter.ignorableWhitespace(" ")
        filter.endElement("doc")
        filter.endDocument()

        self.assertEqual(result.getvalue(), start + b"<doc>content </doc>")
 def endElementNS(self, name, qname):
     self._complete_text_node()
     XMLFilterBase.endElementNS(self, name, qname)
     return
示例#45
0
 def characters(self, content):
     if len(self.header) == 1:
         XMLFilterBase.characters(self, content)
示例#46
0
 def __init__(self, upstream, downstream):
     XMLFilterBase.__init__(self, upstream)
     self._downstream = downstream
     self._accumulator = []
     return
示例#47
0
 def endElement(self, name):
     XMLFilterBase.endElement(self, name)
     if name == 'xcb':
         self.endScope()
示例#48
0
def test_filter_basic():
    result = StringIO()
    gen = XMLGenerator(result)
    filter = XMLFilterBase()
    filter.setContentHandler(gen)

    filter.startDocument()
    filter.startElement("doc", {})
    filter.characters("content")
    filter.ignorableWhitespace(" ")
    filter.endElement("doc")
    filter.endDocument()

    return result.getvalue() == start + "<doc>content </doc>"
 def parse(self, source):
     # import inspect; import pprint; pprint.pprint(inspect.stack())
     self._parent.setProperty(property_lexical_handler, self)
     # Delegate to XMLFilterBase for the rest
     XMLFilterBase.parse(self, source)
     return