# Path: pypi_redirect/pypi_redirect/server_app/handler/_exception.py
# class HandlerException(Exception):
#     def __init__(self, wrapped_exception):
#         self.wrapped_exception = wrapped_exception
# 
#     def raise_wrapped(self):
#         """
#         Raises the 'wrapped' exception, preserving the original
#         traceback. This must be called from within an `except` block.
#         """
#         # The first item is a class instance, so the second item must
#         # be None. The third item is the traceback object, which is why
#         # this method must be called from within an `except` block.
#         raise (
#             self.wrapped_exception(),
#             None,
#             sys.exc_info()[2])


import cherrypy
from ..handler._exception import HandlerException


class PathLengthDispatcher(object):
    def __init__(
            self,
            handlers_indexed_by_path_length,
            invalid_path_handler):
        self.handlers_indexed_by_path_length = handlers_indexed_by_path_length
        self.invalid_path_handler = invalid_path_handler

    @cherrypy.expose
    def default(self, *path):
        try:
            return self.handlers_indexed_by_path_length[len(path)](
                path=path,
                request=cherrypy.request,
                response=cherrypy.response)

        except IndexError:
            return self.invalid_path_handler(
                path=path,
                request=cherrypy.request,
                response=cherrypy.response)


# Path: pypi_redirect/pypi_redirect/server_app/handler/_exception.py
# class HandlerException(Exception):
#     def __init__(self, wrapped_exception):
#         self.wrapped_exception = wrapped_exception
# 
#     def raise_wrapped(self):
#         """
#         Raises the 'wrapped' exception, preserving the original
#         traceback. This must be called from within an `except` block.
#         """
#         # The first item is a class instance, so the second item must
#         # be None. The third item is the traceback object, which is why
#         # this method must be called from within an `except` block.
#         raise (
#             self.wrapped_exception(),
#             None,
#             sys.exc_info()[2])


# Path: pypi_redirect/pypi_redirect/server_app/http/path_length_dispatcher.py
import cherrypy
from ..handler._exception import HandlerException



class PathLengthDispatcher(object):
    def __init__(
            self,
            handlers_indexed_by_path_length,
            invalid_path_handler):
        self.handlers_indexed_by_path_length = handlers_indexed_by_path_length
        self.invalid_path_handler = invalid_path_handler

    @cherrypy.expose
    def default(self, *path):
        try:
            return self.handlers_indexed_by_path_length[len(path)](
                path=path,
                request=cherrypy.request,
                response=cherrypy.response)

        except IndexError:
            return self.invalid_path_handler(
                path=path,
                request=cherrypy.request,
                response=cherrypy.response)


        except HandlerException as e: