changeset 853:4376010bb97e

Convert a bunch of print statements to py3k compatible syntax.
author cmlenz
date Tue, 10 Nov 2009 21:22:51 +0000
parents 04945cd67dad
children 0d9e87c6cf6e
files doc/filters.txt doc/streams.txt doc/templates.txt doc/xpath.txt genshi/builder.py genshi/filters/html.py genshi/filters/i18n.py genshi/filters/transform.py genshi/input.py genshi/output.py genshi/path.py genshi/template/directives.py genshi/template/eval.py genshi/template/interpolation.py genshi/template/loader.py genshi/template/markup.py genshi/template/text.py genshi/util.py scripts/ast_generator.py setup.py
diffstat 20 files changed, 176 insertions(+), 176 deletions(-) [+]
line wrap: on
line diff
--- a/doc/filters.txt
+++ b/doc/filters.txt
@@ -47,7 +47,7 @@
   ...   </p>
   ... </form>""")
   >>> filler = HTMLFormFiller(data=dict(username='john', remember=True))
-  >>> print template.generate() | filler
+  >>> print(template.generate() | filler)
   <form>
     <p>
       <label>User name:
@@ -104,7 +104,7 @@
   ...   <script>alert("Danger: " + document.cookie)</script>
   ... </div>""")
   >>> sanitize = HTMLSanitizer()
-  >>> print html | sanitize
+  >>> print(html | sanitize)
   <div>
     <p>Innocent looking text.</p>
   </div>
@@ -130,7 +130,7 @@
   ...   <br style="background: url(javascript:alert(document.cookie); color: #000" />
   ... </div>""")
   >>> sanitize = HTMLSanitizer(safe_attrs=HTMLSanitizer.SAFE_ATTRS | set(['style']))
-  >>> print html | sanitize
+  >>> print(html | sanitize)
   <div>
     <br style="color: #000"/>
   </div>
@@ -164,10 +164,10 @@
   ...   </body>
   ... </html>''')
   
-  >>> 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 '))
   <html>
     <head><title>Some Title</title></head>
     <body>
@@ -216,7 +216,7 @@
 
   >>> xform = Transformer('body//em').map(unicode.upper, TEXT) \
   >>> xform = xform.apply(RenameTransformation('u'))
-  >>> print html | xform
+  >>> print(html | xform)
   <html>
     <head><title>Some Title</title></head>
     <body>
--- 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))
   ... 
   <Markup u'<p class="intro">'>
   <Markup u'Some text and '>
@@ -158,7 +158,7 @@
 
 .. code-block:: pycon
 
-  >>> print stream.render()
+  >>> print(stream.render())
   <p class="intro">Some text and <a href="http://example.org/">a link</a>.<br/></p>
 
 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'))
   <p class="intro">Some text and <a href="http://example.org/">a link</a>.<br></p>
 
 Note how the `<br>` 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
   <genshi.core.Stream object at ...>
-  >>> print substream
+  >>> print(substream)
   <a href="http://example.org/">a link</a>
 
 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
   <genshi.core.Stream object at ...>
-  >>> print substream
+  >>> print(substream)
   <a href="http://example.org/">a link</a>
-  >>> 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
--- a/doc/templates.txt
+++ b/doc/templates.txt
@@ -116,7 +116,7 @@
   >>> from genshi.template import MarkupTemplate
   >>> tmpl = MarkupTemplate('<h1>Hello, $name!</h1>')
   >>> stream = tmpl.generate(name='world')
-  >>> print stream.render('xhtml')
+  >>> print(stream.render('xhtml'))
   <h1>Hello, world!</h1>
 
 .. 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 <api/index.html>`_ for details on using Genshi via
 the Python API.
@@ -181,7 +181,7 @@
 
   >>> from genshi.template import MarkupTemplate
   >>> tmpl = MarkupTemplate('<em>${items[0].capitalize()} item</em>')
-  >>> print tmpl.generate(items=['first', 'second'])
+  >>> print(tmpl.generate(items=['first', 'second']))
   <em>First item</em>
 
 Expressions support the full power of Python. In addition, it is possible to
@@ -193,7 +193,7 @@
 
   >>> from genshi.template import MarkupTemplate
   >>> tmpl = MarkupTemplate('<em>${dict.foo}</em>')
-  >>> print tmpl.generate(dict={'foo': 'bar'})
+  >>> print(tmpl.generate(dict={'foo': 'bar'}))
   <em>bar</em>
 
 Because there are two ways to access either attributes or items, expressions
@@ -213,12 +213,12 @@
 
   >>> from genshi.template import MarkupTemplate
   >>> tmpl = MarkupTemplate('<em>$foo</em>') # Wanted "$foo" as literal output
-  >>> print tmpl.generate()
+  >>> print(tmpl.generate())
   Traceback (most recent call last):
     ...
   UndefinedError: "foo" not defined
   >>> tmpl = MarkupTemplate('<em>$$foo</em>')
-  >>> print tmpl.generate()
+  >>> print(tmpl.generate())
   <em>$foo</em>
 
 But note that this is not necessary if the characters following the dollar sign
@@ -227,7 +227,7 @@
 .. code-block:: pycon
 
   >>> tmpl = MarkupTemplate('<script>$(function() {})</script>')
-  >>> print tmpl.generate()
+  >>> print(tmpl.generate())
   <script>$(function() {})</script>
 
 On the other hand, Genshi will always replace two dollar signs in text with a
@@ -237,7 +237,7 @@
 .. code-block:: pycon
 
   >>> tmpl = MarkupTemplate('<script>$$$("div")</script>')
-  >>> print tmpl.generate()
+  >>> print(tmpl.generate())
   <script>$$("div")</script>
 
 
@@ -338,7 +338,7 @@
 
   >>> from genshi.template import MarkupTemplate
   >>> tmpl = MarkupTemplate('<p>${defined("doh")}</p>')
-  >>> print tmpl.generate().render('xhtml')
+  >>> print(tmpl.generate().render('xhtml'))
   <p>False</p>
 
 .. 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('<p>${doh}</p>', lookup='lenient')
-  >>> print tmpl.generate().render('xhtml')
+  >>> print(tmpl.generate().render('xhtml'))
   <p></p>
 
 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('<p>${doh.oops}</p>', 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('<p>${type(doh) is not Undefined}</p>',
   ...                       lookup='lenient')
-  >>> print tmpl.generate().render('xhtml')
+  >>> print(tmpl.generate().render('xhtml'))
   <p>False</p>
 
 Alternatively, the built-in functions defined_ or value_of_ can be used in this
--- a/doc/xpath.txt
+++ b/doc/xpath.txt
@@ -86,8 +86,8 @@
   ...   </items>
   ... </doc>''')
 
-  >>> 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
 
 
--- a/genshi/builder.py
+++ b/genshi/builder.py
@@ -32,7 +32,7 @@
 
 >>> doc(tag.br)
 <Element "p">
->>> print doc
+>>> print(doc)
 <p>Some text and <a href="http://example.org/">a link</a>.<br/></p>
 
 If an attribute name collides with a Python keyword, simply append an underscore
@@ -40,7 +40,7 @@
 
 >>> doc(class_='intro')
 <Element "p">
->>> print doc
+>>> print(doc)
 <p class="intro">Some text and <a href="http://example.org/">a link</a>.<br/></p>
 
 As shown above, an `Element` can easily be directly rendered to XML text by
@@ -51,7 +51,7 @@
 >>> stream = doc.generate()
 >>> stream #doctest: +ELLIPSIS
 <genshi.core.Stream object at ...>
->>> print stream
+>>> print(stream)
 <p class="intro">Some text and <a href="http://example.org/">a link</a>.<br/></p>
 
 
@@ -64,7 +64,7 @@
 >>> fragment = tag('Hello, ', tag.em('world'), '!')
 >>> fragment
 <Fragment>
->>> print fragment
+>>> print(fragment)
 Hello, <em>world</em>!
 """
 
