Пример #1
0
	def entity(self, data):
		node = self.pool.entity(data)
		if self.loc:
			node.startloc = xsc.Location(self._url, *self._position)
		node.parsed(self, "entity")
		if self._inattr:
			self._stack[-1].append(node)
		elif not self._indoctype:
			return ("entitynode", node)
Пример #2
0
	def procinst(self, data):
		node = self.pool.procinst(*data)
		if self.loc:
			node.startloc = xsc.Location(self._url, *self._position)
		node.parsed(self, "procinst")
		if self._inattr:
			self._stack[-1].append(node)
		elif not self._indoctype:
			return ("procinstnode", node)
Пример #3
0
	def enterattrns(self, data):
		attrkey = self.pool.attrkey(*data)
		self._stack[-1].attrs[attrkey] = ()
		node = self._stack[-1].attrs[attrkey]
		if self.loc:
			node.startloc = xsc.Location(self._url, *self._position)
		self._stack.append(node)
		self._inattr = True
		node.parsed(self, "enterattrns")
Пример #4
0
	def text(self, data):
		node = xsc.Text(data)
		if self.loc:
			node.startloc = xsc.Location(self._url, *self._position)
		node.parsed(self, "text")
		if self._inattr:
			self._stack[-1].append(node)
		elif not self._indoctype:
			return ("textnode", node)
Пример #5
0
	def begindoctype(self, data):
		if data["publicid"]:
			content = f'{data["name"]} PUBLIC "{data["publicid"]}" "{data["systemid"]}"'
		elif data["systemid"]:
			content = f'{data["name"]} SYSTEM "{data["systemid"]}"'
		else:
			content = data["name"]
		node = xsc.DocType(content)
		if self.loc:
			node.startloc = xsc.Location(self._url, *self._position)
		self.doctype = node
		self._indoctype = True
Пример #6
0
 def toxist(node):
     if isinstance(node, nodes.Text):
         return xsc.Text(str(node.astext()))
     else:
         e = elements[node.__class__.__name__](toxist(child)
                                               for child in node.children)
         e.startloc = xsc.Location(node.source, node.line)
         for (attrkey, attrvalue) in node.attlist():
             if attrkey in e.Attrs:
                 if isinstance(attrvalue, list):
                     attrvalue = " ".join(attrvalue)
                 e.attrs[attrkey] = attrvalue
         return e
Пример #7
0
def test_locationeq():
    l1 = xsc.Location(url="http://gurk.com", line=42, col=666)
    l2 = xsc.Location(url="http://gurk.com", line=42, col=666)
    l3 = xsc.Location(url="http://hurz.com", line=42, col=666)
    l4 = xsc.Location(url="http://gurk.com", line=43, col=666)
    l5 = xsc.Location(url="http://gurk.com", line=43, col=667)
    l6 = xsc.Location(url="http://gurk.com")
    assert l1 == l2
    assert l1 != l3
    assert l1 != l4
    assert l1 != l5
    assert l1 != l6
Пример #8
0
	def endtagns(self, data):
		node = self._stack.pop()
		if self.loc:
			node.endloc = xsc.Location(self._url, *self._position)
		node.parsed(self, "endtagns")
		return ("leaveelementnode", node)
Пример #9
0
	def enterstarttagns(self, data):
		node = self.pool.element(*data)
		if self.loc:
			node.startloc = xsc.Location(self._url, *self._position)
		self._stack.append(node)
		node.parsed(self, "starttagns")
Пример #10
0
	def xmldecl(self, data):
		node = xml.XML(version=data["version"], encoding=data["encoding"], standalone=data["standalone"])
		if self.loc:
			node.startloc = xsc.Location(self._url, *self._position)
		return ("xmldeclnode", node)
Пример #11
0
def test_locationoffset():
    l1 = xsc.Location(url="http://gurk.com", line=42, col=666)
    assert l1 == l1.offset(0)
    l2 = l1.offset(1)
    assert l1.url == l2.url
    assert l1.line + 1 == l2.line