From 5913265c8b74385d8774fba5a8ca0cadb72326fd Mon Sep 17 00:00:00 2001 From: Roberto Prevato Date: Sun, 8 Jan 2023 10:05:44 +0100 Subject: [PATCH] Prep for release 2.0a0 (#301) --- .github/workflows/main.yml | 30 ++++++++---- CHANGELOG.md | 3 +- README.md | 8 ++- blacksheep/includes/consts.pxi | 5 -- blacksheep/server/application.py | 20 -------- blacksheep/server/cors.py | 4 ++ blacksheep/server/files/__init__.py | 76 +---------------------------- setup.py | 4 +- tests/test_files_serving.py | 20 -------- 9 files changed, 36 insertions(+), 134 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7de3221b..59a6005e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -244,15 +244,25 @@ jobs: with: name: dist path: dist - - name: Publish distribution 📦 to Test PyPI - uses: pypa/gh-action-pypi-publish@master + + - name: Use Python 3.11 + uses: actions/setup-python@v1 with: - skip_existing: true - user: __token__ - password: ${{ secrets.test_pypi_password }} - repository_url: https://test.pypi.org/legacy/ + python-version: '3.11' + + - name: Install dependencies + run: | + pip install twine + - name: Publish distribution 📦 to Test PyPI + run: | + twine upload -r testpypi dist/* + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.test_pypi_password }} + - name: Publish distribution 📦 to PyPI - uses: pypa/gh-action-pypi-publish@master - with: - user: __token__ - password: ${{ secrets.pypi_password }} + run: | + twine upload -r pypi dist/* + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.pypi_password }} diff --git a/CHANGELOG.md b/CHANGELOG.md index be264c95..9fa7b7a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [2.0.0] - ??? +## [2.0a0] - 2023-01-08 :hourglass_flowing_sand: - Renames the `plugins` namespace to `settings` - Upgrades `rodi` to v2, which includes improvements. @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ways to achieve Server Side Rendering (SSR) of HTML; however, `Jinja2` is still the default library if the user doesn´t specify how HTML should be rendered. - Adds options to control `Jinja2` settings through environment variables. +- Removes the deprecated `ServeFilesOptions` class. ## [1.2.8] - 2022-10-27 :snake: - Upgrades pinned dependencies to support Python 3.11 diff --git a/README.md b/README.md index b01ddb89..120dbf38 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,7 @@ Since version `1.2.1`, BlackSheep implements: * [Built-in support for OpenID Connect authentication](https://www.neoteroi.dev/blacksheep/authentication/#oidc) * [Built-in support for JWT Bearer authentication](https://www.neoteroi.dev/blacksheep/authentication/#jwt-bearer) -Meaning that it is extremely easy to integrate with services such as: +Meaning that it is easy to integrate with services such as: * [Auth0](https://auth0.com) * [Azure Active Directory](https://azure.microsoft.com/en-us/services/active-directory/) * [Azure Active Directory B2C](https://docs.microsoft.com/en-us/azure/active-directory-b2c/overview) @@ -189,6 +189,7 @@ Meaning that it is extremely easy to integrate with services such as: Refer to the documentation for more details and examples. ## Web framework features + * [ASGI compatibility](https://www.neoteroi.dev/blacksheep/asgi/) * [Routing](https://www.neoteroi.dev/blacksheep/routing/) * Request handlers can be [defined as @@ -264,3 +265,8 @@ Please refer to the [documentation website](https://www.neoteroi.dev/blacksheep/ ## Communication [BlackSheep community in Gitter](https://gitter.im/Neoteroi/BlackSheep). + +## Branches +The _main_ branch contains the currently developed version, which is version 2 +alpha. The _v1_ branch contains version 1 of the web framework, for bugs fixes +and maintenance. diff --git a/blacksheep/includes/consts.pxi b/blacksheep/includes/consts.pxi index 3ba36ebd..7d2cae3c 100644 --- a/blacksheep/includes/consts.pxi +++ b/blacksheep/includes/consts.pxi @@ -1,6 +1 @@ DEF MAX_RESPONSE_CHUNK_SIZE = 61440 # 64kb -DEF MAX_REQUEST_HEADERS_COUNT = 80 -DEF MAX_REQUEST_HEADER_SIZE = 8192 # 8kb - -# 61440 # 64kb -# 16384 \ No newline at end of file diff --git a/blacksheep/server/application.py b/blacksheep/server/application.py index 860e4972..4e4d8aca 100644 --- a/blacksheep/server/application.py +++ b/blacksheep/server/application.py @@ -47,7 +47,6 @@ from blacksheep.server.cors import CORSPolicy, CORSStrategy, get_cors_middleware from blacksheep.server.env import EnvironmentSettings from blacksheep.server.errors import ServerErrorDetailsHandler -from blacksheep.server.files import ServeFilesOptions from blacksheep.server.files.dynamic import serve_files_dynamic from blacksheep.server.normalization import normalize_handler, normalize_middleware from blacksheep.server.responses import _ensure_bytes @@ -475,25 +474,6 @@ def serve_files( response would be otherwise 404 Not Found; e.g. use this to serve SPA that use HTML5 History API for client side routing. """ - if isinstance(source_folder, ServeFilesOptions): - # deprecated class, will be removed in the next version - from typing import cast - - deprecated_arg = cast(ServeFilesOptions, source_folder) - deprecated_arg.validate() - serve_files_dynamic( - self.router, - self.files_handler, - str(deprecated_arg.source_folder), - discovery=deprecated_arg.discovery, - cache_time=deprecated_arg.cache_time, - extensions=deprecated_arg.extensions, - root_path=deprecated_arg.root_path, - index_document=deprecated_arg.index_document, - fallback_document=deprecated_arg.fallback_document, - anonymous_access=deprecated_arg.allow_anonymous, - ) - return serve_files_dynamic( self.router, self.files_handler, diff --git a/blacksheep/server/cors.py b/blacksheep/server/cors.py index 43ea76af..f1c4fc80 100644 --- a/blacksheep/server/cors.py +++ b/blacksheep/server/cors.py @@ -5,6 +5,7 @@ from blacksheep.baseapp import BaseApplication from blacksheep.messages import Request, Response from blacksheep.server.routing import Route, Router +from blacksheep.server.websocket import WebSocket from .responses import not_found, ok, status_code @@ -243,6 +244,9 @@ def get_cors_middleware( strategy: CORSStrategy, ) -> Callable[[Request, Callable[..., Any]], Awaitable[Response]]: async def cors_middleware(request: Request, handler): + if isinstance(request, WebSocket): + return await handler(request) + origin = request.get_first_header(b"Origin") if not origin: diff --git a/blacksheep/server/files/__init__.py b/blacksheep/server/files/__init__.py index e28c030b..df1df425 100644 --- a/blacksheep/server/files/__init__.py +++ b/blacksheep/server/files/__init__.py @@ -1,6 +1,6 @@ import uuid from pathlib import Path -from typing import AsyncIterable, Callable, Optional, Set, Union +from typing import AsyncIterable, Callable, Optional, Set from blacksheep import Request, Response, StreamedContent from blacksheep.common.files.asyncfs import FilesHandler @@ -184,80 +184,6 @@ def validate_source_path(source_folder: str) -> None: raise InvalidArgument("The given root path is not a directory.") -class ServeFilesOptions: - - __slots__ = ( - "source_folder", - "extensions", - "discovery", - "cache_time", - "root_path", - "allow_anonymous", - "index_document", - "fallback_document", - ) - - def __init__( - self, - source_folder: Union[str, Path], - *, - extensions: Optional[Set[str]] = None, - discovery: bool = False, - cache_time: int = 10800, - root_path: str = "", - allow_anonymous: bool = True, - index_document: Optional[str] = "index.html", - fallback_document: Optional[str] = None, - ): - """ - Options for static files serving. - - Args: - source_folder (str): Path to the source folder containing static files. - extensions: The set of files extensions to serve. - discovery: Whether to enable file discovery, serving HTML pages for folders. - cache_time: Controls the Cache-Control Max-Age in seconds for static files. - root_path: Path prefix used for routing requests. - For example, if set to "public", files are served at "/public/*". - allow_anonymous: Whether to enable anonymous access to static files, true by - default. - index_document: The name of the index document to display, if present, - in folders. Requests for folders that contain a file with matching produce - a response with this document. - fallback_document: Optional file name, for a document to serve when a - response would be otherwise 404 Not Found; e.g. use this to serve SPA that - use HTML5 History API for client side routing. - """ - import warnings - - warnings.warn( - "The ServeFilesOptions is deprecated and will " - "be removed in the version 1.0.0. Update your code to not use this class " - "and pass the same arguments to the application.serve_files method. " - "For more information see " - "https://www.neoteroi.dev/blacksheep/static-files/", - DeprecationWarning, - ) - - if extensions is None: - extensions = self.get_default_extensions() - self.source_folder = source_folder - self.extensions = set(extensions) - self.discovery = bool(discovery) - self.cache_time = int(cache_time) - self.root_path = root_path - self.allow_anonymous = allow_anonymous - self.index_document = index_document - self.fallback_document = fallback_document - - def get_default_extensions(self) -> Set[str]: - """Returns a set of extensions that are served by default.""" - return get_default_extensions() - - def validate(self) -> None: - validate_source_path(str(self.source_folder)) - - def get_response_for_file( files_handler: FilesHandler, request: Request, diff --git a/setup.py b/setup.py index 0fed4d41..29038245 100644 --- a/setup.py +++ b/setup.py @@ -11,12 +11,12 @@ def readme(): setup( name="blacksheep", - version="2.0.0", + version="2.0a0", description="Fast web framework for Python asyncio", long_description=readme(), long_description_content_type="text/markdown", classifiers=[ - "Development Status :: 5 - Production/Stable", + "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", diff --git a/tests/test_files_serving.py b/tests/test_files_serving.py index 68f8e53a..d2a56cbf 100644 --- a/tests/test_files_serving.py +++ b/tests/test_files_serving.py @@ -14,7 +14,6 @@ from blacksheep.server.files import ( FileInfo, RangeNotSatisfiable, - ServeFilesOptions, _get_requested_range, get_default_extensions, get_range_file_getter, @@ -338,25 +337,6 @@ async def test_serve_files_no_discovery(app): assert response.status == 404 -@pytest.mark.asyncio -async def test_serve_files_deprecated_serve_files_options(files2_index_contents, app): - with pytest.deprecated_call(): - app.serve_files(ServeFilesOptions(get_folder_path("files2"))) # type: ignore - - await app.start() - - scope = get_example_scope("GET", "/", []) - await app( - scope, - MockReceive(), - MockSend(), - ) - - response = app.response - assert response.status == 200 - assert files2_index_contents == await response.read() - - @pytest.mark.asyncio async def test_serve_files_fallback_document(files2_index_contents: bytes, app): """Feature used to serve SPAs that use HTML5 History API"""