@@ -166,18 +166,18 @@
 
     Construct XML elements by passing the tag name to the constructor:
 
-    >>> print Element('strong')
+    >>> print(Element('strong'))
     <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))
     <textarea rows="10" cols="60"/>
-    >>> print Element('span', title='1 < 2')
+    >>> print(Element('span', title='1 < 2'))
     <span title="1 &lt; 2"/>
-    >>> print Element('span', title='"baz"')
+    >>> print(Element('span', title='"baz"'))
     <span title="&#34;baz&#34;"/>
 
     The " character is escaped using a numerical entity.
@@ -186,50 +186,50 @@
     If an attribute value evaluates to `None`, that attribute is not included
     in the output:
 
-    >>> print Element('a', name=None)
+    >>> print(Element('a', name=None))
     <a/>
 
     Attribute names that conflict with Python keywords can be specified by
     appending an underscore:
 
-    >>> print Element('div', class_='warning')
+    >>> print(Element('div', class_='warning'))
     <div class="warning"/>
 
     Nested elements can be added to an element using item access notation.
     The call notation can also be used for this and for adding attributes
     using keyword arguments, as one would do in the constructor.
 
-    >>> print Element('ul')(Element('li'), Element('li'))
+    >>> print(Element('ul')(Element('li'), Element('li')))
     <ul><li/><li/></ul>
-    >>> print Element('a')('Label')
+    >>> print(Element('a')('Label'))
     <a>Label</a>
-    >>> print Element('a')('Label', href="target")
+    >>> print(Element('a')('Label', href="target"))
     <a href="target">Label</a>
 
     Text nodes can be nested in an element by adding strings instead of
     elements. Any special characters in the strings are escaped automatically:
 
-    >>> print Element('em')('Hello world')
+    >>> print(Element('em')('Hello world'))
     <em>Hello world</em>
-    >>> print Element('em')(42)
+    >>> print(Element('em')(42))
     <em>42</em>
-    >>> print Element('em')('1 < 2')
+    >>> print(Element('em')('1 < 2'))
     <em>1 &lt; 2</em>
 
     This technique also allows mixed content:
 
-    >>> print Element('p')('Hello ', Element('b')('world'))
+    >>> print(Element('p')('Hello ', Element('b')('world')))
     <p>Hello <b>world</b></p>
 
     Quotes are not escaped inside text nodes:
-    >>> print Element('p')('"Hello"')
+    >>> print(Element('p')('"Hello"'))
     <p>"Hello"</p>
 
     Elements can also be combined with other elements or strings using the
     addition operator, which results in a `Fragment` object that contains the
     operands:
     
-    >>> print Element('br') + 'some text' + Element('br')
+    >>> print(Element('br') + 'some text' + Element('br'))
     <br/>some text<br/>
     
     Elements with a namespace can be generated using the `Namespace` and/or
@@ -237,7 +237,7 @@
     
     >>> from genshi.core import Namespace
     >>> xhtml = Namespace('http://www.w3.org/1999/xhtml')
