Merge branch 'lingua-extractor' of https://bitbucket.org/wichert/mako
diff --git a/doc/build/changelog.rst b/doc/build/changelog.rst
index 9f0e9f2..35d1237 100644
--- a/doc/build/changelog.rst
+++ b/doc/build/changelog.rst
@@ -6,6 +6,16 @@
 ===
 
 .. changelog::
+    :version: 1.0.1
+
+    .. change::
+        :tags: bug, py3k
+        :pullreq: bitbucket:11
+
+      Modernized the examples/wsgi/run_wsgi.py file for Py3k. 
+      Pull requset courtesy Cody Taylor.
+
+.. changelog::
     :version: 1.0.0
     :released: Sun Jun 8 2014
 
diff --git a/doc/build/defs.rst b/doc/build/defs.rst
index 31798d4..3c06840 100644
--- a/doc/build/defs.rst
+++ b/doc/build/defs.rst
@@ -139,8 +139,8 @@
         </%def>
     """)
 
-    print template.get_def("hi").render(name="ed")
-    print template.get_def("bye").render(name="ed")
+    print(template.get_def("hi").render(name="ed"))
+    print(template.get_def("bye").render(name="ed"))
 
 Defs within Defs
 ----------------
diff --git a/doc/build/unicode.rst b/doc/build/unicode.rst
index 16eb161..1ba364e 100644
--- a/doc/build/unicode.rst
+++ b/doc/build/unicode.rst
@@ -229,7 +229,7 @@
     mylookup = TemplateLookup(directories=['/docs'], output_encoding='utf-8', encoding_errors='replace')
 
     mytemplate = mylookup.get_template("foo.txt")
-    print mytemplate.render()
+    print(mytemplate.render())
 
 :meth:`~.Template.render` will return a ``bytes`` object in Python 3 if an output
 encoding is specified. By default it performs no encoding and
@@ -240,14 +240,14 @@
 
 .. sourcecode:: python
 
-    print mytemplate.render_unicode()
+    print(mytemplate.render_unicode())
 
 The above method disgards the output encoding keyword argument;
 you can encode yourself by saying:
 
 .. sourcecode:: python
 
-    print mytemplate.render_unicode().encode('utf-8', 'replace')
+    print(mytemplate.render_unicode().encode('utf-8', 'replace'))
 
 Buffer Selection
 ----------------
@@ -289,7 +289,7 @@
     from mako.template import Template
 
     t = Template("drôle de petite voix m’a réveillé.", disable_unicode=True, input_encoding='utf-8')
-    print t.code
+    print(t.code)
 
 The ``disable_unicode`` mode is strictly a Python 2 thing. It is
 not supported at all in Python 3.
diff --git a/doc/build/usage.rst b/doc/build/usage.rst
index d6e5338..ceb8d41 100644
--- a/doc/build/usage.rst
+++ b/doc/build/usage.rst
@@ -20,7 +20,7 @@
     from mako.template import Template
 
     mytemplate = Template("hello world!")
-    print mytemplate.render()
+    print(mytemplate.render())
 
 Above, the text argument to :class:`.Template` is **compiled** into a
 Python module representation. This module contains a function
@@ -41,7 +41,7 @@
     from mako.template import Template
 
     mytemplate = Template("hello, ${name}!")
-    print mytemplate.render(name="jack")
+    print(mytemplate.render(name="jack"))
 
 The :meth:`~.Template.render` method calls upon Mako to create a
 :class:`.Context` object, which stores all the variable names accessible
@@ -59,7 +59,7 @@
     buf = StringIO()
     ctx = Context(buf, name="jack")
     mytemplate.render_context(ctx)
-    print buf.getvalue()
+    print(buf.getvalue())
 
 Using File-Based Templates
 ==========================
@@ -72,7 +72,7 @@
     from mako.template import Template
 
     mytemplate = Template(filename='/docs/mytmpl.txt')
-    print mytemplate.render()
+    print(mytemplate.render())
 
 For improved performance, a :class:`.Template` which is loaded from a
 file can also cache the source code to its generated module on
@@ -85,7 +85,7 @@
     from mako.template import Template
 
     mytemplate = Template(filename='/docs/mytmpl.txt', module_directory='/tmp/mako_modules')
-    print mytemplate.render()
+    print(mytemplate.render())
 
 When the above code is rendered, a file
 ``/tmp/mako_modules/docs/mytmpl.txt.py`` is created containing the
@@ -138,7 +138,7 @@
 
     def serve_template(templatename, **kwargs):
         mytemplate = mylookup.get_template(templatename)
-        print mytemplate.render(**kwargs)
+        print(mytemplate.render(**kwargs))
 
 In the example above, we create a :class:`.TemplateLookup` which will
 look for templates in the ``/docs`` directory, and will store
@@ -206,7 +206,7 @@
     mylookup = TemplateLookup(directories=['/docs'], output_encoding='utf-8', encoding_errors='replace')
 
     mytemplate = mylookup.get_template("foo.txt")
-    print mytemplate.render()
+    print(mytemplate.render())
 
 When using Python 3, the :meth:`~.Template.render` method will return a ``bytes``
 object, **if** ``output_encoding`` is set. Otherwise it returns a
@@ -218,14 +218,14 @@
 
 .. sourcecode:: python
 
-    print mytemplate.render_unicode()
+    print(mytemplate.render_unicode())
 
 The above method disregards the output encoding keyword
 argument; you can encode yourself by saying:
 
 .. sourcecode:: python
 
-    print mytemplate.render_unicode().encode('utf-8', 'replace')
+    print(mytemplate.render_unicode().encode('utf-8', 'replace'))
 
 Note that Mako's ability to return data in any encoding and/or
 ``unicode`` implies that the underlying output stream of the
@@ -264,9 +264,9 @@
 
     try:
         template = lookup.get_template(uri)
-        print template.render()
+        print(template.render())
     except:
-        print exceptions.text_error_template().render()
+        print(exceptions.text_error_template().render())
 
 Or for the HTML render function:
 
@@ -276,9 +276,9 @@
 
     try:
         template = lookup.get_template(uri)
-        print template.render()
+        print(template.render())
     except:
-        print exceptions.html_error_template().render()
+        print(exceptions.html_error_template().render())
 
 The :func:`.html_error_template` template accepts two options:
 specifying ``full=False`` causes only a section of an HTML
@@ -289,7 +289,7 @@
 
 .. sourcecode:: python
 
-    print exceptions.html_error_template().render(full=False)
+    print(exceptions.html_error_template().render(full=False))
 
 The HTML render function is also available built-in to
 :class:`.Template` using the ``format_exceptions`` flag. In this case, any
@@ -300,7 +300,7 @@
 .. sourcecode:: python
 
     template = Template(filename="/foo/bar", format_exceptions=True)
-    print template.render()
+    print(template.render())
 
 Note that the compile stage of the above template occurs when
 you construct the :class:`.Template` itself, and no output stream is
@@ -324,13 +324,13 @@
 
     try:
         template = lookup.get_template(uri)
-        print template.render()
+        print(template.render())
     except:
         traceback = RichTraceback()
         for (filename, lineno, function, line) in traceback.traceback:
-            print "File %s, line %s, in %s" % (filename, lineno, function)
-            print line, "\n"
-        print "%s: %s" % (str(traceback.error.__class__.__name__), traceback.error)
+            print("File %s, line %s, in %s" % (filename, lineno, function))
+            print(line, "\n")
+        print("%s: %s" % (str(traceback.error.__class__.__name__), traceback.error))
 
 Common Framework Integrations
 =============================
diff --git a/examples/wsgi/run_wsgi.py b/examples/wsgi/run_wsgi.py
index 6e86406..270022d 100644
--- a/examples/wsgi/run_wsgi.py
+++ b/examples/wsgi/run_wsgi.py
@@ -1,14 +1,25 @@
 #!/usr/bin/python
 
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import cgi, re, os, posixpath, mimetypes
 from mako.lookup import TemplateLookup
 from mako import exceptions
 
 root = './'
 port = 8000
-error_style = 'html' # select 'text' for plaintext error reporting
 
-lookup = TemplateLookup(directories=[root + 'templates', root + 'htdocs'], filesystem_checks=True, module_directory='./modules')
+lookup = TemplateLookup(
+             directories=[root + 'templates', root + 'htdocs'],
+             filesystem_checks=True,
+             module_directory='./modules',
+             # even better would be to use 'charset' in start_response
+             output_encoding='ascii',
+             encoding_errors='replace'
+         )
 
 def serve(environ, start_response):
     """serves requests using the WSGI callable interface."""
@@ -28,23 +39,25 @@
     if re.match(r'.*\.html$', uri):
         try:
             template = lookup.get_template(uri)
-            start_response("200 OK", [('Content-type','text/html')])
-            return [template.render(**d)]
         except exceptions.TopLevelLookupException:
             start_response("404 Not Found", [])
-            return ["Cant find template '%s'" % uri]
+            return [str.encode("Cant find template '%s'" % uri)]
+
+        start_response("200 OK", [('Content-type','text/html')])
+
+        try:
+            return [template.render(**d)]
         except:
-            if error_style == 'text':
-                start_response("200 OK", [('Content-type','text/plain')])
-                return [exceptions.text_error_template().render()]
-            else:
-                start_response("200 OK", [('Content-type','text/html')])
-                return [exceptions.html_error_template().render()]
+            return [exceptions.html_error_template().render()]
     else:
         u = re.sub(r'^\/+', '', uri)
         filename = os.path.join(root, u)
-        start_response("200 OK", [('Content-type',guess_type(uri))])
-        return [file(filename).read()]
+        if os.path.isfile(filename):
+            start_response("200 OK", [('Content-type',guess_type(uri))])
+            return [open(filename, 'rb').read()]
+        else:
+            start_response("404 Not Found", [])
+            return [str.encode("File not found: '%s'" % filename)]
  
 def getfield(f):
     """convert values from cgi.Field objects to plain values."""
@@ -54,9 +67,6 @@
         return f.value
 
 extensions_map = mimetypes.types_map.copy()
-extensions_map.update({
-'': 'text/html', # Default
-})
 
 def guess_type(path):
     """return a mimetype for the given path based on file extension."""
@@ -67,12 +77,10 @@
     if ext in extensions_map:
         return extensions_map[ext]
     else:
-        return extensions_map['']
+        return 'text/html'
  
 if __name__ == '__main__':
     import wsgiref.simple_server
     server = wsgiref.simple_server.make_server('', port, serve)
-    print "Server listening on port %d" % port
+    print("Server listening on port %d" % port)
     server.serve_forever()
-
-
diff --git a/mako/__init__.py b/mako/__init__.py
index 52a1c05..c8c18e8 100644
--- a/mako/__init__.py
+++ b/mako/__init__.py
@@ -5,7 +5,7 @@
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
 
-__version__ = '1.0.0'
+__version__ = '1.0.1'
 
 
 
diff --git a/mako/ext/preprocessors.py b/mako/ext/preprocessors.py
index 94569c5..6be1d2d 100644
--- a/mako/ext/preprocessors.py
+++ b/mako/ext/preprocessors.py
@@ -15,6 +15,6 @@
     example:
  
     from mako.ext.preprocessors import convert_comments
-    t = Template(..., preprocessor=preprocess_comments)"""
+    t = Template(..., preprocessor=convert_comments)"""
     return re.sub(r'(?<=\n)\s*#[^#]', "##", text)