Walter Dörwald avatar Walter Dörwald committed 7f40b6f

transform heißt jetzt convert.

Comments (0)

Files changed (13)

 " inside attributes.
 
 All the asHTML methods now have an additional argument
-transformer which defaults to None. This makes it possible
+converter which defaults to None. This makes it possible
 to implement different processing modes or stages
 for new elements. All currently implemented elements and
 entities ignore this argument, but pass it on
 in the call to their childrens' asHTML method.
 As the name asHTML no longer makes sense, asHTML
-has been renamed to transform.
+has been renamed to convert.
 
 There is now a tools dtd2xsc.py in the tools directory
 that creates a skeleton XIST module for a dtd
 (this requires xmlproc from the PyXML package).
 
 New preliminary module for DocBook 4.12.
-(Incomplete: transform methods and Unicode character
+(Incomplete: convert methods and Unicode character
 entities are missing)
 
 New module that implements the W3C Ruby draft:
 
 make.py has a new option --files/-f. The argument
 is a file containing a list of filenames (one
-name per line), that should be transformed.
+name per line) that should be transformed.
 
 New in 0.4.7
 ------------
 	empty = 0
 	attrHandlers = {"var": xsc.TextAttr}
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		cases = self.find(type=case)
 
 		return xsc.Null
 	empty = 0
 	attrHandlers = {"case": xsc.TextAttr}
 
-	def transform(self, transformer=None):
-		return self.content.transform(transformer)
+	def convert(self, converter=None):
+		return self.content.convert(converter)
 
 class If(xsc.Element):
 	empty = 0
 	attrHandlers = {"cond": CondAttr}
 	name = "if"
 
-	def transform(self, transformer=None):
-		intruecondition = self.__testCond(self["cond"], transformer)
+	def convert(self, converter=None):
+		intruecondition = self.__testCond(self["cond"], converter)
 		truecondition = xsc.Frag()
 		for child in self.content:
 			if isinstance(child, ElIf):
 			else:
 				if intruecondition:
 					truecondition.append(child)
-		return truecondition.transform(transformer)
+		return truecondition.convert(converter)
 
-	def __testCond(self, attr, transformer):
-		cond = attr.transform(transformer).asPlainString()
+	def __testCond(self, attr, converter):
+		cond = attr.convert(converter).asPlainString()
 		result = eval(str(cond), procinst.__dict__)
 		return result
 
 	attrHandlers = {"cond": CondAttr}
 	name = "elif"
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return xsc.Null
 
 class Else(xsc.Element):
 	empty = 1
 	name = "else"
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return xsc.Null
 
 namespace = xsc.Namespace("cond", "http://www.livinglogic.de/DTDs/cond.dtd", vars())

xist/converter.py