-    >>> print Element(xhtml.html, lang='en')
+    >>> print(Element(xhtml.html, lang='en'))
     <html xmlns="http://www.w3.org/1999/xhtml" lang="en"/>
     """
     __slots__ = ['tag', 'attrib']
@@ -283,28 +283,28 @@
     attribute of the factory object:
     
     >>> factory = ElementFactory()
-    >>> print factory.foo
+    >>> print(factory.foo)
     <foo/>
-    >>> print factory.foo(id=2)
+    >>> print(factory.foo(id=2))
     <foo id="2"/>
     
     Markup fragments (lists of nodes without a parent element) can be created
     by calling the factory:
     
-    >>> print factory('Hello, ', factory.em('world'), '!')
+    >>> print(factory('Hello, ', factory.em('world'), '!'))
     Hello, <em>world</em>!
     
     A factory can also be bound to a specific namespace:
     
     >>> factory = ElementFactory('http://www.w3.org/1999/xhtml')
-    >>> print factory.html(lang="en")
+    >>> print(factory.html(lang="en"))
     <html xmlns="http://www.w3.org/1999/xhtml" lang="en"/>
     
     The namespace for a specific element can be altered on an existing factory
     by specifying the new namespace using item access:
     
     >>> factory = ElementFactory()
-    >>> print factory.html(factory['http://www.w3.org/2000/svg'].g(id=3))
+    >>> print(factory.html(factory['http://www.w3.org/2000/svg'].g(id=3)))
     <html><g xmlns="http://www.w3.org/2000/svg" id="3"/></html>
     
     Usually, the `ElementFactory` class is not be used directly. Rather, the
--- a/genshi/filters/html.py
+++ b/genshi/filters/html.py
@@ -30,7 +30,7 @@
     ...   <p><input type="text" name="foo" /></p>
     ... </form>''')
     >>> filler = HTMLFormFiller(data={'foo': 'bar'})
-    >>> print html | filler
+    >>> print(html | filler)
     <form>
       <p><input type="text" name="foo" value="bar"/></p>
     </form>
@@ -195,7 +195,7 @@
     
     >>> from genshi import HTML
     >>> html = HTML('<div><script>alert(document.cookie)</script></div>')
-    >>> print html | HTMLSanitizer()
+    >>> print(html | HTMLSanitizer())
     <div/>
     
     The default set of safe tags and attributes can be modified when the filter
@@ -204,14 +204,14 @@
     
     >>> html = HTML('<div style="background: #000"></div>')
     >>> sanitizer = HTMLSanitizer(safe_attrs=HTMLSanitizer.SAFE_ATTRS | set(['style']))
-    >>> print html | sanitizer
+    >>> print(html | sanitizer)
     <div style="background: #000"/>
     
     Note that even in this case, the filter *does* attempt to remove dangerous
     constructs from style attributes:
 
     >>> html = HTML('<div style="background: url(javascript:void); color: #000"></div>')
-    >>> print html | sanitizer
+    >>> print(html | sanitizer)
     <div style="color: #000"/>
     
     This handles HTML entities, unicode escapes in CSS and Javascript text, as
--- a/genshi/filters/i18n.py
+++ b/genshi/filters/i18n.py
@@ -91,7 +91,7 @@
     >>> translator.setup(tmpl)
     >>> list(translator.extract(tmpl.stream))
     [(2, None, u'[1:Foo]\n    [2:Bar]', []), (6, None, u'Foo [1:bar]!', [])]
-    >>> print tmpl.generate().render()
+    >>> print(tmpl.generate().render())
     <html>
       <div><p>Foo</p>
         <p>Bar</p></div>
@@ -118,7 +118,7 @@
     ...   <p i18n:msg="">Foo <em>bar</em>!</p>
     ... </html>''')
     >>> translator.setup(tmpl)
-    >>> print tmpl.generate(fname='John', lname='Doe').render()
+    >>> print(tmpl.generate(fname='John', lname='Doe').render())
     <html>
       <div><p>First Name: John</p>
         <p>Last Name: Doe</p></div>
@@ -259,13 +259,13 @@
     ...   </div>
     ... </html>''')
     >>> translator.setup(tmpl)
-    >>> print tmpl.generate(num=1).render()
+    >>> print(tmpl.generate(num=1).render())
     <html>
       <div>
         <p>There is 1 coin</p>
       </div>
     </html>
-    >>> print tmpl.generate(num=2).render()
+    >>> print(tmpl.generate(num=2).render())
     <html>
       <div>
         <p>There are 2 coins</p>
@@ -420,7 +420,7 @@
     >>> translator = Translator(translations)
     >>> translator.setup(tmpl)
 
-    >>> print tmpl.generate().render()
+    >>> print(tmpl.generate().render())
     <html>
       <p>Voh</p>
       <div>
@@ -487,7 +487,7 @@
     When generating the template output, our hard-coded translations should be
     applied as expected:
     
-    >>> print tmpl.generate(username='Hans', _=pseudo_gettext)
+    >>> print(tmpl.generate(username='Hans', _=pseudo_gettext))
     <html>
       <head>
         <title>Beispiel</title>
@@ -698,7 +698,7 @@
         ...   </body>
         ... </html>''', filename='example.html')
         >>> for line, func, msg, comments in Translator().extract(tmpl.stream):
-        ...    print "%d, %r, %r" % (line, func, msg)
+        ...    print('%d, %r, %r' % (line, func, msg))
         3, None, u'Example'
         6, None, u'Example'
         7, '_', u'Hello, %(name)s'
--- a/genshi/filters/transform.py
+++ b/genshi/filters/transform.py
@@ -32,8 +32,8 @@
 ...    Some <em>body</em> text.
 ...  </body>
 ... </html>''')
->>> print html | Transformer('body/em').map(unicode.upper, TEXT) \\
-...                                    .unwrap().wrap(tag.u)
+>>> print(html | Transformer('body/em').map(unicode.upper, TEXT)
+...                                    .unwrap().wrap(tag.u))
 <html>
   <head><title>Some Title</title></head>
   <body>
@@ -142,7 +142,7 @@
     Here's an example of removing some markup (the title, in this case)
     selected by an expression:
 
-    >>> print html | Transformer('head/title').remove()
+    >>> print(html | Transformer('head/title').remove())
     <html><head/><body>Some <em>body</em> text.</body></html>
 
     Inserted content can be passed in the form of a string, or a markup event
@@ -150,7 +150,7 @@
     `builder` module:
 
     >>> from genshi.builder import tag
-    >>> print html | Transformer('body').prepend(tag.h1('Document Title'))
+    >>> print(html | Transformer('body').prepend(tag.h1('Document Title')))
     <html><head><title>Some Title</title></head><body><h1>Document
     Title</h1>Some <em>body</em> text.</body></html>
 
@@ -160,8 +160,8 @@
     copied text into the body as ``<h1>`` enclosed text:
 
     >>> buffer = StreamBuffer()
-    >>> print html | Transformer('head/title/text()').copy(buffer) \\
-    ...     .end().select('body').prepend(tag.h1(buffer))
+    >>> print(html | Transformer('head/title/text()').copy(buffer)
+    ...     .end().select('body').prepend(tag.h1(buffer)))
     <html><head><title>Some Title</title></head><body><h1>Some Title</h1>Some
     <em>body</em> text.</body></html>
 
@@ -170,7 +170,7 @@
     transforms:
 
     >>> emphasis = Transformer('body//em').attr('class', 'emphasis')
-    >>> print html | emphasis
+    >>> print(html | emphasis)
     <html><head><title>Some Title</title></head><body>Some <em
     class="emphasis">body</em> text.</body></html>
     """
