Commits

Anonymous committed 5a51437

Python 3.3 and Python 3.x compat

  • Participants
  • Parent commits b0a7c7b

Comments (0)

Files changed (2)

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to:
 
-The Free Software Foundation, Inc., 
-51 Franklin Street, Fifth Floor, 
+The Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor,
 Boston, MA  02110-1301, USA.
 
 Luke Arno can be found at http://lukearno.com/
 except:
     from distutils.core import setup
 
+import sys
+PY3 = sys.version > '3'
+if PY3:
+  # wsgiref is now in Python stdlib
+    install_requires = ()
+else:
+  # For older versions of Python
+    install_requires = "wsgiref"
+
 setup(name='static',
       version='0.4',
       description=\
         'A really simple WSGI way to serve static (or mixed) content.',
       long_description="""\
-This distribution provides an easy way to include static content 
-in your WSGI applications. There is a convenience method for serving 
-files located via pkg_resources. There are also facilities for serving 
-mixed (static and dynamic) content using "magic" file handlers. 
-Python builtin string substitution and Kid template support are provided 
-and it is easy to roll your own handlers. Note that this distribution 
-does not require Kid unless you want to use that type of template. Also 
-provides a command of the same name as a convenience when you just want 
+This distribution provides an easy way to include static content
+in your WSGI applications. There is a convenience method for serving
+files located via pkg_resources. There are also facilities for serving
+mixed (static and dynamic) content using "magic" file handlers.
+Python builtin string substitution and Kid template support are provided
+and it is easy to roll your own handlers. Note that this distribution
+does not require Kid unless you want to use that type of template. Also
+provides a command of the same name as a convenience when you just want
 to share a little content over HTTP, ad hoc.""",
       author='Luke Arno',
       author_email='luke.arno@gmail.com',
       license="LGPL",
       py_modules=['static'],
       packages = [],
-      install_requires="wsgiref",
+      install_requires=install_requires,
       extras_require={'KidMagic': 'kid'},
       entry_points = """
           [console_scripts]
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to:
 
-The Free Software Foundation, Inc., 
-51 Franklin Street, Fifth Floor, 
+The Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor,
 Boston, MA  02110-1301, USA.
 
 Luke Arno can be found at http://lukearno.com/
         if not self._is_under_root(full_path):
             return self.not_found(environ, start_response)
         if path.isdir(full_path):
-            if full_path[-1] <> '/' or full_path == self.root:
+            if full_path[-1] != '/' or full_path == self.root:
                 location = util.request_uri(environ, include_query=False) + '/'
                 if environ.get('QUERY_STRING'):
                     location += '?' + environ.get('QUERY_STRING')
                 return self._body(full_path, environ, file_like)
             else:
                 return ['']
-        except (IOError, OSError), e:
-            print e
+        except (IOError, OSError) as e:
+            print(e)
             return self.not_found(environ, start_response)
 
     def _full_path(self, path_info):
             block = file_like.read(block_size)
             if block: yield block
             else: raise StopIteration
-        except StopIteration, si:
+        except StopIteration:
             file_like.close()
             return 
 
     """Return a Cling that serves from the given package and dir_name.
     
     This uses pkg_resources.resource_filename which is not the
-    recommended way, since it extracts the files. 
+    recommended way, since it extracts the files.
     
-    I think this works fine unless you have some _very_ serious 
-    requirements for static content, in which case you probably 
+    I think this works fine unless you have some _very_ serious
+    requirements for static content, in which case you probably
     shouldn't be serving it through a WSGI app, IMHO. YMMV.
     """
     resource = Requirement.parse(package_name)
         if self.matches(full_path):
             return full_path[:-len(self.extension)]
         else:
-            raise MagicError, "Path does not match this magic."
+            raise MagicError("Path does not match this magic.")
 
     def matches(self, full_path):
         """Check that path ends with self.extension."""
     
     def body(self, environ, full_path):
         """Pass environ and **self.variables into the template."""
-        template = kid.Template(file=full_path, 
-                                environ=environ, 
+        template = kid.Template(file=full_path,
+                                environ=environ,
                                 **self.variables)
         return [template.serialize()]
 
 
 def command():
-    parser = OptionParser(usage="%prog DIR [HOST][:][PORT]", 
+    parser = OptionParser(usage="%prog DIR [HOST][:][PORT]",
                           version="static 0.3.6")
     options, args = parser.parse_args()
     if len(args) in (1, 2):
         app = Cling(args[0])
         try:
             make_server(host, port, app).serve_forever()
-        except KeyboardInterrupt, ki:
-            print "Cio, baby!"
+        except KeyboardInterrupt:
+            print("Cio, baby!")
         except:
             sys.exit("Problem initializing server.")
     else:
     app = Shock('testdata/pub', magics=magics)
     try:
         make_server('localhost', 9999, validator(app)).serve_forever()
-    except KeyboardInterrupt, ki:
-        print "Ciao, baby!"
+    except KeyboardInterrupt:
+        print("Ciao, baby!")
 
 
 if __name__ == '__main__':