Index: quintagroup.distrpoxy/trunk/quintagroup/distproxy/wsgi.py =================================================================== --- quintagroup.distrpoxy/trunk/quintagroup/distproxy/wsgi.py (revision 1066) +++ quintagroup.distrpoxy/trunk/quintagroup/distproxy/wsgi.py (revision 1082) @@ -4,4 +4,6 @@ from paste.script.appinstall import Installer as BaseInstaller from paste.fileapp import FileApp +from paste import urlparser +from paste import request from paste.httpexceptions import HTTPNotFound from spider import webmirror @@ -24,7 +26,7 @@ def __call__(self, environ, start_response): path = environ.get('PATH_INFO', '').strip() - filename = self.checkCache(path) - if path.split('/')[0] == "favicon.ico": - return HTTPNotFound()(environ, start_response) + if path.split('/')[1] == "favicon.ico": + return HTTPNotFound()(environ, start_response) + filename = self.checkCache(path) if filename is None: return HTTPNotFound()(environ, start_response) @@ -39,5 +41,5 @@ pth = '/'.join(pth.split('/')[:-1]) if not os.path.exists(pth1): - webmirror(pth,1,self.index_url+path,0,1) + webmirror(pth,1,self.index_url+path,0,1) if pth1: return pth1 @@ -50,4 +52,77 @@ index_url = local_conf.get('index', None) return PackageProxyApp(index_url, pack_dir) + +class StaticURLParser(urlparser.StaticURLParser): + + def __call__(self, environ, start_response): + path_info = environ.get('PATH_INFO', '') + if not path_info: + return self.add_slash(environ, start_response) + if path_info == '/': + # @@: This should obviously be configurable + filename = 'index.html' + else: + filename = request.path_info_pop(environ) + full = os.path.normcase(os.path.normpath( + os.path.join(self.directory, filename))) + if os.path.sep != '/': + full = full.replace('/', os.path.sep) + if self.root_directory is not None and not full.startswith(self.root_directory): + # Out of bounds + return self.not_found(environ, start_response) + if not os.path.exists(full): + if full.endswith('index.html') and not os.path.isfile(full): + start_response('200 OK', []) + return [self.get_index_html()] + return self.not_found(environ, start_response) + if os.path.isdir(full): + # @@: Cache? + child_root = self.root_directory is not None and \ + self.root_directory or self.directory + return self.__class__(full, root_directory=child_root, + cache_max_age=self.cache_max_age)(environ, + start_response) + if environ.get('PATH_INFO') and environ.get('PATH_INFO') != '/': + return self.error_extra_path(environ, start_response) + if_none_match = environ.get('HTTP_IF_NONE_MATCH') + if if_none_match: + mytime = os.stat(full).st_mtime + if str(mytime) == if_none_match: + headers = [] + ETAG.update(headers, mytime) + start_response('304 Not Modified', headers) + return [''] # empty body + + fa = self.make_app(full) + if self.cache_max_age: + fa.cache_control(max_age=self.cache_max_age) + return fa(environ, start_response) + + def get_index_html(self): + path = self.directory + # create sorted lists of directories and files + names = os.listdir(path) + dirs = [i for i in names if os.path.isdir(os.path.join(path, i))] + dirs.sort() + files = [i for i in names if os.path.isfile(os.path.join(path, i))] + files.sort() + names = dirs + files + links = '\n'.join(['