@@ -216,7 +216,7 @@
         ...         else:
         ...             yield mark, (kind, data, pos)
         >>> short_stream = HTML('<body>Some <em>test</em> text</body>')
-        >>> print short_stream | Transformer('.//em/text()').apply(upper)
+        >>> print(short_stream | Transformer('.//em/text()').apply(upper))
         <body>Some <em>TEST</em> text</body>
         """
         transformer = Transformer()
@@ -234,7 +234,7 @@
         selection.
 
         >>> html = HTML('<body>Some <em>test</em> text</body>')
-        >>> print html | Transformer().select('.//em').trace()
+        >>> print(html | Transformer().select('.//em').trace())
         (None, ('START', (QName(u'body'), Attrs()), (None, 1, 0)))
         (None, ('TEXT', u'Some ', (None, 1, 6)))
         ('ENTER', ('START', (QName(u'em'), Attrs()), (None, 1, 11)))
@@ -258,7 +258,7 @@
         are converted to OUTSIDE marks.
 
         >>> html = HTML('<body>Some <em>test</em> text</body>')
-        >>> print html | Transformer('//em').invert().trace()
+        >>> print(html | Transformer('//em').invert().trace())
         ('OUTSIDE', ('START', (QName(u'body'), Attrs()), (None, 1, 0)))
         ('OUTSIDE', ('TEXT', u'Some ', (None, 1, 6)))
         (None, ('START', (QName(u'em'), Attrs()), (None, 1, 11)))
@@ -278,7 +278,7 @@
         Example:
 
         >>> html = HTML('<body>Some <em>test</em> text</body>')
-        >>> print html | Transformer('//em').end().trace()
+        >>> print(html | Transformer('//em').end().trace())
         ('OUTSIDE', ('START', (QName(u'body'), Attrs()), (None, 1, 0)))
         ('OUTSIDE', ('TEXT', u'Some ', (None, 1, 6)))
         ('OUTSIDE', ('START', (QName(u'em'), Attrs()), (None, 1, 11)))
@@ -302,7 +302,7 @@
 
         >>> html = HTML('<html><head><title>Some Title</title></head>'
         ...             '<body>Some <em>body</em> text.</body></html>')
-        >>> print html | Transformer('.//em').empty()
+        >>> print(html | Transformer('.//em').empty())
         <html><head><title>Some Title</title></head><body>Some <em/>
         text.</body></html>
 
@@ -317,7 +317,7 @@
 
         >>> html = HTML('<html><head><title>Some Title</title></head>'
         ...             '<body>Some <em>body</em> text.</body></html>')
-        >>> print html | Transformer('.//em').remove()
+        >>> print(html | Transformer('.//em').remove())
         <html><head><title>Some Title</title></head><body>Some
         text.</body></html>
 
@@ -334,7 +334,7 @@
 
         >>> html = HTML('<html><head><title>Some Title</title></head>'
         ...             '<body>Some <em>body</em> text.</body></html>')
-        >>> print html | Transformer('.//em').unwrap()
+        >>> print(html | Transformer('.//em').unwrap())
         <html><head><title>Some Title</title></head><body>Some body
         text.</body></html>
 
@@ -347,7 +347,7 @@
 
         >>> html = HTML('<html><head><title>Some Title</title></head>'
         ...             '<body>Some <em>body</em> text.</body></html>')
-        >>> print html | Transformer('.//em').wrap('strong')
+        >>> print(html | Transformer('.//em').wrap('strong'))
         <html><head><title>Some Title</title></head><body>Some
         <strong><em>body</em></strong> text.</body></html>
 
@@ -363,7 +363,7 @@
 
         >>> html = HTML('<html><head><title>Some Title</title></head>'
         ...             '<body>Some <em>body</em> text.</body></html>')
-        >>> print html | Transformer('.//title/text()').replace('New Title')
+        >>> print(html | Transformer('.//title/text()').replace('New Title'))
         <html><head><title>New Title</title></head><body>Some <em>body</em>
         text.</body></html>
 
@@ -381,7 +381,7 @@
 
         >>> html = HTML('<html><head><title>Some Title</title></head>'
         ...             '<body>Some <em>body</em> text.</body></html>')
-        >>> print html | Transformer('.//em').before('emphasised ')
+        >>> print(html | Transformer('.//em').before('emphasised '))
         <html><head><title>Some Title</title></head><body>Some emphasised
         <em>body</em> text.</body></html>
 
@@ -398,7 +398,7 @@
 
         >>> html = HTML('<html><head><title>Some Title</title></head>'
         ...             '<body>Some <em>body</em> text.</body></html>')
-        >>> print html | Transformer('.//em').after(' rock')
+        >>> print(html | Transformer('.//em').after(' rock'))
         <html><head><title>Some Title</title></head><body>Some <em>body</em>
         rock text.</body></html>
 
@@ -415,7 +415,7 @@
 
         >>> html = HTML('<html><head><title>Some Title</title></head>'
         ...             '<body>Some <em>body</em> text.</body></html>')
-        >>> print html | Transformer('.//body').prepend('Some new body text. ')
+        >>> print(html | Transformer('.//body').prepend('Some new body text. '))
         <html><head><title>Some Title</title></head><body>Some new body text.
         Some <em>body</em> text.</body></html>
 
@@ -430,7 +430,7 @@
 
         >>> html = HTML('<html><head><title>Some Title</title></head>'
         ...             '<body>Some <em>body</em> text.</body></html>')
-        >>> print html | Transformer('.//body').append(' Some new body text.')
+        >>> print(html | Transformer('.//body').append(' Some new body text.'))
         <html><head><title>Some Title</title></head><body>Some <em>body</em>
         text. Some new body text.</body></html>
 
@@ -451,13 +451,13 @@
         >>> html = HTML('<html><head><title>Some Title</title></head>'
         ...             '<body>Some <em class="before">body</em> <em>text</em>.</body>'
         ...             '</html>')
-        >>> print html | Transformer('body/em').attr('class', None)
+        >>> print(html | Transformer('body/em').attr('class', None))
         <html><head><title>Some Title</title></head><body>Some <em>body</em>
         <em>text</em>.</body></html>
 
         Otherwise the attribute will be set to `value`:
 
-        >>> print html | Transformer('body/em').attr('class', 'emphasis')
+        >>> print(html | Transformer('body/em').attr('class', 'emphasis'))
         <html><head><title>Some Title</title></head><body>Some <em
         class="emphasis">body</em> <em class="emphasis">text</em>.</body></html>
 
@@ -467,9 +467,9 @@
 
         >>> def print_attr(name, event):
         ...     attrs = event[1][1]
-        ...     print attrs
+        ...     print(attrs)
         ...     return attrs.get(name)
-        >>> print html | Transformer('body/em').attr('class', print_attr)
+        >>> print(html | Transformer('body/em').attr('class', print_attr))
         Attrs([(QName(u'class'), u'before')])
         Attrs()
         <html><head><title>Some Title</title></head><body>Some <em
@@ -494,20 +494,20 @@
         >>> buffer = StreamBuffer()
         >>> html = HTML('<html><head><title>Some Title</title></head>'
         ...             '<body>Some <em>body</em> text.</body></html>')
-        >>> print html | Transformer('head/title/text()').copy(buffer) \\
-        ...     .end().select('body').prepend(tag.h1(buffer))
+        >>> print(html | Transformer('head/title/text()').copy(buffer)
+        ...     .end().select('body').prepend(tag.h1(buffer)))
         <html><head><title>Some Title</title></head><body><h1>Some
         Title</h1>Some <em>body</em> text.</body></html>
 
         This example illustrates that only a single contiguous selection will
         be buffered:
 
-        >>> print html | Transformer('head/title/text()').copy(buffer) \\
-        ...     .end().select('body/em').copy(buffer).end().select('body') \\
-        ...     .prepend(tag.h1(buffer))
+        >>> print(html | Transformer('head/title/text()').copy(buffer)
+        ...     .end().select('body/em').copy(buffer).end().select('body')
+        ...     .prepend(tag.h1(buffer)))
         <html><head><title>Some Title</title></head><body><h1>Some
         Title</h1>Some <em>body</em> text.</body></html>
-        >>> print buffer
+        >>> print(buffer)
         <em>body</em>
 
         Element attributes can also be copied for later use:
@@ -518,9 +518,9 @@
         >>> buffer = StreamBuffer()
         >>> def apply_attr(name, entry):
         ...     return list(buffer)[0][1][1].get('class')
-        >>> print html | Transformer('body/em[@class]/@class').copy(buffer) \\
-        ...     .end().buffer().select('body/em[not(@class)]') \\
-        ...     .attr('class', apply_attr)
+        >>> print(html | Transformer('body/em[@class]/@class').copy(buffer)
+        ...     .end().buffer().select('body/em[not(@class)]')
+        ...     .attr('class', apply_attr))
         <html><head><title>Some Title</title></head><body><em
         class="before">Some</em> <em class="before">body</em><em
         class="before">text</em>.</body></html>
@@ -547,8 +547,8 @@
         >>> buffer = StreamBuffer()
         >>> html = HTML('<html><head><title>Some Title</title></head>'
         ...             '<body>Some <em>body</em> text.</body></html>')
-        >>> print html | Transformer('.//em/text()').cut(buffer) \\
-        ...     .end().select('.//em').after(tag.h1(buffer))
+        >>> print(html | Transformer('.//em/text()').cut(buffer)
+        ...     .end().select('.//em').after(tag.h1(buffer)))
         <html><head><title>Some Title</title></head><body>Some
         <em/><h1>body</h1> text.</body></html>
 
@@ -579,8 +579,8 @@
         >>> doc = HTML('<doc><notes></notes><body>Some <note>one</note> '
         ...            'text <note>two</note>.</body></doc>')
         >>> buffer = StreamBuffer()
-        >>> print doc | Transformer('body/note').cut(buffer, accumulate=True) \\
-        ...     .end().buffer().select('notes').prepend(buffer)
+        >>> print(doc | Transformer('body/note').cut(buffer, accumulate=True)
+        ...     .end().buffer().select('notes').prepend(buffer))
         <doc><notes><note>one</note><note>two</note></notes><body>Some  text
         .</body></doc>
 
@@ -596,7 +596,7 @@
         >>> from genshi.filters.html import HTMLSanitizer
         >>> html = HTML('<html><body>Some text<script>alert(document.cookie)'
         ...             '</script> and some more text</body></html>')
-        >>> print html | Transformer('body/*').filter(HTMLSanitizer())
+        >>> print(html | Transformer('body/*').filter(HTMLSanitizer()))
         <html><body>Some text and some more text</body></html>
 
         :param filter: The stream filter to apply.
@@ -610,7 +610,7 @@
 
         >>> html = HTML('<html><head><title>Some Title</title></head>'
         ...               '<body>Some <em>body</em> text.</body></html>')
-        >>> print html | Transformer('head/title').map(unicode.upper, TEXT)
+        >>> print(html | Transformer('head/title').map(unicode.upper, TEXT))
         <html><head><title>SOME TITLE</title></head><body>Some <em>body</em>
         text.</body></html>
 
@@ -628,13 +628,13 @@
         >>> html = HTML('<html><body>Some text, some more text and '
         ...             '<b>some bold text</b>\\n'
         ...             '<i>some italicised text</i></body></html>')
-        >>> print html | Transformer('body/b').substitute('(?i)some', 'SOME')
+        >>> print(html | Transformer('body/b').substitute('(?i)some', 'SOME'))
         <html><body>Some text, some more text and <b>SOME bold text</b>
         <i>some italicised text</i></body></html>
         >>> tags = tag.html(tag.body('Some text, some more text and\\n',
         ...      Markup('<b>some bold text</b>')))
-        >>> print tags.generate() | Transformer('body').substitute(
-        ...     '(?i)some', 'SOME')
+        >>> print(tags.generate() | Transformer('body').substitute(
+        ...     '(?i)some', 'SOME'))
         <html><body>SOME text, some more text and
         <b>SOME bold text</b></body></html>
 
@@ -650,7 +650,7 @@
 
         >>> html = HTML('<html><body>Some text, some more text and '
         ...             '<b>some bold text</b></body></html>')
-        >>> print html | Transformer('body/b').rename('strong')
+        >>> print(html | Transformer('body/b').rename('strong'))
         <html><body>Some text, some more text and <strong>some bold text</strong></body></html>
         """
         return self.apply(RenameTransformation(name))
