Skip to content

Commit

Permalink
v0.3.1 🎄
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoPrevato authored Dec 27, 2020
1 parent f4cff8e commit 486f04b
Show file tree
Hide file tree
Showing 45 changed files with 2,361 additions and 514 deletions.
17 changes: 15 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,24 @@ 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).

## [0.3.1] - 2020-12-27 🎄
- Implements an abstraction layer to [handle CORS](https://www.neoteroi.dev/blacksheep/cors/)
- Improves the code API to handle [response cookies](https://www.neoteroi.dev/blacksheep/responses/#setting-cookies)
- Improves the default handling of authorization for request handlers (#69)
- Adds more binders: `FromText`, `FromBytes`, `RequestMethod`, `RequestURL`
- Improves `FromJson` binder to support returning the dictionary after JSON deserialization
- Improves the default bad request response for invalid dataclass
- Adds two more features to the OpenAPI Documentation:
- - support defining common responses to be shared across all operations
- - support defining servers settings without subclassing `OpenAPIHandler`
- Fixes bugs: #54, #55, #68
- Renames `HttpException` class to `HTTPException` to follow [PEP 8](https://www.python.org/dev/peps/pep-0008/)

## [0.3.0] - 2020-12-16 :gear:
- Builds `wheels` and packs them in the distribution package.
- Builds `wheels` and packs them in the distribution package

## [0.2.9] - 2020-12-12 🏳️
- Corrects inconsistent dependency causing an error in `pip-20.3.1`.
- Corrects inconsistent dependency causing an error in `pip-20.3.1`

## [0.2.8] - 2020-12-10 📜
- Links to the new website with documentation: [https://www.neoteroi.dev/blacksheep/](https://www.neoteroi.dev/blacksheep/)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![pypi](https://img.shields.io/pypi/v/BlackSheep.svg?color=blue)](https://pypi.org/project/BlackSheep/)
[![versions](https://img.shields.io/pypi/pyversions/blacksheep.svg)](https://github.com/robertoprevato/blacksheep)
[![codecov](https://codecov.io/gh/RobertoPrevato/BlackSheep/branch/master/graph/badge.svg?token=Nzi29L0Eg1)](https://codecov.io/gh/RobertoPrevato/BlackSheep)
[![license](https://img.shields.io/github/license/RobertoPrevato/blacksheep.svg)](https://github.com/RobertoPrevato/blacksheep/blob/master/LICENSE)

# BlackSheep
BlackSheep is an asynchronous web framework to build event based web
Expand Down Expand Up @@ -192,7 +193,7 @@ async def only_for_authenticated_users():
routing](https://www.neoteroi.dev/blacksheep/static-files/#how-to-serve-spas-that-use-html5-history-api)
* [Support for automatic generation of OpenAPI
Documentation](https://www.neoteroi.dev/blacksheep/openapi/)

* [Strategy to handle CORS settings](https://www.neoteroi.dev/blacksheep/cors/)
## Client features
BlackSheep includes an HTTP Client.

Expand Down Expand Up @@ -220,7 +221,6 @@ loop.run_until_complete(client_example(loop))
* Python 3.7 (cpython)
* Python 3.8 (cpython)
* Python 3.9 (cpython)

* Ubuntu 18.04
* Windows 10
* macOS
Expand Down
3 changes: 2 additions & 1 deletion blacksheep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .url import URL, InvalidURL
from .headers import Header, Headers
from .exceptions import HttpException
from .exceptions import HTTPException
from .contents import (
Content,
StreamedContent,
Expand All @@ -16,6 +16,7 @@
)
from .cookies import (
Cookie,
CookieSameSiteMode,
datetime_from_cookie_format,
datetime_to_cookie_format,
parse_cookie,
Expand Down
3 changes: 2 additions & 1 deletion blacksheep/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ from .contents import (
)
from .cookies import (
Cookie as Cookie,
CookieSameSiteMode as CookieSameSiteMode,
datetime_from_cookie_format as datetime_from_cookie_format,
datetime_to_cookie_format as datetime_to_cookie_format,
parse_cookie as parse_cookie,
)
from .exceptions import HttpException as HttpException
from .exceptions import HTTPException as HTTPException
from .headers import Header as Header, Headers as Headers
from .messages import Request as Request, Response as Response
from .url import InvalidURL as InvalidURL, URL as URL
Expand Down
4 changes: 2 additions & 2 deletions blacksheep/baseapp.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
# This module is part of BlackSheep and is released under
# the MIT License https://opensource.org/licenses/MIT

from .exceptions cimport HttpException
from .exceptions cimport HTTPException


cdef class BaseApplication:

cdef public bint show_error_details
cdef readonly object router
cdef public dict exceptions_handlers
cdef object get_http_exception_handler(self, HttpException http_exception)
cdef object get_http_exception_handler(self, HTTPException http_exception)
cdef object get_exception_handler(self, Exception exception)
25 changes: 7 additions & 18 deletions blacksheep/baseapp.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from blacksheep.messages import Request, Response
from blacksheep.exceptions import HttpException
from blacksheep.exceptions import HTTPException
from blacksheep.server.application import Application
from blacksheep.server.routing import Router
from typing import Awaitable, Dict, Union, Type, Callable, TypeVar
Expand All @@ -11,28 +11,17 @@ ExceptionHandlersType = Dict[
Callable[[Application, Request, ExcT], Awaitable[Response]],
]


class BaseApplication:
def __init__(self, show_error_details: bool, router: Router):
self.router = router
self.exceptions_handlers = self.init_exceptions_handlers()
self.show_error_details = show_error_details

def init_exceptions_handlers(self) -> ExceptionHandlersType:
...

async def handle(self, request: Request) -> Response:
...

def init_exceptions_handlers(self) -> ExceptionHandlersType: ...
async def handle(self, request: Request) -> Response: ...
async def handle_internal_server_error(
self, request: Request, exc: Exception
) -> Response:
...

) -> Response: ...
async def handle_http_exception(
self, request: Request, http_exception: HttpException
) -> Response:
...

async def handle_exception(self, request: Request, exc: Exception) -> Response:
...
self, request: Request, http_exception: HTTPException
) -> Response: ...
async def handle_exception(self, request: Request, exc: Exception) -> Response: ...
14 changes: 7 additions & 7 deletions blacksheep/baseapp.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .messages cimport Request, Response
from .contents cimport TextContent, HtmlContent
from .exceptions cimport HttpException, NotFound
from .exceptions cimport HTTPException, NotFound


import os
Expand All @@ -9,15 +9,15 @@ import http
import traceback


async def handle_not_found(app, Request request, HttpException http_exception):
async def handle_not_found(app, Request request, HTTPException http_exception):
return Response(404, content=TextContent('Resource not found'))


async def handle_bad_request(app, Request request, HttpException http_exception):
async def handle_bad_request(app, Request request, HTTPException http_exception):
return Response(400, content=TextContent(f'Bad Request: {str(http_exception)}'))


async def common_http_exception_handler(app, Request request, HttpException http_exception):
async def common_http_exception_handler(app, Request request, HTTPException http_exception):
return Response(http_exception.status, content=TextContent(http.HTTPStatus(http_exception.status).phrase))


Expand Down Expand Up @@ -45,7 +45,7 @@ cdef class BaseApplication:

try:
response = await route.handler(request)
except HttpException as http_exception:
except HTTPException as http_exception:
response = await self.handle_http_exception(request, http_exception)
except Exception as exc:
response = await self.handle_exception(request, exc)
Expand All @@ -59,7 +59,7 @@ cdef class BaseApplication:
# this might be ambiguous, if a programmer thinks to return None for "Not found"
return response or Response(204)

cdef object get_http_exception_handler(self, HttpException http_exception):
cdef object get_http_exception_handler(self, HTTPException http_exception):
return self.exceptions_handlers.get(http_exception.status, common_http_exception_handler)

cdef object get_exception_handler(self, Exception exception):
Expand Down Expand Up @@ -91,7 +91,7 @@ cdef class BaseApplication:
except Exception as server_ex:
return await self.handle_exception(request, server_ex)

async def handle_http_exception(self, Request request, HttpException http_exception):
async def handle_http_exception(self, Request request, HTTPException http_exception):
exception_handler = self.get_http_exception_handler(http_exception)
if exception_handler:
return await self._apply_exception_handler(request, http_exception, exception_handler)
Expand Down
5 changes: 2 additions & 3 deletions blacksheep/client/connection.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import asyncio
import ssl
from typing import Optional
import weakref
from typing import Optional

import certifi
import httptools
from httptools import HttpParserCallbackError, HttpParserError

from blacksheep import Content, Request, Response
from blacksheep.scribe import (
is_small_request,
Expand All @@ -16,6 +14,7 @@
write_request_without_body,
write_small_request,
)
from httptools import HttpParserCallbackError, HttpParserError

SECURE_SSLCONTEXT = ssl.create_default_context(
ssl.Purpose.SERVER_AUTH, cafile=certifi.where()
Expand Down
Loading

0 comments on commit 486f04b

Please sign in to comment.