How to use the pywb.utils.wbexception.WbException function in pywb

To help you get started, we’ve selected a few pywb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webrecorder / pywb / pywb / utils / wbexception.py View on Github external
#=================================================================
class AccessException(WbException):
    def status(self):
        return '403 Access Denied'


#=================================================================
class BadRequestException(WbException):
    def status(self):
        return '400 Bad Request'


#=================================================================
class NotFoundException(WbException):
    def status(self):
        return '404 Not Found'


#=================================================================
class LiveResourceException(WbException):
    def status(self):
        return '400 Bad Live Resource'
github webrecorder / pywb / pywb / warcserver / index / aggregator.py View on Github external
def load_child_source(self, name, source, params):
        try:
            params['_name'] = name
            params['_formatter'] = ParamFormatter(params, name)
            res = source.load_index(params)
            if isinstance(res, tuple):
                cdx_iter, err_list = res
            else:
                cdx_iter = res
                err_list = []
        except WbException as wbe:
            #print('Not found in ' + name)
            cdx_iter = iter([])
            err_list = [(name, repr(wbe))]

        def add_source(cdx, name):
            if not cdx.get('url'):
                return cdx

            if cdx.get('source'):
                cdx['source'] = name + ':' + cdx['source']
            else:
                cdx['source'] = name

            cdx['source-coll'] = self._get_coll(name)

            return cdx
github webrecorder / pywb / pywb / utils / wbexception.py View on Github external
def __repr__(self):
        return "{0}('{1}',)".format(self.__class__.__name__,  self.msg)

# Default Error Code
#    def status(self):
#        return '500 Internal Server Error'


#=================================================================
class AccessException(WbException):
    def status(self):
        return '403 Access Denied'


#=================================================================
class BadRequestException(WbException):
    def status(self):
        return '400 Bad Request'


#=================================================================
class NotFoundException(WbException):
    def status(self):
        return '404 Not Found'


#=================================================================
class LiveResourceException(WbException):
    def status(self):
        return '400 Bad Live Resource'
github webrecorder / pywb / pywb / framework / wsgi_wrappers.py View on Github external
def handle_methods(self, env, start_response):
        wb_router = self.wb_router
        response = None

        try:
            response = wb_router(env)

            if not response:
                if self.fallback_app:
                    return self.fallback_app(env, start_response)
                else:
                    msg = 'No handler for "{0}".'.format(env['REL_REQUEST_URI'])
                    raise NotFoundException(msg)

        except WbException as e:
            response = self.handle_exception(env, e, False)

        except Exception as e:
            response = self.handle_exception(env, e, True)

        return response(env, start_response)
github webrecorder / pywb / pywb / cdx / cdxsource.py View on Github external
if self.cookie:
                request.add_header('Cookie', self.cookie)

            response = urllib2.urlopen(request)

        except urllib2.HTTPError as e:
            if e.code == 403:
                raise AccessException('Access Denied')
            elif e.code == 404:
                # return empty list for consistency with other cdx sources
                # will be converted to 404 if no other retry
                return []
            elif e.code == 400:
                raise BadRequestException()
            else:
                raise WbException('Invalid response from remote cdx server')

        return iter(response)
github harvard-lil / perma / perma_web / warc_server / pywb_config.py View on Github external
if not timestamp:
            # if timestamp is not available, fall back on today's date
            now = datetime.now()
            timestamp = '{:%Y%m%d%H%M%S}'.format(now)

        raise CustomTemplateException(status='404 Not Found',
                                      template_path='archive/archive-error.html',
                                      template_kwargs={
                                          'content_host': settings.PLAYBACK_HOST,
                                          'err_url': url,
                                          'timestamp': timestamp,
                                      })
    raise NotFoundException('No Captures found for: %s' % url, url=url)


class CustomTemplateException(WbException):
    def __init__(self, msg=None, url=None, status='500 Internal Server Error', template_path=None, template_kwargs=None):
        if not template_kwargs:
            template_kwargs = {}
        self.status_string = status
        self.template_path = template_path
        self.template_kwargs = template_kwargs
        super(CustomTemplateException, self).__init__(msg, url)

    def status(self):
        return self.status_string

    def render_response(self):
        return PermaTemplateView(self.template_path).render_response(status=self.status(), **self.template_kwargs)

# monkey-patch WSGIApp.handle_exception to add custom exception handling
real_handle_exception = WSGIApp.handle_exception
github webrecorder / pywb / pywb / utils / wbexception.py View on Github external
class WbException(Exception):
    def __init__(self, msg=None, url=None):
        Exception.__init__(self, msg)
        self.msg = msg
        self.url = url

    def __repr__(self):
        return "{0}('{1}',)".format(self.__class__.__name__,  self.msg)

# Default Error Code
#    def status(self):
#        return '500 Internal Server Error'


#=================================================================
class AccessException(WbException):
    def status(self):
        return '403 Access Denied'


#=================================================================
class BadRequestException(WbException):
    def status(self):
        return '400 Bad Request'


#=================================================================
class NotFoundException(WbException):
    def status(self):
        return '404 Not Found'
github webrecorder / pywb / pywb / framework / wbexceptions.py View on Github external
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'
github webrecorder / pywb / pywb / warc / recordloader.py View on Github external
#=================================================================
#ArcWarcRecord = collections.namedtuple('ArcWarcRecord',
#                                       'format, rec_type, rec_headers, ' +
#                                       'stream, status_headers, ' +
#                                       'content_type, length')

#=================================================================
class ArcWarcRecord(object):
    def __init__(self, *args):
        (self.format, self.rec_type, self.rec_headers, self.stream,
         self.status_headers, self.content_type, self.length) = args


#=================================================================
class ArchiveLoadFailed(WbException):
    def __init__(self, reason, filename=''):
        if filename:
            msg = filename + ': ' + str(reason)
        else:
            msg = str(reason)

        super(ArchiveLoadFailed, self).__init__(msg)

    def status(self):
        return '503 Service Unavailable'


#=================================================================
class ArcWarcRecordLoader(object):
    WARC_TYPES = ['WARC/1.0', 'WARC/0.17', 'WARC/0.18']
github webrecorder / pywb / pywb / framework / proxy_resolvers.py View on Github external
def select_coll_response(self, env, default_coll=None):
        raise WbException('Invalid Proxy Collection Specified: ' + str(default_coll))