@@ -659,7 +659,7 @@
         """Print events as they pass through the transform.
 
         >>> html = HTML('<body>Some <em>test</em> text</body>')
-        >>> print html | Transformer('em').trace()
+        >>> print(html | Transformer('em').trace())
         (None, ('START', (QName(u'body'), Attrs()), (None, 1, 0)))
         (None, ('TEXT', u'Some ', (None, 1, 6)))
         ('ENTER', ('START', (QName(u'em'), Attrs()), (None, 1, 11)))
@@ -1025,7 +1025,7 @@
     ...         for event in stream:
     ...             yield event
     >>> html = HTML('<body>Some <em>test</em> text</body>')
-    >>> print html | Transformer('.//em').apply(Top('Prefix '))
+    >>> print(html | Transformer('.//em').apply(Top('Prefix ')))
     Prefix <body>Some <em>test</em> text</body>
     """
     def __init__(self, content):
--- a/genshi/input.py
+++ b/genshi/input.py
@@ -79,7 +79,7 @@
     
     >>> parser = XMLParser(StringIO('<root id="2"><child>Foo</child></root>'))
     >>> for kind, data, pos in parser:
-    ...     print kind, data
+    ...     print('%s %s' % (kind, data))
     START (QName(u'root'), Attrs([(QName(u'id'), u'2')]))
     START (QName(u'child'), Attrs())
     TEXT Foo
