Commits

Walter Dörwald committed 6c07be9

Knotenformatierfunktionen in presenters global gemacht, damit
sie die Exception-Klassen benutzen können.

Kleinere Bugs beseitigt.

Neues Entity dtd.

  • Participants
  • Parent commits 67f56cd

Comments (0)

Files changed (5)

 		self.element = element
 
 	def __str__(self):
-		return Error.__str__(self) + "element " + self.element._str() + " specified to be empty, but has content"
+		return Error.__str__(self) + "element %s specified to be empty, but has content" % presenters.strElementWithBrackets(self.element)
 
 class IllegalAttrError(Error):
 	"""
 			for element in namespace.elementsByName.values():
 				all[(element.name, element.namespace.prefix)] = element
 
-		presenter = presenters.NormalPresenter()
-
 		allkeys = all.keys()
 		allkeys.sort()
 		allAsList = []
 		for key in allkeys:
 			element = all[key]
-			allAsList.append(str(presenter.strElement(element)))
+			allAsList.append(str(presenters.strElementWithBrackets(element)))
 
-		s = Error.__str__(self) + "element <%s:%s> not allowed. " % (self.name[0], self.name[1])
-		#s = Error.__str__(self) + "element " + xsc._strName((self.name[0], self.name[1], 0)) + " not allowed. "
+		s = Error.__str__(self) + "element %s not allowed. " % presenters.strElementNameWithBrackets(self.name[0], self.name[1])
 		if allAsList:
 			s = s + "Allowed elements are: " + ", ".join(allAsList) + "."
 		else:
 		self.name = name
 
 	def __str__(self):
-		# List the element sorted by name
+		# List the procinsts sorted by name
 		all = {}
 		for namespace in xsc.namespaceRegistry.byPrefix.values():
 			for procinst in namespace.procInstsByName.values():
 		allAsList = []
 		for key in allkeys:
 			procinst = all[key]
-			allAsList.append(xsc.strProcInstTarget(procinst.name))
+			allAsList.append(str(presenters.strProcInstWithBrackets(procinst)))
 
-		s = Error.__str__(self) + "procinst " + xsc.strProcInstTarget(self.name[1]) + " not allowed. "
+		s = Error.__str__(self) + "procinst %s not allowed. " % presenters.strProcInstWithBrackets(self.name[0], self.name[1])
 		if allAsList:
-			s += "Allowed procinsts are: " + ", ".join(allAsList) + "."
+			s = s + "Allowed procinsts are: " + ", ".join(allAsList) + "."
 		else:
-			s += "There are no allowed procinsts."
+			s = s + "There are no allowed procinsts."
 		return s
 
 class IllegalElementNestingError(Error):
 		self.foundelement = foundelement
 
 	def __str__(self):
-		return Error.__str__(self) + "illegal element nesting (" + xsc._strNode(self.expectedelement) + " expected; " + xsc._strNode(self.foundelement) + " found)"
+		return Error.__str__(self) + "illegal element nesting (%s expected; %s found)" % (presenters.strElementWithBrackets(self.expectedelement), presenters.strElementWithBrackets(self.foundelement))
 
 class IllegalAttrNodeError(Error):
 	"""
 		self.name = name
 
 	def __str__(self):
-		entitynames = []
-		for namespacename in xsc.namespaceRegistry.byPrefix.keys():
-			namespace = xsc.namespaceRegistry.byPrefix[namespacename]
-			try:
-				entity = namespace.entitiesByName[self.name[1]]
-				entitynames.append(xsc.strEntity(entity.namespace.prefix, entity.name))
-			except KeyError: # this namespace doesn't have an entity with this name
-				pass
-		entitynames.sort()
+		# List the entities sorted by name
+		all = {}
+		for namespace in xsc.namespaceRegistry.byPrefix.values():
+			for entity in namespace.entitiesByName.values():
+				all[(entity.name, entity.namespace.prefix)] = entity
 
-		s = Error.__str__(self) + "entity " + xsc.strEntity(self.name[0], self.name[1]) + " not allowed. "
-		if entitynames:
-			s = s + "Allowed entities are: " + ", ".join(entitynames) + "."
+		allkeys = all.keys()
+		allkeys.sort()
+		allAsList = []
+		for key in allkeys:
+			entity = all[key]
+			allAsList.append(str(presenters.strEntity(entity)))
+
+		s = Error.__str__(self) + "entity %s not allowed. " % presenters.strEntityName(self.name[0], self.name[1])
+		if allAsList:
+			s = s + "Allowed entities are: " + ", ".join(allAsList) + "."
 		else:
 			s = s + "There are no allowed entities."
 		return s
 import sys
 import getopt
 import time
