Example #1
0
def test_static_route_path_existence_check():
    directory = os.path.dirname(__file__)
    web.StaticResource("/", directory)

    nodirectory = os.path.join(directory, "nonexistent-uPNiOEAg5d")
    with pytest.raises(ValueError):
        web.StaticResource("/", nodirectory)
Example #2
0
def test_static_route_path_existence_check() -> None:
    directory = pathlib.Path(__file__).parent
    web.StaticResource("/", directory)

    nodirectory = directory / "nonexistent-uPNiOEAg5d"
    with pytest.raises(ValueError):
        web.StaticResource("/", nodirectory)
    def register_static_path(self,
                             url_path: str,
                             path: str,
                             cache_headers: bool = True) -> None:
        """Register a folder or file to serve as a static path."""
        if os.path.isdir(path):
            if cache_headers:
                resource: CachingStaticResource | web.StaticResource = (
                    CachingStaticResource(url_path, path))
            else:
                resource = web.StaticResource(url_path, path)
            self.app.router.register_resource(resource)
            self.app["allow_configured_cors"](resource)
            return

        async def serve_file(request: web.Request) -> web.FileResponse:
            """Serve file from disk."""
            if cache_headers:
                return web.FileResponse(path, headers=CACHE_HEADERS)
            return web.FileResponse(path)

        self.app["allow_configured_cors"](self.app.router.add_route(
            "GET", url_path, serve_file))
Example #4
0
async def make_app(*args, **kwargs):
    KEY = kwargs.pop('KEY')
    KEY = KEY or cfg.app.session_secret
    sio = socketio.AsyncServer(logger=log, engineio_logger=log)
    app = web.Application(middlewares=[
        session_middleware(EncryptedCookieStorage(hashlib.sha256(bytes(KEY, 'utf-8')).digest(), httponly=False)),
        authorize
    ])

    app.mgr = DBManager(cfg.db.connection)

    app.core_states = {
        'cp': False,
        'lab1': False,
        'lab2': False,
        'lab3': False,
        'lec1': False,
        'lec2': False,
        'lec3': False,
        'tea': False,
        'afk': False
    }
    sio.attach(app)
    sio.register_namespace(ChatWS('/ws', app=app))

    app.router.add_routes(routes)
    static_resource = web.StaticResource('', cfg.app.static_folder, name="resources")

    async def index(request):
        request.match_info['filename'] = 'index.html'
        return await static_resource._handle(request)

    app.router.add_route('GET', '/{path:(?!static/?).*$}', index)
    app.router.register_resource(static_resource)

    return app
Example #5
0
def function1336():
    var1743 = os.path.dirname(__file__)
    web.StaticResource('/', var1743)
    var4516 = os.path.join(var1743, 'nonexistent-uPNiOEAg5d')
    with pytest.raises(ValueError):
        web.StaticResource('/', var4516)