@@ -256,11 +256,11 @@
     iterated over multiple times:
     
     >>> xml = XML('<doc><elem>Foo</elem><elem>Bar</elem></doc>')
-    >>> print xml
+    >>> print(xml)
     <doc><elem>Foo</elem><elem>Bar</elem></doc>
-    >>> print xml.select('elem')
+    >>> print(xml.select('elem'))
     <elem>Foo</elem><elem>Bar</elem>
-    >>> print xml.select('elem/text()')
+    >>> print(xml.select('elem/text()'))
     FooBar
     
     :param text: the XML source
@@ -280,7 +280,7 @@
     
     >>> parser = HTMLParser(StringIO('<UL compact><LI>Foo</UL>'))
     >>> for kind, data, pos in parser:
-    ...     print kind, data
+    ...     print('%s %s' % (kind, data))
     START (QName(u'ul'), Attrs([(QName(u'compact'), u'compact')]))
     START (QName(u'li'), Attrs())
     TEXT Foo
@@ -409,11 +409,11 @@
     iterated over multiple times:
     
     >>> html = HTML('<body><h1>Foo</h1></body>')
-    >>> print html
+    >>> print(html)
     <body><h1>Foo</h1></body>
-    >>> print html.select('h1')
+    >>> print(html.select('h1'))
     <h1>Foo</h1>
-    >>> print html.select('h1/text()')
+    >>> print(html.select('h1/text()'))
     Foo
     
     :param text: the HTML source
--- a/genshi/output.py
+++ b/genshi/output.py
@@ -172,7 +172,7 @@
     
     >>> from genshi.builder import tag
     >>> elem = tag.div(tag.a(href='foo'), tag.br, tag.hr(noshade=True))
-    >>> print ''.join(XMLSerializer()(elem.generate()))
+    >>> print(''.join(XMLSerializer()(elem.generate())))
     <div><a href="foo"/><br/><hr noshade="True"/></div>
     """
 
@@ -285,7 +285,7 @@
     
     >>> from genshi.builder import tag
     >>> elem = tag.div(tag.a(href='foo'), tag.br, tag.hr(noshade=True))
-    >>> print ''.join(XHTMLSerializer()(elem.generate()))
+    >>> print(''.join(XHTMLSerializer()(elem.generate())))
     <div><a href="foo"></a><br /><hr noshade="noshade" /></div>
     """
 
@@ -413,7 +413,7 @@
     
     >>> from genshi.builder import tag
     >>> elem = tag.div(tag.a(href='foo'), tag.br, tag.hr(noshade=True))
-    >>> print ''.join(HTMLSerializer()(elem.generate()))
+    >>> print(''.join(HTMLSerializer()(elem.generate())))
     <div><a href="foo"></a><br><hr noshade></div>
     """
 
@@ -533,23 +533,23 @@
     
     >>> from genshi.builder import tag
     >>> elem = tag.div(tag.a('<Hello!>', href='foo'), tag.br)
-    >>> print elem
+    >>> print(elem)
     <div><a href="foo">&lt;Hello!&gt;</a><br/></div>
-    >>> print ''.join(TextSerializer()(elem.generate()))
+    >>> print(''.join(TextSerializer()(elem.generate())))
     <Hello!>
 
     If text events contain literal markup (instances of the `Markup` class),
     that markup is by default passed through unchanged:
     
     >>> elem = tag.div(Markup('<a href="foo">Hello &amp; Bye!</a><br/>'))
-    >>> print elem.generate().render(TextSerializer)
+    >>> print(elem.generate().render(TextSerializer))
     <a href="foo">Hello &amp; Bye!</a><br/>
     
     You can use the ``strip_markup`` to change this behavior, so that tags and
     entities are stripped from the output (or in the case of entities,
     replaced with the equivalent character):
 
-    >>> print elem.generate().render(TextSerializer, strip_markup=True)
+    >>> print(elem.generate().render(TextSerializer, strip_markup=True))
     Hello & Bye!
     """
 
