# HG changeset patch # User cmlenz # Date 1257888171 0 # Node ID 4376010bb97ea22d4ee81915c53eaa0b4096fe9e # Parent 04945cd67dad2ca1a1e8887cb29a76df580f1b20 Convert a bunch of print statements to py3k compatible syntax. diff --git a/doc/filters.txt b/doc/filters.txt --- a/doc/filters.txt +++ b/doc/filters.txt @@ -47,7 +47,7 @@ ...

... """) >>> filler = HTMLFormFiller(data=dict(username='john', remember=True)) - >>> print template.generate() | filler + >>> print(template.generate() | filler)

Innocent looking text.

@@ -130,7 +130,7 @@ ...
... """) >>> sanitize = HTMLSanitizer(safe_attrs=HTMLSanitizer.SAFE_ATTRS | set(['style'])) - >>> print html | sanitize + >>> print(html | sanitize)

@@ -164,10 +164,10 @@ ... ... ''') - >>> print html | Transformer('body/em').map(unicode.upper, TEXT) \ - ... .unwrap().wrap(tag.u).end() \ - ... .select('body/u') \ - ... .prepend('underlined ') + >>> print(html | Transformer('body/em').map(unicode.upper, TEXT) + ... .unwrap().wrap(tag.u).end() + ... .select('body/u') + ... .prepend('underlined ')) Some Title @@ -216,7 +216,7 @@ >>> xform = Transformer('body//em').map(unicode.upper, TEXT) \ >>> xform = xform.apply(RenameTransformation('u')) - >>> print html | xform + >>> print(html | xform) Some Title diff --git a/doc/streams.txt b/doc/streams.txt --- a/doc/streams.txt +++ b/doc/streams.txt @@ -46,7 +46,7 @@ .. code-block:: pycon >>> for kind, data, pos in stream: - ... print kind, `data`, pos + ... print('%s %r %r' % (kind, data, pos)) ... START (QName(u'p'), Attrs([(QName(u'class'), u'intro')])) (None, 1, 0) TEXT u'Some text and ' (None, 1, 17) @@ -143,7 +143,7 @@ .. code-block:: pycon >>> for output in stream.serialize(): - ... print `output` + ... print(repr(output)) ... '> @@ -158,7 +158,7 @@ .. code-block:: pycon - >>> print stream.render() + >>> print(stream.render())

Some text and a link.

Both methods can be passed a ``method`` parameter that determines how exactly @@ -167,7 +167,7 @@ .. code-block:: pycon - >>> print stream.render('html') + >>> print(stream.render('html'))

Some text and a link.

Note how the `
` element isn't closed, which is the right thing to do for @@ -183,14 +183,14 @@ >>> from genshi.filters import HTMLSanitizer >>> from genshi.output import TextSerializer - >>> print ''.join(TextSerializer()(HTMLSanitizer()(stream))) + >>> print(''.join(TextSerializer()(HTMLSanitizer()(stream)))) Some text and a link. The pipe operator allows a nicer syntax: .. code-block:: pycon - >>> print stream | HTMLSanitizer() | TextSerializer() + >>> print(stream | HTMLSanitizer() | TextSerializer()) Some text and a link. @@ -327,7 +327,7 @@ >>> substream = stream.select('a') >>> substream - >>> print substream + >>> print(substream) a link Often, streams cannot be reused: in the above example, the sub-stream is based @@ -341,11 +341,11 @@ >>> substream = Stream(list(stream.select('a'))) >>> substream - >>> print substream + >>> print(substream) a link - >>> print substream.select('@href') + >>> print(substream.select('@href')) http://example.org/ - >>> print substream.select('text()') + >>> print(substream.select('text()')) a link See `Using XPath in Genshi`_ for more information about the XPath support in diff --git a/doc/templates.txt b/doc/templates.txt --- a/doc/templates.txt +++ b/doc/templates.txt @@ -116,7 +116,7 @@ >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('

Hello, $name!

') >>> stream = tmpl.generate(name='world') - >>> print stream.render('xhtml') + >>> print(stream.render('xhtml'))

Hello, world!

.. note:: See the Serialization_ section of the `Markup Streams`_ page for @@ -129,7 +129,7 @@ >>> from genshi.template import TextTemplate >>> tmpl = TextTemplate('Hello, $name!') >>> stream = tmpl.generate(name='world') - >>> print stream + >>> print(stream) Hello, world! .. note:: If you want to use text templates, you should consider using the @@ -152,7 +152,7 @@ loader = TemplateLoader([templates_dir1, templates_dir2]) tmpl = loader.load('test.html') stream = tmpl.generate(title='Hello, world!') - print stream.render() + print(stream.render()) See the `API documentation `_ for details on using Genshi via the Python API. @@ -181,7 +181,7 @@ >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('${items[0].capitalize()} item') - >>> print tmpl.generate(items=['first', 'second']) + >>> print(tmpl.generate(items=['first', 'second'])) First item Expressions support the full power of Python. In addition, it is possible to @@ -193,7 +193,7 @@ >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('${dict.foo}') - >>> print tmpl.generate(dict={'foo': 'bar'}) + >>> print(tmpl.generate(dict={'foo': 'bar'})) bar Because there are two ways to access either attributes or items, expressions @@ -213,12 +213,12 @@ >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('$foo') # Wanted "$foo" as literal output - >>> print tmpl.generate() + >>> print(tmpl.generate()) Traceback (most recent call last): ... UndefinedError: "foo" not defined >>> tmpl = MarkupTemplate('$$foo') - >>> print tmpl.generate() + >>> print(tmpl.generate()) $foo But note that this is not necessary if the characters following the dollar sign @@ -227,7 +227,7 @@ .. code-block:: pycon >>> tmpl = MarkupTemplate('') - >>> print tmpl.generate() + >>> print(tmpl.generate()) On the other hand, Genshi will always replace two dollar signs in text with a @@ -237,7 +237,7 @@ .. code-block:: pycon >>> tmpl = MarkupTemplate('') - >>> print tmpl.generate() + >>> print(tmpl.generate()) @@ -338,7 +338,7 @@ >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('

${defined("doh")}

') - >>> print tmpl.generate().render('xhtml') + >>> print(tmpl.generate().render('xhtml'))

False

.. note:: Lenient error handling was the default in Genshi prior to version 0.5. @@ -364,7 +364,7 @@ >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('

${doh}

', lookup='lenient') - >>> print tmpl.generate().render('xhtml') + >>> print(tmpl.generate().render('xhtml'))

You *will* however get an exception if you try to call an undefined variable, or @@ -374,7 +374,7 @@ >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('

${doh.oops}

', lookup='lenient') - >>> print tmpl.generate().render('xhtml') + >>> print(tmpl.generate().render('xhtml')) Traceback (most recent call last): ... UndefinedError: "doh" not defined @@ -387,7 +387,7 @@ >>> from genshi.template import MarkupTemplate >>> tmpl = MarkupTemplate('

${type(doh) is not Undefined}

', ... lookup='lenient') - >>> print tmpl.generate().render('xhtml') + >>> print(tmpl.generate().render('xhtml'))

False

Alternatively, the built-in functions defined_ or value_of_ can be used in this diff --git a/doc/xpath.txt b/doc/xpath.txt --- a/doc/xpath.txt +++ b/doc/xpath.txt @@ -86,8 +86,8 @@ ... ... ''') - >>> print doc.select('items/item[@status="closed" and ' - ... '(@resolution="invalid" or not(@resolution))]/summary/text()') + >>> print(doc.select('items/item[@status="closed" and ' + ... '(@resolution="invalid" or not(@resolution))]/summary/text()')) BarBaz diff --git a/genshi/builder.py b/genshi/builder.py --- a/genshi/builder.py +++ b/genshi/builder.py @@ -32,7 +32,7 @@ >>> doc(tag.br) ->>> print doc +>>> print(doc)

Some text and a link.

If an attribute name collides with a Python keyword, simply append an underscore @@ -40,7 +40,7 @@ >>> doc(class_='intro') ->>> print doc +>>> print(doc)

Some text and a link.

As shown above, an `Element` can easily be directly rendered to XML text by @@ -51,7 +51,7 @@ >>> stream = doc.generate() >>> stream #doctest: +ELLIPSIS ->>> print stream +>>> print(stream)

Some text and a link.

@@ -64,7 +64,7 @@ >>> fragment = tag('Hello, ', tag.em('world'), '!') >>> fragment ->>> print fragment +>>> print(fragment) Hello, world! """ @@ -166,18 +166,18 @@ Construct XML elements by passing the tag name to the constructor: - >>> print Element('strong') + >>> print(Element('strong')) Attributes can be specified using keyword arguments. The values of the arguments will be converted to strings and any special XML characters escaped: - >>> print Element('textarea', rows=10, cols=60) + >>> print(Element('textarea', rows=10, cols=60))