+#! /usr/bin/env python
+
+## Copyright 1999-2001 by LivingLogic AG, Bayreuth, Germany.
+## Copyright 1999-2001 by Walter D�rwald
+##
+## All Rights Reserved
+##
+## Permission to use, copy, modify, and distribute this software and its documentation
+## for any purpose and without fee is hereby granted, provided that the above copyright
+## notice appears in all copies and that both that copyright notice and this permission
+## notice appear in supporting documentation, and that the name of LivingLogic AG or
+## the author not be used in advertising or publicity pertaining to distribution of the
+## software without specific, written prior permission.
+##
+## LIVINGLOGIC AG AND THE AUTHOR DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+## INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+## LIVINGLOGIC AG OR THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+## DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+## IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+## IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+"""
+This modules contains the base class for the converter objects
+used in the call to the convert method.
+"""
+
+__version__ = tuple(map(int, "$Revision$"[11:-2].split(".")))
+# $Source$
+
+class Converter:
+	def __init__(self, mode=None):
+		self.mode = mode
 class checkbox(xsc.Element):
 	attrHandlers = {"name": xsc.TextAttr, "value": xsc.TextAttr}
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = html.input(**self.attrs)
 		e["type"] = "checkbox"
 		if self.hasAttr("value") and int(self["value"].asPlainString()) != 0:
 			e["checked"] = None
 		else:
 			del e["checked"]
-		return e.transform(transformer)
+		return e.convert(converter)
 
 class edit(xsc.Element):
 	attrHandlers = {"name": xsc.TextAttr, "value": xsc.TextAttr, "size": xsc.TextAttr}
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = html.input(**self.attrs)
-		return e.transform(transformer)
+		return e.convert(converter)
 
 class memo(xsc.Element):
 	attrHandlers = {"name": xsc.TextAttr, "value": xsc.TextAttr}
 	attrHandlers.update(html.textarea.attrHandlers)
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = html.textarea()
 		if self.hasAttr("value"):
 			e.extend(self["value"])
 		for attr in self.attrs.keys():
 			if attr != "value":
 				e[attr] = self[attr]
-		return e.transform(transformer)
+		return e.convert(converter)
 
 class hidden(xsc.Element):
 	attrHandlers = {"name": xsc.TextAttr, "value": xsc.TextAttr}
 	def asPlainString(self):
 		return u""
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = html.input(type="hidden", name=self["name"])
 		if self.hasAttr("value"):
 			e["value"] = self["value"]
-		return e.transform(transformer)
+		return e.convert(converter)
 
 namespace = xsc.Namespace("form", "http://www.livinglogic.de/DTDs/form.dtd", vars())
 	empty = 0
 	attrHandlers = i18n
 
-	def transform(self, transformer=None):
-		return title(self.content.transform(transformer).asPlainString(), **self.attrs)
+	def convert(self, converter=None):
+		return title(self.content.convert(converter).asPlainString(), **self.attrs)
 
 class meta(xsc.Element):
 	"""
 from xist import xsc, html
 
 class rmi(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html.abbr("RMI", title="Remote Method Invocation", lang="en")
 	def asPlainString(self):
 		return u"RMI"
 
 class jfc(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html.abbr("JFC", title="Java Foundation Classes", lang="en")
 	def asPlainString(self):
 		return u"JFC"
 
 class awt(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html.abbr("AWT", title="Abstract Window Toolkit", lang="en")
 	def asPlainString(self):
 		return u"AWT"
 
 class jdbc(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html.abbr("JDBC", title="Java Database Connectivity", lang="en")
 	def asPlainString(self):
 		return u"JDBC"
 
 class jndi(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html.abbr("JNDI", title="Java Naming and Directory Interface", lang="en")
 	def asPlainString(self):
 		return u"JNDI"
 
 class jpda(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html.abbr("JPDA", title="Java Platform Debugger Architecture", lang="en")
 	def asPlainString(self):
 		return u"JPDA"
 
 class jvmpi(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html.abbr("JVMPI", title="Java Virtual Machine Profiler Interface", lang="en")
 	def asPlainString(self):
 		return u"JVMPI"
 
 class jni(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html.abbr("JNI", title="Java Native Interface", lang="en")
 	def asPlainString(self):
 		return u"JNI"
 
 class ejb(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html.abbr("EJB", title="Enterprice Java Beans", lang="en")
 	def asPlainString(self):
 		return u"EJB"
 
 class jgl(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html.abbr("JGL", title="Java Generic Library", lang="en")
 	def asPlainString(self):
 		return u"JGL"
 import sys
 import getopt
 import time
-from xist import xsc, html, publishers, url, utils, color, transformers # don't do a subpackage import here, otherwise chaos will ensue, because XIST modules will be imported twice
+from xist import xsc, html, publishers, url, utils, color, converters # don't do a subpackage import here, otherwise chaos will ensue, because XIST modules will be imported twice
 
 def extXSC2HTML(ext):
 	try:
 	files.extend(args)
 
 	if files:
-		transformer = transformers.Transformer(mode)
+		converter = converters.Transformer(mode)
 		for file in files:
 			inname = url.URL(file)
 			outname = globaloutname.clone()
 			e_in = xsc.xsc.parse(inname)
 			t2 = time.clock()
 			xsc.xsc.pushURL(inname)
-			e_out = e_in.transform(transformer)
+			e_out = e_in.convert(converter)
 			t3 = time.clock()
 			p = publishers.FilePublisher(utils.forceopen(outname.asPlainString(), "wb", 65536), encoding=encoding, XHTML=XHTML)
 			e_out.publish(p)
 			t4 = time.clock()
 			size = p.tell()
-			sys.stderr.write("XSC(encoding=%s, XHTML=%s): %s->%s: %s (parse %ss; transform %ss; save %ss)\n" % (ColoredString(p.encoding), ColoredNumber(p.XHTML), ColoredURL(inname), ColoredURL(outname), ColoredNumber(size), ColoredNumber("%.02f" % (t2-t1)), ColoredNumber("%.02f" % (t3-t2)), ColoredNumber("%.02f" % (t4-t3))))
+			sys.stderr.write("XSC(encoding=%s, XHTML=%s): %s->%s: %s (parse %ss; convert %ss; save %ss)\n" % (ColoredString(p.encoding), ColoredNumber(p.XHTML), ColoredURL(inname), ColoredURL(outname), ColoredNumber(size), ColoredNumber("%.02f" % (t2-t1)), ColoredNumber("%.02f" % (t3-t2)), ColoredNumber("%.02f" % (t4-t3))))
 			xsc.xsc.popURL()
 	else:
 		sys.stderr.write("XSC: no files to convert.\n")
 	del attrHandlers["name"]
 	del attrHandlers["content"]
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = html.meta(**self.attrs)
 		e["http-equiv"] = "Content-Type"
 		e["content"] = "text/html"
-		return e.transform(transformer)
+		return e.convert(converter)
 
 class keywords(html.meta):
 	"""
 	del attrHandlers["name"]
 	del attrHandlers["content"]
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = html.meta(**self.attrs)
 		e["name"] = "keywords"
-		e["content"] = self.content.transform(transformer).asPlainString()
-		return e.transform(transformer)
+		e["content"] = self.content.convert(converter).asPlainString()
+		return e.convert(converter)
 
 class description(html.meta):
 	"""
 	del attrHandlers["name"]
 	del attrHandlers["content"]
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = html.meta(**self.attrs)
 		e["name"] = "description"
-		e["content"] = self.content.transform(transformer).asPlainString()
-		return e.transform(transformer)
+		e["content"] = self.content.convert(converter).asPlainString()
+		return e.convert(converter)
 
 class stylesheet(html.link):
 	"""
 	del attrHandlers["rel"]
 	del attrHandlers["type"]
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = html.link(**self.attrs)
 		e["rel"] = "stylesheet"
 		e["type"] = "text/css"
-		return e.transform(transformer)
+		return e.convert(converter)
 
 class made(html.link):
 	"""
 	attrHandlers = html.link.attrHandlers.copy()
 	del attrHandlers["rel"]
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = html.link(**self.attrs)
 		e["rel"] = "made"
 		e["href"] = ("mailto:", e["href"])
-		return e.transform(transformer)
+		return e.convert(converter)
 
 namespace = xsc.Namespace("meta", "http://www.livinglogic.de/DTDs/meta.dtd", vars())
 
 	empty = 0
 	defaults = {"cellpadding": 0, "cellspacing": 0, "border": 0}
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = html_.table(*self.content, **self.attrs)
 		e.copyDefaultAttrs(self.defaults)
-		return e.transform(transformer)
+		return e.convert(converter)
 
 class plainbody(html_.body):
 	"""
 	empty = 0
 	defaults = {"leftmargin": 0, "topmargin": 0, "marginheight": 0, "marginwidth": 0}
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = html_.body(*self.content, **self.attrs)
 		e.copyDefaultAttrs(self.defaults)
-		return e.transform(transformer)
+		return e.convert(converter)
 
 class z(xsc.Element):
 	"""
 	"""
 	empty = 0
 
-	def transform(self, transformer=None):
-		e = xsc.Frag(u"�", self.content.transform(transformer), u"�")
+	def convert(self, converter=None):
+		e = xsc.Frag(u"�", self.content.convert(converter), u"�")
 
 		return e
 
 	empty = 1
 	attrHandlers = {"href": xsc.URLAttr}
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		size = self["href"].FileSize()
 		if size is not None:
 			return xsc.Text(size)
 	empty = 1
 	attrHandlers = {"href": xsc.URLAttr, "format": xsc.TextAttr}
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return xsc.Text(self["href"].FileTime())
 
 class time(xsc.Element):
 	"""
-	the current time (i.e. the time when transform() is called). You can specify the
+	the current time (i.e. the time when convert() is called). You can specify the
 	format of the string in the attribute format, which is a strftime() compatible
 	string.
 	"""
 	empty = 1
 	attrHandlers = {"format": xsc.TextAttr}
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		if self.hasAttr("format"):
-			format = self["format"].transform(transformer).asPlainString()
+			format = self["format"].convert(converter).asPlainString()
 		else:
 			format = "%d. %b. %Y, %H:%M"
 
 	"""
 	empty = 0
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return xsc.Null
 
 class pixel(html_.img):
 	attrHandlers.update({"color": xsc.ColorAttr})
 	del attrHandlers["src"]
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = autoimg()
 		color = "dot_clear"
 		for attr in self.attrs.keys():
 			e["alt"] = u""
 		e["src"] = ("*/Images/Pixels/", color, ".gif")
 
-		return e.transform(transformer)
+		return e.convert(converter)
 
 class caps(xsc.Element):
 	"""
 
 	lowercase = string.lowercase + ' '
 
-	def transform(self, transformer=None):
-		e = self.content.transform(transformer).asPlainString()
+	def convert(self, converter=None):
+		e = self.content.convert(converter).asPlainString()
 		result = xsc.Frag()
 		if e: # if we have nothing to do, we skip everything to avoid errors
 			collect = ""
 class endash(xsc.Element):
 	empty = 1
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return xsc.Text("-")
 
 	def asPlainString(self):
 class emdash(xsc.Element):
 	empty = 1
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return xsc.Text("-")
 
 	def asPlainString(self):
 	empty = 1
 	attrHandlers = {"src": xsc.URLAttr}
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = xsc.xsc.parse(self["src"].forInput())
 
-		return e.transform(transformer)
+		return e.convert(converter)
 
 class par(html_.div):
 	empty = 0
 	attrHandlers = html_.div.attrHandlers.copy()
 	attrHandlers.update({"noindent": xsc.TextAttr})
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = html_.div(*self.content)
 		indent = 1
 		for attr in self.attrs.keys():
 				e[attr] = self[attr]
 		if indent is not None:
 			e["class"] = "indent"
-		return e.transform(transformer)
+		return e.convert(converter)
 
 class autoimg(html_.img):
 	"""
 	<code>width</code> and <code>height</code>, i.e. you could make your image twice
 	as wide with <code>width="2*%(width)d"</code>.</par>
 	"""
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		e = html_.img(**self.attrs)
-		e._addImageSizeAttributes(transformer, "src", "width", "height")
-		return e.transform(transformer)
+		e._addImageSizeAttributes(converter, "src", "width", "height")
+		return e.convert(converter)
 
 class autoinput(html_.input):
 	"""
 	with the ability to automatically set the size, if this element
 	has <code>type=="image"</code>.
 	"""
-	def transform(self, transformer=None):
-		if self.hasAttr("type") and self["type"].transform(transformer).asPlainString() == u"image":
+	def convert(self, converter=None):
+		if self.hasAttr("type") and self["type"].convert(converter).asPlainString() == u"image":
 			e = html_.input(*self.content, **self.attrs)
-			e._addImageSizeAttributes(transformer, "src", "size", None) # no height
-			return e.transform(transformer)
+			e._addImageSizeAttributes(converter, "src", "size", None) # no height
+			return e.convert(converter)
 		else:
-			return html.img.transform(self, transformer)
+			return html.img.convert(self, converter)
 
 class loremipsum(xsc.Element):
 	empty = 1
 
 	text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diem nonummy nibh euismod tincidnut ut lacreet dolore magna aliguam erat volutpat. Ut wisis enim ad minim veniam, quis nostrud exerci tution ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis te feugifacilisi. Duis antem dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zril delinit au gue duis dolore te feugat nulla facilisi."
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		if self.hasAttr("len"):
 			text = self.text[:self["len"].asInt()]
 		else:
 	empty = 1
 	attrHandlers = {"href": xsc.URLAttr}
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		url = self["href"]
 		e = html_.html(
 			html_.head(html_.title("Redirection")),
 				html_.a(url, href=url)
 			)
 		)
-		return e.transform(transformer)
+		return e.convert(converter)
 
 # Control characters (not part of HTML)
 class lf(xsc.Entity): "line feed"; codepoint = 10
 class esc(xsc.Entity): "escape"; codepoint = 27
 
 class html(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("HTML", title="Hypertext Markup Language", lang="en")
 	def asPlainString(self):
 		return u"HTML"
 
 class xml(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("XML", title="Extensible Markup Language", lang="en")
 	def asPlainString(self):
 		return u"XML"
 
 class css(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("CSS", title="Cascading Style Sheet", lang="en")
 	def asPlainString(self):
 		return u"CSS"
 
 class cgi(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("CGI", title="Common Gateway Interface", lang="en")
 	def asPlainString(self):
 		return u"CGI"
 
 class www(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("WWW", title="World Wide Web", lang="en")
 	def asPlainString(self):
 		return u"WWW"
 
 class pdf(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("PDF", title="Protable Document Format", lang="en")
 	def asPlainString(self):
 		return u"PDF"
 
 class url(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("URL", title="Uniform Resource Locator", lang="en")
 	def asPlainString(self):
 		return u"URL"
 
 class http(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("HTTP", title="Hypertext Transfer Protocol", lang="en")
 	def asPlainString(self):
 		return u"HTTP"
 
 class smtp(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("SMTP", title="Simple Mail Transfer Protocol", lang="en")
 	def asPlainString(self):
 		return u"SMTP"
 
 class ftp(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("FTP", title="File Transfer Protocol", lang="en")
 	def asPlainString(self):
 		return u"FTP"
 
 class pop3(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("POP3", title="Post Office Protocol 3", lang="en")
 	def asPlainString(self):
 		return u"POP3"
 
 class cvs(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("CVS", title="Concurrent Versions System", lang="en")
 	def asPlainString(self):
 		return u"CVS"
 
 class faq(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("FAQ", title="Frequently Asked Question", lang="en")
 	def asPlainString(self):
 		return u"FAQ"
 
 class gnu(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("GNU", title="GNU's Not UNIX", lang="en")
 		# we could do it ;): return html_.abbr("GNU", title=(self, "'s Not UNIX"), lang="en")
 	def asPlainString(self):
 		return u"GNU"
 
 class dns(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("DNS", title="Domain Name Service", lang="en")
 	def asPlainString(self):
 		return u"DNS"
 
 class ppp(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("PPP", title="Domain Name Service", lang="en")
 	def asPlainString(self):
 		return u"PPP"
 
 class isdn(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.abbr("ISDN", title="Integrated Services Digital Network", lang="en")
 	def asPlainString(self):
 		return u"ISDN"
 
 class corba(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.span(html_.abbr("CORBA", title="Common Object Request Broker Architecture", lang="en"), class_="caps")
 	def asPlainString(self):
 		return u"CORBA"
 
 class wap(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.span(html_.abbr("WAP", title="Wireless Application Protocol", lang="en"), class_="caps")
 	def asPlainString(self):
 		return u"WAP"
 
 class wml(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.span(html_.abbr("WML", title="Wireless Markup Language", lang="en"), class_="caps")
 	def asPlainString(self):
 		return u"WML"
 
 class mac(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.span(html_.abbr("MAC", title="Media Access Control", lang="en"), class_="caps")
 	def asPlainString(self):
 		return u"MAC"
 
 class nat(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.span(html_.abbr("NAT", title="Network Address Translation", lang="en"), class_="caps")
 	def asPlainString(self):
 		return u"NAT"
 
 class sql(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.span(html_.abbr("SQL", title="Structured Query Language", lang="en"), class_="caps")
 	def asPlainString(self):
 		return u"SQL"
 
 class xsl(xsc.Entity):
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return html_.span(html_.abbr("XSL", title="Extensible Stylesheet Language", lang="en"), class_="caps")
 	def asPlainString(self):
 		return u"XSL"
 
 class smil(xsc.Entity):
-	def asHTML(self):
+	def convert(self, converter=None):
 		return html.span(html.abbr("SMIL", title="Synchronized Multimedia Integration Language", lang="en"), class_="caps")
 	def asPlainString(self):
 		return u"SMIL"

xist/transformers.py

-#! /usr/bin/env python
-
-## Copyright 1999-2001 by LivingLogic AG, Bayreuth, Germany.
-## Copyright 1999-2001 by Walter D�rwald
-##
-## All Rights Reserved
-##
-## Permission to use, copy, modify, and distribute this software and its documentation
-## for any purpose and without fee is hereby granted, provided that the above copyright
-## notice appears in all copies and that both that copyright notice and this permission
-## notice appear in supporting documentation, and that the name of LivingLogic AG or
-## the author not be used in advertising or publicity pertaining to distribution of the
-## software without specific, written prior permission.
-##
-## LIVINGLOGIC AG AND THE AUTHOR DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-## INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-## LIVINGLOGIC AG OR THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
-## DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-## IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
-## IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-"""
-This modules contains the base class for the transformer objects
-used in the call to the transform method.
-"""
-
-__version__ = tuple(map(int, "$Revision$"[11:-2].split(".")))
-# $Source$
-
-class Transformer:
-	def __init__(self, mode=None):
-		self.mode = mode
 
 	def funcify(self, name="__"):
 		self.indent()
-		self.lines.insert(0, [u"", u"def " + name + u"(transformer=None):"])
+		self.lines.insert(0, [u"", u"def " + name + u"(converter=None):"])
 
 	def asString(self):
 		v = []
 	encoding = "utf-8"
 
 	def respondToGet(self, trans):
-		trans._response.write(self.content(trans).transformer(None).asBytes(encoding=self.encoding))
+		trans._response.write(self.content(trans).converter(None).asBytes(encoding=self.encoding))
 
 	def content(self, trans):
 		return xsc.Null
 In XIST you're not limited to the HTML element types.
 You can define your own! To be able to convert these
 new element types to a HTML object tree, you must implement
-the method transform, and you must derive your class from
+the method convert, and you must derive your class from
 xsc.Element as in the following example:
 
 	class cool(xsc.Element):
 		empty = 1
 
-		def transform(self, transformer=None):
+		def convert(self, converter=None):
 			return html.b("Python is cool!")
 
 Using this element is as simple as this:
 	e = cool()
-	print e.transform().asString()
+	print e.convert().asString()
 
-(The additional argument transformer allows you to implement
+(The additional argument converter allows you to implement
 different processing modes or stages)
 
 The class variable empty in the above example specifies
 
 There is another situation where you will want to manually
 push an URL onto the stack: When some of your own elements
-generate new URLs in their transform() methods. As this
+generate new URLs in their convert() methods. As this
 conversion happens sometime after the file is parsed, the URL
 of the file is already gone from the stack. But of course
 you will want new URLs to be interpreted relative to the file
 	url = "foo/bar/baz.xml"
 	element = xsc.xsc.parse(url)
 	xsc.xsc.pushURL(url)
-	str = element.transform().asString()
+	str = element.convert().asString()
 	xsc.xsc.popURL()
 
 Automatic generation of image size attributes
 =============================================
 The module special contains an element autoimg, that extends
-html.img. When converted to HTML via the transform() method the
+html.img. When converted to HTML via the convert() method the
 size of the image will be determined and the HEIGHT
 and WIDTH attributes will be set accordingly.
 
 instruction node is instantiated, i.e. when the XML file is parsed,
 so anything you do there will be available afterwards.
 
-The result of a call to transform() for a xsc-eval processing instruction
+The result of a call to convert() for a xsc-eval processing instruction
 is whatever the Python code in the content returns. For example, consider
 the following XML file:
 	<?xsc-exec
 class Node:
 	"""
 	base class for nodes in the document tree. Derived classes must
-	implement <methodref>transform</methodref> and may implement
+	implement <methodref>convert</methodref> and may implement
 	<methodref>publish</methodref> and <methodref>asPlainString</methodref>.
 	"""
 
 		# (nestinglevel, location, elementnumber, string representation) of the nodes
 		return [[nest, self.startloc, elementno, self._dorepr(presenter)]]
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		"""
 		<par noindent>returns a version of this node and it's content converted to HTML,
-		so when you define your own element classes you should overwrite <methodref>transform</methodref>.</par>
+		so when you define your own element classes you should overwrite <methodref>convert</methodref>.</par>
 
 		<par>E.g. when you want to define an element that packs it's content into an HTML
 		bold element, do the following:
 		def foo(xsc.Element):
 			empty = 0
 
-			def transform(self, transformer=None):
-				return html.b(self.content).transform(transformer)
+			def convert(self, converter=None):
+				return html.b(self.content).convert(converter)
 		</pre>
 		</par>
 		"""
 		class caps(xsc.Element):
 			empty = 0
 
-			def transform(self, transformer=None):
+			def convert(self, converter=None):
 				return html.span(
-					self.content.transform(transformer),
+					self.content.convert(converter),
 					style="font-variant: small-caps;"
 				)
 		</pre>
 			content = content._content
 		StringMixIn.__init__(self, content)
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return self
 
-	clone = transform
+	clone = convert
 
 	def asPlainString(self):
 		return self._content
 		for child in content:
 			self.extend(child)
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		node = self.__class__() # virtual constructor => attributes (which are derived from Frag) will be handled correctly)
-		node.__content = [ child.transform(transformer) for child in self.__content ]
+		node.__content = [ child.convert(converter) for child in self.__content ]
 		return self._decorateNode(node)
 
 	def clone(self):
 	def __init__(self, content=""):
 		StringMixIn.__init__(self, content)
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return self
 
 	def clone(self):
 	def __init__(self, content=""):
 		StringMixIn.__init__(self, content)
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return self
 
 	def clone(self):
 		self._target = utils.stringFromCode(target)
 		StringMixIn.__init__(self, content)
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return self
 
 	def clone(self):
 		code = utils.Code(self._content, 1)
 		exec code.asString() in procinst.__dict__ # requires Python 2.0b2 (and doesn't really work)
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return Null # has been executed at construction time already, so we don't have to do anything here
 
 class Eval(PythonCode):
 	def __init__(self, content=u""):
 		ProcInst.__init__(self, u"xsc-eval", content)
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		"""
-		Evaluates the code. The <argref>transformer</argref> argument will be available
-		under the name <code>transformer</code> as an argument.
+		Evaluates the code. The <argref>converter</argref> argument will be available
+		under the name <code>converter</code> as an argument.
 		"""
 		code = utils.Code(self._content, 1)
 		code.funcify()
 		exec code.asString() in procinst.__dict__ # requires Python 2.0b2 (and doesn't really work)
-		return ToNode(procinst.__(transformer)).transform(transformer)
+		return ToNode(procinst.__(converter)).convert(converter)
 
 class XML(ProcInst):
 	"""
 		if self.empty and len(self):
 			raise errors.EmptyElementWithContentError(self)
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		node = self.__class__() # "virtual" copy constructor
-		node.content = self.content.transform(transformer) # this is faster than passing it in the constructor (no ToNode call)
+		node.content = self.content.convert(converter) # this is faster than passing it in the constructor (no ToNode call)
 		for attr in self.attrs.keys():
-			node.attrs[attr] = self.attrs[attr].transform(transformer)
+			node.attrs[attr] = self.attrs[attr].convert(converter)
 		return self._decorateNode(node)
 
 	def clone(self):
 	def asPlainString(self):
 		return self.content.asPlainString()
 
-	def _addImageSizeAttributes(self, transformer, imgattr, widthattr=None, heightattr=None):
+	def _addImageSizeAttributes(self, converter, imgattr, widthattr=None, heightattr=None):
 		"""
 		<par noindent>add width and height attributes to the element for the image that can be found in the attribute
 		<argref>imgattr</argref>. If the attributes are already there, they are taken as a formatting
 		"""
 
 		if self.hasAttr(imgattr):
-			size = self[imgattr].transform(transformer).ImageSize()
+			size = self[imgattr].convert(converter).ImageSize()
 			if size is not None: # the size was retrieved so we can use it
 				sizedict = {"width": size[0], "height": size[1]}
 				for attr in (heightattr, widthattr):
 					if attr is not None: # do something to the width/height
 						if self.hasAttr(attr):
 							try:
-								s = self[attr].transform(transformer).asPlainString() % sizedict
+								s = self[attr].convert(converter).asPlainString() % sizedict
 								s = str(eval(s))
 								s = utils.stringFromCode(s)
 								self[attr] = s
 class Entity(Node):
 	"""
 	<par noindent>Class for entities. Derive your own entities from
-	it and implement <code>transform()</code> and <code>asPlainString()</code>.</par>
+	it and implement <code>convert()</code> and <code>asPlainString()</code>.</par>
 
 	<par>If this entity is a simple character reference, you don't have to implement
 	those functions. Simply set the class attribute <code>codepoint</code>, and
 	you're done.</par>
 	"""
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		node = Text(unichr(self.codepoint))
 		return self._decorateNode(node)
 
 	node that does not contain anything.
 	"""
 
-	def transform(self, transformer=None):
+	def convert(self, converter=None):
 		return self
 
 	def clone(self):
 	def publish(self, publisher):
 		Text(self.forOutput().asPlainString()).publish(publisher)
 
-	def transform(self, transformer=None):
-		node = Attr.transform(self, transformer)
+	def convert(self, converter=None):
+		node = Attr.convert(self, converter)
 		node.base = self.base.clone()
 		return node
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.