@@ -607,7 +607,7 @@
     ...   <two:item/>
     ... </doc>''')
     >>> for kind, data, pos in NamespaceFlattener()(xml):
-    ...     print kind, repr(data)
+    ...     print('%s %r' % (kind, data))
     START (u'doc', Attrs([('xmlns', u'NS1'), (u'xmlns:two', u'NS2')]))
     TEXT u'\n  '
     START (u'two:item', Attrs())
--- a/genshi/path.py
+++ b/genshi/path.py
@@ -30,8 +30,8 @@
 ...       </item>
 ...   </items>
 ... </doc>''')
->>> 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
 
 Because the XPath engine operates on markup streams (as opposed to tree
@@ -558,10 +558,10 @@
         >>> from genshi.input import XML
         >>> xml = XML('<root><elem><child>Text</child></elem></root>')
         
-        >>> print Path('.//child').select(xml)
+        >>> print(Path('.//child').select(xml))
         <child>Text</child>
         
-        >>> print Path('.//child/text()').select(xml)
+        >>> print(Path('.//child/text()').select(xml))
         Text
         
         :param stream: the stream to select from
@@ -618,7 +618,7 @@
         >>> namespaces, variables = {}, {}
         >>> for event in xml:
         ...     if test(event, namespaces, variables):
-        ...         print event[0], repr(event[1])
+        ...         print('%s %r' % (event[0], event[1]))
         START (QName(u'child'), Attrs([(QName(u'id'), u'2')]))
         
         :param ignore_context: if `True`, the path is interpreted like a pattern
--- a/genshi/template/directives.py
+++ b/genshi/template/directives.py
@@ -144,11 +144,11 @@
     >>> tmpl = MarkupTemplate('''<ul xmlns:py="http://genshi.edgewall.org/">
     ...   <li py:attrs="foo">Bar</li>
     ... </ul>''')
-    >>> print tmpl.generate(foo={'class': 'collapse'})
+    >>> print(tmpl.generate(foo={'class': 'collapse'}))
     <ul>
       <li class="collapse">Bar</li>
     </ul>
-    >>> print tmpl.generate(foo=[('class', 'collapse')])
+    >>> print(tmpl.generate(foo=[('class', 'collapse')]))
     <ul>
       <li class="collapse">Bar</li>
     </ul>
@@ -156,7 +156,7 @@
     If the value evaluates to ``None`` (or any other non-truth value), no
     attributes are added:
     
-    >>> print tmpl.generate(foo=None)
+    >>> print(tmpl.generate(foo=None))
     <ul>
       <li>Bar</li>
     </ul>
@@ -195,7 +195,7 @@
     >>> tmpl = MarkupTemplate('''<ul xmlns:py="http://genshi.edgewall.org/">
     ...   <li py:content="bar">Hello</li>
     ... </ul>''')
-    >>> print tmpl.generate(bar='Bye')
+    >>> print(tmpl.generate(bar='Bye'))
     <ul>
       <li>Bye</li>
     </ul>
@@ -230,7 +230,7 @@
     ...   </p>
     ...   ${echo('Hi', name='you')}
     ... </div>''')
-    >>> print tmpl.generate(bar='Bye')
+    >>> print(tmpl.generate(bar='Bye'))
     <div>
       <p class="message">
         Hi, you!
@@ -246,7 +246,7 @@
     ...   </p>
     ...   ${helloworld()}
     ... </div>''')
-    >>> print tmpl.generate(bar='Bye')
+    >>> print(tmpl.generate(bar='Bye'))
     <div>
       <p class="message">
         Hello, world!
@@ -330,7 +330,7 @@
     >>> tmpl = MarkupTemplate('''<ul xmlns:py="http://genshi.edgewall.org/">
     ...   <li py:for="item in items">${item}</li>
     ... </ul>''')
-    >>> print tmpl.generate(items=[1, 2, 3])
+    >>> print(tmpl.generate(items=[1, 2, 3]))
     <ul>
       <li>1</li><li>2</li><li>3</li>
     </ul>
@@ -382,7 +382,7 @@
     >>> tmpl = MarkupTemplate('''<div xmlns:py="http://genshi.edgewall.org/">
     ...   <b py:if="foo">${bar}</b>
     ... </div>''')
-    >>> print tmpl.generate(foo=True, bar='Hello')
+    >>> print(tmpl.generate(foo=True, bar='Hello'))
     <div>
       <b>Hello</b>
     </div>
@@ -413,7 +413,7 @@
     ...   </span>
     ...   <greeting name="Dude" />
     ... </div>''')
-    >>> print tmpl.generate()
+    >>> print(tmpl.generate())
     <div>
       <span>
         Hello Dude
@@ -463,7 +463,7 @@
     >>> tmpl = MarkupTemplate('''<div xmlns:py="http://genshi.edgewall.org/">
     ...   <span py:replace="bar">Hello</span>
     ... </div>''')
-    >>> print tmpl.generate(bar='Bye')
+    >>> print(tmpl.generate(bar='Bye'))
     <div>
       Bye
     </div>
@@ -474,7 +474,7 @@
     >>> tmpl = MarkupTemplate('''<div xmlns:py="http://genshi.edgewall.org/">
     ...   <span py:content="bar" py:strip="">Hello</span>
     ... </div>''')
-    >>> print tmpl.generate(bar='Bye')
+    >>> print(tmpl.generate(bar='Bye'))
     <div>
       Bye
     </div>
@@ -502,7 +502,7 @@
     >>> tmpl = MarkupTemplate('''<div xmlns:py="http://genshi.edgewall.org/">
     ...   <div py:strip="True"><b>foo</b></div>
     ... </div>''')
-    >>> print tmpl.generate()
+    >>> print(tmpl.generate())
     <div>
       <b>foo</b>
     </div>
@@ -518,7 +518,7 @@
     ...   </div>
     ...   ${echo('foo')}
     ... </div>''')
-    >>> print tmpl.generate()
+    >>> print(tmpl.generate())
     <div>
         <b>foo</b>
     </div>
@@ -555,7 +555,7 @@
     ...   <span py:when="1 == 1">1</span>
     ...   <span py:otherwise="">2</span>
     ... </div>''')
-    >>> print tmpl.generate()
+    >>> print(tmpl.generate())
     <div>
       <span>1</span>
     </div>
@@ -569,7 +569,7 @@
     ...   <span py:when="1">1</span>
     ...   <span py:when="2">2</span>
     ... </div>''')
