mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
cleanup wbexceptions, remove unused
This commit is contained in:
parent
5345459298
commit
94f1dc3be5
@ -1,6 +1,5 @@
|
|||||||
import urlparse
|
import urlparse
|
||||||
import re
|
import re
|
||||||
import wbexceptions
|
|
||||||
|
|
||||||
from wbrequestresponse import WbRequest, WbResponse
|
from wbrequestresponse import WbRequest, WbResponse
|
||||||
from pywb.rewrite.url_rewriter import UrlRewriter
|
from pywb.rewrite.url_rewriter import UrlRewriter
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
import wbexceptions
|
|
||||||
|
from wbexceptions import NotFoundException
|
||||||
|
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
@ -30,15 +31,13 @@ class IndexReader(object):
|
|||||||
params.update(wbrequest.custom_params)
|
params.update(wbrequest.custom_params)
|
||||||
|
|
||||||
params['url'] = wburl.url
|
params['url'] = wburl.url
|
||||||
try:
|
|
||||||
cdxlines = self.load_cdx(output='raw', **params)
|
cdxlines = self.load_cdx(output='raw', **params)
|
||||||
except CDXException:
|
|
||||||
raise wbexceptions.BadUrlException('Bad Request Url: ' + wburl.url)
|
|
||||||
|
|
||||||
cdxlines = self.peek_iter(cdxlines)
|
cdxlines = self.peek_iter(cdxlines)
|
||||||
|
|
||||||
if cdxlines is None:
|
if cdxlines is None:
|
||||||
raise wbexceptions.NotFoundException('WB Does Not Have Url: ' + wburl.url)
|
raise NotFoundException('No Captures found for: ' + wburl.url)
|
||||||
|
|
||||||
return cdxlines
|
return cdxlines
|
||||||
|
|
||||||
|
@ -4,7 +4,8 @@ from pywb.rewrite.url_rewriter import UrlRewriter
|
|||||||
from pywb.utils.bufferedreaders import ChunkedDataReader
|
from pywb.utils.bufferedreaders import ChunkedDataReader
|
||||||
from wbrequestresponse import WbResponse
|
from wbrequestresponse import WbResponse
|
||||||
|
|
||||||
import wbexceptions
|
from wbexceptions import CaptureException, InternalRedirect
|
||||||
|
from pywb.warc.recordloader import ArchiveLoadFailed
|
||||||
|
|
||||||
|
|
||||||
#=================================================================
|
#=================================================================
|
||||||
@ -64,7 +65,7 @@ class ReplayView:
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
except wbexceptions.CaptureException as ce:
|
except (CaptureException, ArchiveLoadFailed) as ce:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
last_e = ce
|
last_e = ce
|
||||||
@ -73,7 +74,7 @@ class ReplayView:
|
|||||||
if last_e:
|
if last_e:
|
||||||
raise last_e
|
raise last_e
|
||||||
else:
|
else:
|
||||||
raise wbexceptions.UnresolvedArchiveFileException()
|
raise WbException('No Content Loaded for: ' + wbrequest.wb_url)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stream_to_iter(stream):
|
def stream_to_iter(stream):
|
||||||
@ -141,7 +142,7 @@ class ReplayView:
|
|||||||
def _redirect_if_needed(self, wbrequest, cdx):
|
def _redirect_if_needed(self, wbrequest, cdx):
|
||||||
if self.redir_to_exact and not wbrequest.is_proxy and cdx and (cdx['timestamp'] != wbrequest.wb_url.timestamp):
|
if self.redir_to_exact and not wbrequest.is_proxy and cdx and (cdx['timestamp'] != wbrequest.wb_url.timestamp):
|
||||||
new_url = wbrequest.urlrewriter.get_timestamp_url(cdx['timestamp'], cdx['original'])
|
new_url = wbrequest.urlrewriter.get_timestamp_url(cdx['timestamp'], cdx['original'])
|
||||||
raise wbexceptions.InternalRedirect(new_url)
|
raise InternalRedirect(new_url)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -153,5 +154,5 @@ class ReplayView:
|
|||||||
|
|
||||||
#TODO: canonicalize before testing?
|
#TODO: canonicalize before testing?
|
||||||
if (UrlRewriter.strip_protocol(request_url) == UrlRewriter.strip_protocol(location_url)):
|
if (UrlRewriter.strip_protocol(request_url) == UrlRewriter.strip_protocol(location_url)):
|
||||||
raise wbexceptions.CaptureException('Self Redirect: ' + str(cdx))
|
raise CaptureException('Self Redirect: ' + str(cdx))
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import pywb.utils.timeutils as timeutils
|
import pywb.utils.timeutils as timeutils
|
||||||
|
|
||||||
import wbrequestresponse
|
import wbrequestresponse
|
||||||
import wbexceptions
|
|
||||||
import urlparse
|
import urlparse
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import wbexceptions
|
from wbexceptions import WbException, NotFoundException, InternalRedirect
|
||||||
|
|
||||||
from wbrequestresponse import WbResponse, StatusAndHeaders
|
from wbrequestresponse import WbResponse, StatusAndHeaders
|
||||||
|
|
||||||
from pywb.cdx.cdxserver import CDXException
|
from pywb.cdx.cdxserver import CDXException
|
||||||
|
from pywb.warc.recordloader import ArchiveLoadFailed
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import importlib
|
import importlib
|
||||||
@ -49,17 +50,14 @@ def create_wb_app(wb_router):
|
|||||||
response = wb_router(env)
|
response = wb_router(env)
|
||||||
|
|
||||||
if not response:
|
if not response:
|
||||||
raise wbexceptions.NotFoundException('No handler for "{0}"'.format(env['REL_REQUEST_URI']))
|
raise NotFoundException('No handler for "{0}"'.format(env['REL_REQUEST_URI']))
|
||||||
|
|
||||||
except wbexceptions.InternalRedirect as ir:
|
except InternalRedirect as ir:
|
||||||
response = WbResponse(StatusAndHeaders(ir.status, ir.httpHeaders))
|
response = WbResponse(StatusAndHeaders(ir.status, ir.httpHeaders))
|
||||||
|
|
||||||
except (wbexceptions.NotFoundException, wbexceptions.AccessException) as e:
|
except (WbException, CDXException, ArchiveLoadFailed) as e:
|
||||||
response = handle_exception(env, wb_router.error_view, e, False)
|
response = handle_exception(env, wb_router.error_view, e, False)
|
||||||
|
|
||||||
except (wbexceptions.WbException, CDXException) as wbe:
|
|
||||||
response = handle_exception(env, wb_router.error_view, wbe, False)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
response = handle_exception(env, wb_router.error_view, e, True)
|
response = handle_exception(env, wb_router.error_view, e, True)
|
||||||
|
|
||||||
|
@ -2,26 +2,6 @@
|
|||||||
class WbException(Exception):
|
class WbException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class RequestParseException(WbException):
|
|
||||||
def __init__(self, string, to_parse):
|
|
||||||
WbException.__init__(self, string + to_parse)
|
|
||||||
self.to_parse = to_parse
|
|
||||||
|
|
||||||
def status(_):
|
|
||||||
return '400 Bad Request'
|
|
||||||
|
|
||||||
class BadUrlException(WbException):
|
|
||||||
def status(_):
|
|
||||||
return '400 Bad Request'
|
|
||||||
|
|
||||||
class AccessException(WbException):
|
|
||||||
def status(_):
|
|
||||||
return '403 Forbidden'
|
|
||||||
|
|
||||||
class InvalidCDXException(WbException):
|
|
||||||
def status(_):
|
|
||||||
return '500 Internal Server Error'
|
|
||||||
|
|
||||||
class NotFoundException(WbException):
|
class NotFoundException(WbException):
|
||||||
def status(_):
|
def status(_):
|
||||||
return '404 Not Found'
|
return '404 Not Found'
|
||||||
@ -31,29 +11,6 @@ class CaptureException(WbException):
|
|||||||
def status(_):
|
def status(_):
|
||||||
return '500 Internal Server Error'
|
return '500 Internal Server Error'
|
||||||
|
|
||||||
class UnresolvedArchiveFileException(CaptureException):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class UnknownArchiveFormatException(CaptureException):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class UnknownLoaderProtocolException(CaptureException):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class InvalidArchiveRecordException(CaptureException):
|
|
||||||
def __init__(self, msg, errList = None):
|
|
||||||
super(InvalidArchiveRecordException, self).__init__(msg)
|
|
||||||
self.errList = errList
|
|
||||||
|
|
||||||
class ArchiveLoadFailed(CaptureException):
|
|
||||||
def __init__(self, filename, reason):
|
|
||||||
super(ArchiveLoadFailed, self).__init__(filename + ':' + str(reason))
|
|
||||||
self.filename = filename
|
|
||||||
self.reason = reason
|
|
||||||
|
|
||||||
def status(_):
|
|
||||||
return '503 Service Unavailable'
|
|
||||||
|
|
||||||
class InternalRedirect(WbException):
|
class InternalRedirect(WbException):
|
||||||
def __init__(self, location, status = '302 Internal Redirect'):
|
def __init__(self, location, status = '302 Internal Redirect'):
|
||||||
WbException.__init__(self, 'Redirecting -> ' + location)
|
WbException.__init__(self, 'Redirecting -> ' + location)
|
||||||
|
@ -160,7 +160,7 @@ class TestWb:
|
|||||||
def test_error(self):
|
def test_error(self):
|
||||||
resp = self.testapp.get('/pywb/?abc', status = 400)
|
resp = self.testapp.get('/pywb/?abc', status = 400)
|
||||||
assert resp.status_int == 400
|
assert resp.status_int == 400
|
||||||
assert 'Bad Request Url: http://?abc' in resp.body
|
assert 'Invalid Url: http://?abc' in resp.body
|
||||||
|
|
||||||
# Reporter callback for replay view
|
# Reporter callback for replay view
|
||||||
def print_reporter(wbrequest, cdx, response):
|
def print_reporter(wbrequest, cdx, response):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user