1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

Merge pull request #3 from jcushman/master

wsgiref compatibility fixes
This commit is contained in:
ikreymer 2014-01-19 16:00:13 -08:00
commit 628c130261
3 changed files with 18 additions and 8 deletions

View File

@ -107,6 +107,14 @@ def iso_date_to_timestamp(string):
return datetime_to_timestamp(iso_date_to_datetime(string))
# adapted from wsgiref.request_uri, but doesn't include domain name and allows ':' in url
def request_uri(environ, include_query=1):
"""Return the requested path, optionally including the query string"""
from urllib import quote
url = quote(environ.get('SCRIPT_NAME', '')+environ.get('PATH_INFO',''),safe='/;=,:')
if include_query and environ.get('QUERY_STRING'):
url += '?' + environ['QUERY_STRING']
return url
if __name__ == "__main__":

View File

@ -1,3 +1,4 @@
from utils import request_uri
from query import QueryHandler, EchoEnv, EchoRequest
from replay import WBHandler
import wbexceptions
@ -81,6 +82,7 @@ except:
def application(env, start_response):
env['REQUEST_URI'] = request_uri(env)
response = None
try:

View File

@ -1,28 +1,28 @@
class RequestParseException(Exception):
def status(_):
return '400'
return '400 Bad Request'
class BadUrlException(Exception):
def status(_):
return '400'
return '400 Bad Request'
class AccessException(Exception):
def status(_):
return '403'
return '403 Forbidden'
class InvalidCDXException(Exception):
def status(_):
return '500'
return '500 Internal Server Error'
class NotFoundException(Exception):
def status(_):
return '404'
return '404 Not Found'
# Exceptions that effect a specific capture and result in a retry
class CaptureException(Exception):
def status(_):
return '500'
return '500 Internal Server Error'
class UnresolvedArchiveFileException(CaptureException):
pass
@ -45,7 +45,7 @@ class ArchiveLoadFailed(CaptureException):
self.reason = reason
def status(_):
return '503'
return '503 Service Unavailable'
class InternalRedirect(Exception):
def __init__(self, location, status = '302 Internal Redirect'):
@ -53,6 +53,6 @@ class InternalRedirect(Exception):
self.status = status
self.httpHeaders = [('Location', location)]
def status(_):
def status(self):
return self.status