mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
pep8 fixes, improve docs for proxy
move CaptureException into replay_views
This commit is contained in:
parent
bdcda1df6f
commit
14a12f95b2
@ -3,14 +3,24 @@ from io import BytesIO
|
||||
|
||||
from pywb.utils.bufferedreaders import ChunkedDataReader
|
||||
from pywb.utils.statusandheaders import StatusAndHeaders
|
||||
from pywb.utils.wbexception import WbException
|
||||
from pywb.utils.loaders import LimitReader
|
||||
|
||||
from pywb.framework.wbrequestresponse import WbResponse
|
||||
from pywb.framework.memento import MementoResponse
|
||||
|
||||
from pywb.framework.wbexceptions import CaptureException
|
||||
from pywb.warc.recordloader import ArchiveLoadFailed
|
||||
|
||||
from pywb.utils.loaders import LimitReader
|
||||
|
||||
#=================================================================
|
||||
class CaptureException(WbException):
|
||||
"""
|
||||
raised to indicate an issue with a specific capture
|
||||
and will be caught and result in a retry, if possible
|
||||
if not, will result in a 502
|
||||
"""
|
||||
def status(self):
|
||||
return '502 Internal Server Error'
|
||||
|
||||
|
||||
#=================================================================
|
||||
|
@ -4,12 +4,15 @@ import urlparse
|
||||
|
||||
from pywb.rewrite.url_rewriter import HttpsUrlRewriter
|
||||
|
||||
#=================================================================
|
||||
# An experimental router which combines both archival and proxy modes
|
||||
# http proxy mode support is very simple so far:
|
||||
# only latest capture is available currently
|
||||
|
||||
#=================================================================
|
||||
class ProxyArchivalRouter(ArchivalRouter):
|
||||
"""
|
||||
A router which combines both archival and proxy modes support
|
||||
First, request is treated as a proxy request using ProxyRouter
|
||||
Second, if not handled by the router, it is treated as a regular
|
||||
archival mode request.
|
||||
"""
|
||||
def __init__(self, routes, **kwargs):
|
||||
super(ProxyArchivalRouter, self).__init__(routes, **kwargs)
|
||||
request_class = routes[0].request_class
|
||||
@ -28,11 +31,18 @@ class ProxyArchivalRouter(ArchivalRouter):
|
||||
|
||||
|
||||
#=================================================================
|
||||
# Simple router which routes http proxy requests
|
||||
# Handles requests of the form: GET http://example.com
|
||||
# Only supports latest capture replay at the moment
|
||||
#=================================================================
|
||||
class ProxyRouter:
|
||||
class ProxyRouter(object):
|
||||
"""
|
||||
A router which supports http proxy mode requests
|
||||
Handles requests of the form: GET http://example.com
|
||||
|
||||
The router returns latest capture by default.
|
||||
However, if Memento protocol support is enabled,
|
||||
the memento Accept-Datetime header can be used
|
||||
to select specific capture.
|
||||
See: http://www.mementoweb.org/guide/rfc/#Pattern1.3
|
||||
for more details.
|
||||
"""
|
||||
def __init__(self, handler, **kwargs):
|
||||
self.handler = handler
|
||||
self.hostpaths = kwargs.get('hostpaths')
|
||||
|
@ -1,8 +0,0 @@
|
||||
from pywb.utils.wbexception import WbException
|
||||
|
||||
|
||||
# Exceptions that effect a specific capture and result in a retry
|
||||
class CaptureException(WbException):
|
||||
def status(self):
|
||||
return '502 Internal Server Error'
|
||||
|
@ -2,6 +2,7 @@ from pywb.utils.statusandheaders import StatusAndHeaders
|
||||
|
||||
import pprint
|
||||
|
||||
|
||||
#=================================================================
|
||||
class WbRequest(object):
|
||||
"""
|
||||
|
@ -13,6 +13,7 @@ def make_perms_cdx_filter(perms_policy, wbrequest):
|
||||
|
||||
return _create_cdx_perms_filter(perms_checker)
|
||||
|
||||
|
||||
#=================================================================
|
||||
def _create_cdx_perms_filter(perms_checker):
|
||||
"""
|
||||
|
@ -11,6 +11,7 @@ RESPONSE_TYPE = 'application/json'
|
||||
|
||||
NOT_FOUND = 'Please specify a url to check for access'
|
||||
|
||||
|
||||
#=================================================================
|
||||
class PermsHandler(WbUrlHandler):
|
||||
|
||||
|
@ -20,6 +20,7 @@ class UrlCanonicalizer(object):
|
||||
class UrlCanonicalizeException(BadRequestException):
|
||||
pass
|
||||
|
||||
|
||||
#=================================================================
|
||||
def canonicalize(url, surt_ordered=True):
|
||||
"""
|
||||
|
@ -10,6 +10,7 @@ import time
|
||||
import pkg_resources
|
||||
from io import open
|
||||
|
||||
|
||||
#=================================================================
|
||||
def is_http(filename):
|
||||
return filename.startswith(('http://', 'https://'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user