+import ansistyle
 from xist import xsc, html, publishers, url, utils, converters # don't do a subpackage import here, otherwise chaos will ensue, because XIST modules will be imported twice
 
 def extXSC2HTML(ext):
 	files.extend(args)
 
 	if files:
-		converter = converters.Transformer(mode)
+		converter = converters.Converter(mode)
 		for file in files:
 			inname = url.URL(file)
 			outname = globaloutname.clone()

xist/presenters.py

 	ascharref = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f<>\"&"
 	ascolor   = "\x09\x0a"
 
+def strElementName(namespacename=None, elementname=None):
+	s = ansistyle.Text()
+	if namespacename is not None:
+		s.append(
+			EnvTextForNamespace(EscInlineText(namespacename)),
+			EnvTextForColon(":")
+		)
+	if elementname is None:
+		elementname = "unnamed"
+	s.append(EnvTextForElementName(EscInlineText(elementname)))
+	return s
+
+def strElementNameWithBrackets(namespacename=None, elementname=None):
+	return ansistyle.Text(EnvTextForBracket("<"), strElementName(namespacename, elementname), EnvTextForBracket(">"))
+
+def strElement(node):
+	if hasattr(node, "namespace"):
+		namespacename = node.namespace.prefix
+	else:
+		namespacename = None
+	if hasattr(node, "name"):
+		elementname = node.name
+	else:
+		elementname = node.__class__.__name__
+	return strElementName(namespacename, elementname)
+
+def strElementWithBrackets(node):
+	return ansistyle.Text(EnvTextForBracket("<"), strElement(node), EnvTextForBracket(">"))
+
+def strEntityName(namespacename=None, entityname=None):
+	s = ansistyle.Text("&")
+	if namespacename is not None:
+		s.append(
+			EnvTextForNamespace(EscInlineText(namespacename)),
+			EnvTextForColon(":")
+		)
+	if entityname is None:
+		entityname = "unnamed"
+	s.append(
+		EnvTextForEntityName(EscInlineText(entityname)),
+		";"
+	)
+	return s
+
+def strEntity(node):
+	if hasattr(node, "namespace"):
+		namespacename = node.namespace.prefix
+	else:
+		namespacename = None
+	if hasattr(node, "name"):
+		entityname = node.name
+	else:
+		entityname = node.__class__.__name__
+	return strEntityName(namespacename, entityname)
+
+def strProcInstName(procinstname=None):
+	if procinstname is None:
+		procinstname = "unnamed"
+	return EnvTextForProcInstTarget(EscInlineText(procinstname))
+
+def strProcInst(node):
+	if hasattr(node, "name"):
+		procinstname = node.name
+	else:
+		procinstname = node.__class__.__name__
+	return strProcInstName(procinstname)
+
+def strProcInstNameWithBrackets(procinstname=None):
+	return ansistyle.Text(EnvTextForBracket("<"), EnvTextForQuestion("?"), strProcInstName(procinstname), EnvTextForQuestion("?"), EnvTextForBracket(">"))
+
+def strProcInstWithBrackets(node):
+	return ansistyle.Text(EnvTextForBracket("<"), EnvTextForQuestion("?"), strProcInst(node), EnvTextForQuestion("?"), EnvTextForBracket(">"))
+
 class Presenter:
 	"""
 	base class for all presenters.
 		self.buffer = ansistyle.Stream(ansistyle.StringBuffer())
 		self.inAttr = 0
 
-	def strElement(self, node):
-		s = ansistyle.Text()
-		if hasattr(node, "namespace"):
-			s.append(
-				EnvTextForNamespace(EscInlineText(node.namespace.prefix)),
-				self.strColon()
-			)
-		if hasattr(node, "name"):
-			name = node.name
-		else:
-			name = node.__class__.name
-		s.append(EnvTextForElementName(EscInlineText(name)))
-		return s
-
-	def strEntity(self, node):
-		s = ansistyle.Text("&")
-		if hasattr(node, "namespace"):
-			s.append(
-				EnvTextForNamespace(EscInlineText(node.namespace.prefix)),
-				EnvTextForColon(":")
-			)
-		if hasattr(node, "name"):
-			name = node.name
-		else:
-			name = node.__class__.name
-		s.append(
-			EnvTextForEntityName(EscInlineText(name)),
-			";"
-		)
-		return s
-
 	def strAttrName(self, attrname):
 		return EnvTextForAttrName(EscInlineText(attrname))
 
 
 	def presentElement(self, node):
 		if node.empty:
-			self.buffer.append(self.strBracketOpen(), self.strElement(node))
+			self.buffer.append(self.strBracketOpen(), strElement(node))
 			self._writeAttrs(node.attrs)
 			self.buffer.append(self.strSlash(), self.strBracketClose())
 		else:
-			self.buffer.append(self.strBracketOpen(), self.strElement(node))
+			self.buffer.append(self.strBracketOpen(), strElement(node))
 			self._writeAttrs(node.attrs)
 			self.buffer.append(self.strBracketClose())
 			for child in node:
 				child.present(self)
-			self.buffer.append(self.strBracketOpen(), self.strSlash(), self.strElement(node), self.strBracketClose())
+			self.buffer.append(self.strBracketOpen(), self.strSlash(), strElement(node), self.strBracketClose())
 
 	def presentEntity(self, node):
-		self.buffer.append(self.strEntity(node))
+		self.buffer.append(strEntity(node))
 
 	def presentNull(self, node):
-		self.buffer.append(self.strBracketOpen(), self.strElement(node), self.strSlash(), self.strBracketClose())
+		self.buffer.append(self.strBracketOpen(), strElement(node), self.strSlash(), self.strBracketClose())
 
 	def presentAttr(self, node):
 		self.inAttr = 1
 
 class smil(xsc.Entity):
 	def convert(self, converter=None):
-		return html.span(html.abbr("SMIL", title="Synchronized Multimedia Integration Language", lang="en"), class_="caps")
+		return html_.span(html_.abbr("SMIL", title="Synchronized Multimedia Integration Language", lang="en"), class_="caps")
 	def asPlainString(self):
 		return u"SMIL"
 
+class dtd(xsc.Entity):
+	def convert(self, converter=None):
+		return html_.span(html_.abbr("DTD", title="Document Type Definiton", lang="en"), class_="caps")
+	def asPlainString(self):
+		return u"DTD"
+
 class PHP(xsc.ProcInst):
 	"""
 	PHP processing instruction (must be used with a target)
 			return cmp(self._content, other)
 
 	def __contains__(self, char):
