changeset 27:fb03f34a982f

stub using new fileserver
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 29 Feb 2012 16:51:04 -0800
parents f8ff95180d04
children e86a17fbe50f
files simpypi/factory.py
diffstat 1 files changed, 1 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/simpypi/factory.py	Wed Feb 29 16:43:46 2012 -0800
+++ b/simpypi/factory.py	Wed Feb 29 16:51:04 2012 -0800
@@ -10,52 +10,10 @@
 import sys
 import tempfile
 
-from paste.httpexceptions import HTTPExceptionHandler
-from paste.urlparser import StaticURLParser
-from pkg_resources import resource_filename
+from fileserver import DirectoryServer
 from wsgi import SimPyPI
 from wsgiref import simple_server
 
-class DirectoryServer(StaticURLParser):
-    def __init__(self, directory):
-        StaticURLParser.__init__(self, directory)
-
-    def index(self, directory):
-        """
-        generate a directory listing for a given directory
-        """
-        parts = ['<html><head><title>Simple Index</title></head><body>']
-        listings = os.listdir(directory)
-        listings = [(os.path.isdir(os.path.join(directory, entry)) and entry + '/' or entry, entry)
-                    for entry in listings]
-        for link, entry in listings:
-            parts.append('<a href="%s">%s</a><br/>' % (link, entry))
-        parts.append('</body></html>')
-        return '\n'.join(parts)
-
-    def __call__(self, environ, start_response):
-
-        # normalize path
-        # from paste.urlparser.StaticURLParser
-        path_info = environ.get('PATH_INFO', '')
-        if not path_info:
-            return self.add_slash(environ, start_response)
-        full = self.normpath(os.path.join(self.directory, path_info.strip('/')))
-        if not full.startswith(self.root_directory):
-            # Out of bounds
-            return self.not_found(environ, start_response)
-
-        # return index listing
-        if os.path.isdir(full):
-            if not path_info.endswith('/'):
-                return self.add_slash(environ, start_response)
-            index = self.index(full)
-            response_headers = [('Content-Type', 'text/html'),
-                                ('Content-Length', str(len(index)))]
-            start_response('200 OK', response_headers)
-            return [index]
-
-        return StaticURLParser.__call__(self, environ, start_response)
 
 class PassthroughFileserver(object):
     """serve files if they exist"""