-    >>> print tmpl.generate()
+    >>> print(tmpl.generate())
     <div>
       <span>2</span>
     </div>
@@ -676,7 +676,7 @@
     >>> tmpl = MarkupTemplate('''<div xmlns:py="http://genshi.edgewall.org/">
     ...   <span py:with="y=7; z=x+10">$x $y $z</span>
     ... </div>''')
-    >>> print tmpl.generate(x=42)
+    >>> print(tmpl.generate(x=42))
     <div>
       <span>42 7 52</span>
     </div>
--- a/genshi/template/eval.py
+++ b/genshi/template/eval.py
@@ -229,7 +229,7 @@
     False
     >>> list(foo)
     []
-    >>> print foo
+    >>> print(foo)
     undefined
     
     However, calling an undefined variable, or trying to access an attribute
--- a/genshi/template/interpolation.py
+++ b/genshi/template/interpolation.py
@@ -44,7 +44,7 @@
     string.
     
     >>> for kind, data, pos in interpolate("hey ${foo}bar"):
-    ...     print kind, repr(data)
+    ...     print('%s %r' % (kind, data))
     TEXT u'hey '
     EXPR Expression('foo')
     TEXT u'bar'
--- a/genshi/template/loader.py
+++ b/genshi/template/loader.py
@@ -308,9 +308,9 @@
         ...     app1 = lambda filename: ('app1', filename, None, None),
         ...     app2 = lambda filename: ('app2', filename, None, None)
         ... )
-        >>> print load('app1/foo.html')
+        >>> print(load('app1/foo.html'))
         ('app1', 'app1/foo.html', None, None)
-        >>> print load('app2/bar.html')
+        >>> print(load('app2/bar.html'))
         ('app2', 'app2/bar.html', None, None)
         
         :param delegates: mapping of path prefixes to loader functions
--- a/genshi/template/markup.py
+++ b/genshi/template/markup.py
@@ -36,7 +36,7 @@
     >>> tmpl = MarkupTemplate('''<ul xmlns:py="http://genshi.edgewall.org/">
     ...   <li py:for="item in items">${item}</li>
     ... </ul>''')
-    >>> print tmpl.generate(items=[1, 2, 3])
+    >>> print(tmpl.generate(items=[1, 2, 3]))
     <ul>
       <li>1</li><li>2</li><li>3</li>
     </ul>
--- a/genshi/template/text.py
+++ b/genshi/template/text.py
@@ -61,7 +61,7 @@
     ...  * ${'Item %d' % item}
     ... {% end %}
     ... ''')
-    >>> print tmpl.generate(name='Joe', items=[1, 2, 3]).render()
+    >>> print(tmpl.generate(name='Joe', items=[1, 2, 3]).render())
     Dear Joe,
     <BLANKLINE>
     <BLANKLINE>
@@ -86,7 +86,7 @@
     ...  * $item
     ... {% end %}\
     ... ''')
-    >>> print tmpl.generate(name='Joe', items=[1, 2, 3]).render()
+    >>> print(tmpl.generate(name='Joe', items=[1, 2, 3]).render())
     Dear Joe,
     <BLANKLINE>
     We have the following items for you:
@@ -106,7 +106,7 @@
     ...  * $item
     ... {% end %}\
     ... ''')
-    >>> print tmpl.generate(name='Joe', items=[1, 2, 3]).render()
+    >>> print(tmpl.generate(name='Joe', items=[1, 2, 3]).render())
     Dear Joe,
     <BLANKLINE>
     {# This is a comment #}
@@ -248,7 +248,7 @@
     ... 
     ... All the best,
     ... Foobar''')
-    >>> print tmpl.generate(name='Joe', items=[1, 2, 3]).render()
+    >>> print(tmpl.generate(name='Joe', items=[1, 2, 3]).render())
     Dear Joe,
     <BLANKLINE>
     We have the following items for you:
--- a/genshi/util.py
+++ b/genshi/util.py
@@ -46,7 +46,7 @@
     used:
     
     >>> for key in cache:
-    ...     print key
+    ...     print(key)
     D
     A
     C
--- a/scripts/ast_generator.py
+++ b/scripts/ast_generator.py
@@ -20,24 +20,24 @@
                 print_class(base)
             bnames.append(base.__name__)
         elif base.__module__ == '__builtin__':
-            bnames.append("%s"%base.__name__)
+            bnames.append("%s" % base.__name__)
         else:
-            bnames.append("%s.%s"%(base.__module__,base.__name__))
-    print "class %s(%s):"%(cls.__name__, ", ".join(bnames))
+            bnames.append("%s.%s" % (base.__module__,base.__name__))
+    print("class %s(%s):" % (cls.__name__, ", ".join(bnames)))
     written = False
     for attr in cls.__dict__:
         if attr not in IGNORE_ATTRS:
             written = True
-            print "\t%s = %s"%(attr, repr(cls.__dict__[attr]),)
+            print("\t%s = %s" % (attr, repr(cls.__dict__[attr]),))
     if not written:
-        print "\tpass"
+        print("\tpass")
     done.add(cls)
 
-print "# Generated automatically, please do not edit"
-print "# Generator can be found in Genshi SVN, scripts/ast-generator.py"
-print
-print "__version__ = %s" % _ast.__version__
-print
+print('# Generated automatically, please do not edit')
+print('# Generator can be found in Genshi SVN, scripts/ast-generator.py')
+print('')
+print('__version__ = %s' % _ast.__version__)
+print('')
 
 for name in dir(_ast):
     cls = getattr(_ast, name)
--- a/setup.py
+++ b/setup.py
@@ -52,12 +52,12 @@
             self._unavailable(e)
 
     def _unavailable(self, exc):
-        print '*' * 70
-        print """WARNING:
+        print('*' * 70)
+        print("""WARNING:
 An optional C extension could not be compiled, speedups will not be
-available."""
-        print '*' * 70
-        print exc
+available.""")
+        print('*' * 70)
+        print(exc)
 
 
 if Feature:
Copyright (C) 2012-2017 Edgewall Software