mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
cleanup wbexceptions, remove unused
This commit is contained in:
parent
5345459298
commit
94f1dc3be5
@ -1,6 +1,5 @@
|
||||
import urlparse
|
||||
import re
|
||||
import wbexceptions
|
||||
|
||||
from wbrequestresponse import WbRequest, WbResponse
|
||||
from pywb.rewrite.url_rewriter import UrlRewriter
|
||||
|
@ -1,6 +1,7 @@
|
||||
import urllib
|
||||
import urllib2
|
||||
import wbexceptions
|
||||
|
||||
from wbexceptions import NotFoundException
|
||||
|
||||
from itertools import chain
|
||||
from pprint import pprint
|
||||
@ -30,15 +31,13 @@ class IndexReader(object):
|
||||
params.update(wbrequest.custom_params)
|
||||
|
||||
params['url'] = wburl.url
|
||||
try:
|
||||
cdxlines = self.load_cdx(output='raw', **params)
|
||||
except CDXException:
|
||||
raise wbexceptions.BadUrlException('Bad Request Url: ' + wburl.url)
|
||||
|
||||
cdxlines = self.load_cdx(output='raw', **params)
|
||||
|
||||
cdxlines = self.peek_iter(cdxlines)
|
||||
|
||||
if cdxlines is None:
|
||||
raise wbexceptions.NotFoundException('WB Does Not Have Url: ' + wburl.url)
|
||||
raise NotFoundException('No Captures found for: ' + wburl.url)
|
||||
|
||||
return cdxlines
|
||||
|
||||
|
@ -4,7 +4,8 @@ from pywb.rewrite.url_rewriter import UrlRewriter
|
||||
from pywb.utils.bufferedreaders import ChunkedDataReader
|
||||
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
|
||||
|
||||
|
||||
except wbexceptions.CaptureException as ce:
|
||||
except (CaptureException, ArchiveLoadFailed) as ce:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
last_e = ce
|
||||
@ -73,7 +74,7 @@ class ReplayView:
|
||||
if last_e:
|
||||
raise last_e
|
||||
else:
|
||||
raise wbexceptions.UnresolvedArchiveFileException()
|
||||
raise WbException('No Content Loaded for: ' + wbrequest.wb_url)
|
||||
|
||||
@staticmethod
|
||||
def stream_to_iter(stream):
|
||||
@ -141,7 +142,7 @@ class ReplayView:
|
||||
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):
|
||||
new_url = wbrequest.urlrewriter.get_timestamp_url(cdx['timestamp'], cdx['original'])
|
||||
raise wbexceptions.InternalRedirect(new_url)
|
||||
raise InternalRedirect(new_url)
|
||||
|
||||
return None
|
||||
|
||||
@ -153,5 +154,5 @@ class ReplayView:
|
||||
|
||||
#TODO: canonicalize before testing?
|
||||
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 wbrequestresponse
|
||||
import wbexceptions
|
||||
import urlparse
|
||||
import time
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
import wbexceptions
|
||||
|
||||
from wbexceptions import WbException, NotFoundException, InternalRedirect
|
||||
from wbrequestresponse import WbResponse, StatusAndHeaders
|
||||
|
||||
from pywb.cdx.cdxserver import CDXException
|
||||
from pywb.warc.recordloader import ArchiveLoadFailed
|
||||
|
||||
import os
|
||||
import importlib
|
||||
@ -49,17 +50,14 @@ def create_wb_app(wb_router):
|
||||
response = wb_router(env)
|
||||
|
||||
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))
|
||||
|
||||
except (wbexceptions.NotFoundException, wbexceptions.AccessException) as e:
|
||||
except (WbException, CDXException, ArchiveLoadFailed) as e:
|
||||
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:
|
||||
response = handle_exception(env, wb_router.error_view, e, True)
|
||||
|
||||
|
@ -2,26 +2,6 @@
|
||||
class WbException(Exception):
|
||||
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):
|
||||
def status(_):
|
||||
return '404 Not Found'
|
||||
@ -31,29 +11,6 @@ class CaptureException(WbException):
|
||||
def status(_):
|
||||
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):
|
||||
def __init__(self, location, status = '302 Internal Redirect'):
|
||||
WbException.__init__(self, 'Redirecting -> ' + location)
|
||||
|
@ -160,7 +160,7 @@ class TestWb:
|
||||
def test_error(self):
|
||||
resp = self.testapp.get('/pywb/?abc', status = 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
|
||||
def print_reporter(wbrequest, cdx, response):
|
||||
|
Loading…
x
Reference in New Issue
Block a user