예제 #1
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)
 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)
예제 #3
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')
예제 #4
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 test_filter_basic(self):
        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()

        self.assertEqual(result.getvalue(), start + "<doc>content </doc>")
예제 #6
0
파일: test_sax.py 프로젝트: Eyepea/cpython
    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>")
예제 #7
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)
예제 #8
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)
예제 #9
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)
예제 #10
0
 def startElement(self, name, attrs):
     self._complete_text_node()
     XMLFilterBase.startElement(self, name, attrs)
     return
 def startElement(self, name, attrs):
     self._complete_text_node()
     XMLFilterBase.startElement(self, name, attrs)
     return
예제 #12
0
# regression test for SAX 2.0
예제 #13
0
 def endElement(self, name):
     if self.in_universe >= 0:
         self.in_universe -= 1
         if self.in_universe == -1:
             # send the recorded tags in the new format
             if not (self.cell is None and self.cell_active is None):
                 if self.cell is None:
                     self.cell = numpy.identity(3, float)*20.0
                 if self.cell_active is None:
                     self.cell_active = numpy.zeros(3, bool)
                 XMLFilterBase.startElement(self, "unit_cell", Attributes({"label": "cell"}))
                 # matrix
                 XMLFilterBase.startElement(self, "array", Attributes({"label": "matrix"}))
                 XMLFilterBase.startElement(self, "shape", Attributes({}))
                 XMLFilterBase.characters(self, "3 3")
                 XMLFilterBase.endElement(self, "shape")
                 XMLFilterBase.startElement(self, "cells", Attributes({}))
                 XMLFilterBase.characters(self, " ".join(str(v) for v in self.cell.ravel()))
                 XMLFilterBase.endElement(self, "cells")
                 XMLFilterBase.endElement(self, "array")
                 # matrix
                 XMLFilterBase.startElement(self, "array", Attributes({"label": "active"}))
                 XMLFilterBase.startElement(self, "shape", Attributes({}))
                 XMLFilterBase.characters(self, "3")
                 XMLFilterBase.endElement(self, "shape")
                 XMLFilterBase.startElement(self, "cells", Attributes({}))
                 XMLFilterBase.characters(self, " ".join(str(v) for v in self.cell_active))
                 XMLFilterBase.endElement(self, "cells")
                 XMLFilterBase.endElement(self, "array")
                 # end unit cell
                 XMLFilterBase.endElement(self, "unit_cell")
     if self.recording is None:
         XMLFilterBase.endElement(self, name)
     else:
         if name == "array" and self.recording == "cell":
             self.recording = None
             words = (" ".join(self.cell)).split()[2:]
             self.cell = numpy.array([float(v) for v in words])
             self.cell.shape = (3,3)
         if name == "array" and self.recording == "cell_active":
             self.recording = None
             words = (" ".join(self.cell_active)).split()[1:]
             self.cell_active = numpy.array([eval(v) for v in words])
             self.cell_active.shape = (3,)