-		return char in self._content
+		return utils.stringFromCode(char) in self._content
 
 	def __hash__(self):
 		return hash(self._content)
 		return self._content.count(sub, start, end)
 
 	def endswith(self, suffix, start=0, end=sys.maxint):
-		return self._content.endswith(suffix, start, end)
+		return self._content.endswith(utils.stringFromCode(suffix), start, end)
 
 	def find(self, sub, start=0, end=sys.maxint):
-		return self._content.find(sub, start, end)
+		return self._content.find(utils.stringFromCode(sub), start, end)
 
 	def index(self, sub, start=0, end=sys.maxint):
-		return self._content.index(sub, start, end)
+		return self._content.index(utils.stringFromCode(sub), start, end)
 
 	def isalpha(self):
 		return self._content.isalpha()
 		return self.__class__(self._content.lstrip())
 
 	def replace(self, old, new, maxsplit=-1):
-		return self.__class__(self._content.replace(old, new, maxsplit))
+		return self.__class__(self._content.replace(utils.stringFromCode(old), utils.stringFromCode(new), maxsplit))
 
 	def rfind(self, sub, start=0, end=sys.maxint):
-		return self._content.rfind(sub, start, end)
+		return self._content.rfind(utils.stringFromCode(sub), start, end)
 
 	def rindex(self, sub, start=0, end=sys.maxint):
-		return self._content.rindex(sub, start, end)
+		return self._content.rindex(utils.stringFromCode(sub), start, end)
 
 	def rjust(self, width):
 		return self.__class__(self._content.rjust(width))
 		return Frag(self._content.splitlines(keepends))
 
 	def startswith(self, prefix, start=0, end=sys.maxint):
-		return self._content.startswith(prefix, start, end)
+		return self._content.startswith(utils.stringFromCode(prefix), start, end)
 
 	def strip(self):
 		return self.__class__(self._content.strip())
 	"""
 	XML header version 1.0
 	"""
+	name = None # don't register this ProcInst, because it will never be parsed from a file, this is just a convenience class
 	def __init__(self):
 		XML.__init__(self, 'version="1.0"')