Skip to content

Commit

Permalink
re-exports the most commonly used types from the main module 🐱
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoPrevato authored Feb 13, 2022
1 parent aa58247 commit 2c6b613
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 87 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ 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).

## [1.2.4] - 2022-02-12 🐱
## [1.2.4] - 2022-02-13 :cat:
* Modifies the `WebSocket` class to support built-in binders
* Re-exports the most common types from the `blacksheep` module to reduce
the verbosity of import statements

## [1.2.3] - 2022-02-06 :cat2:
* Adds support for [WebSocket](https://www.neoteroi.dev/blacksheep/websocket/)
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ pip install blacksheep

```python
from datetime import datetime
from blacksheep.server import Application
from blacksheep.server.responses import text
from blacksheep import Application, text


app = Application()
Expand Down Expand Up @@ -83,7 +82,10 @@ here](https://www.neoteroi.dev/blacksheep/requests/).
```python
from dataclasses import dataclass

from blacksheep.server.bindings import FromJSON
from blacksheep import Application, FromJSON, FromQuery


app = Application()


@dataclass
Expand Down
99 changes: 73 additions & 26 deletions blacksheep/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,75 @@
"""
Root module of the framework. This module re-exports the most commonly
used types to reduce the verbosity of the imports statements.
"""
__author__ = "Roberto Prevato <[email protected]>"

from .contents import (
Content,
FormContent,
FormPart,
HTMLContent,
HtmlContent,
JSONContent,
JsonContent,
MultiPartFormData,
StreamedContent,
TextContent,
parse_www_form,
)
from .cookies import (
Cookie,
CookieSameSiteMode,
datetime_from_cookie_format,
datetime_to_cookie_format,
parse_cookie,
)
from .exceptions import HTTPException
from .headers import Header, Headers
from .messages import Request, Response
from .server import Application, Route, Router
from .server.websocket import WebSocket, WebSocketDisconnectError
from .url import URL, InvalidURL
from .contents import Content as Content
from .contents import FormContent as FormContent
from .contents import FormPart as FormPart
from .contents import HTMLContent as HTMLContent
from .contents import HtmlContent as HtmlContent
from .contents import JSONContent as JSONContent
from .contents import MultiPartFormData as MultiPartFormData
from .contents import StreamedContent as StreamedContent
from .contents import TextContent as TextContent
from .contents import parse_www_form as parse_www_form
from .cookies import Cookie as Cookie
from .cookies import CookieSameSiteMode as CookieSameSiteMode
from .cookies import datetime_from_cookie_format as datetime_from_cookie_format
from .cookies import datetime_to_cookie_format as datetime_to_cookie_format
from .cookies import parse_cookie as parse_cookie
from .exceptions import HTTPException as HTTPException
from .headers import Header as Header
from .headers import Headers as Headers
from .messages import Message as Message
from .messages import Request as Request
from .messages import Response as Response
from .server.application import Application as Application
from .server.authorization import allow_anonymous as allow_anonymous
from .server.authorization import auth as auth
from .server.bindings import ClientInfo as ClientInfo
from .server.bindings import FromBytes as FromBytes
from .server.bindings import FromCookie as FromCookie
from .server.bindings import FromFiles as FromFiles
from .server.bindings import FromForm as FromForm
from .server.bindings import FromHeader as FromHeader
from .server.bindings import FromJSON as FromJSON
from .server.bindings import FromQuery as FromQuery
from .server.bindings import FromRoute as FromRoute
from .server.bindings import FromServices as FromServices
from .server.bindings import FromText as FromText
from .server.bindings import ServerInfo as ServerInfo
from .server.responses import ContentDispositionType as ContentDispositionType
from .server.responses import FileInput as FileInput
from .server.responses import accepted as accepted
from .server.responses import bad_request as bad_request
from .server.responses import created as created
from .server.responses import file as file
from .server.responses import forbidden as forbidden
from .server.responses import html as html
from .server.responses import json as json
from .server.responses import moved_permanently as moved_permanently
from .server.responses import no_content as no_content
from .server.responses import not_found as not_found
from .server.responses import not_modified as not_modified
from .server.responses import ok as ok
from .server.responses import permanent_redirect as permanent_redirect
from .server.responses import pretty_json as pretty_json
from .server.responses import redirect as redirect
from .server.responses import see_other as see_other
from .server.responses import status_code as status_code
from .server.responses import temporary_redirect as temporary_redirect
from .server.responses import text as text
from .server.responses import unauthorized as unauthorized
from .server.routing import Route as Route
from .server.routing import RouteException as RouteException
from .server.routing import Router as Router
from .server.routing import RoutesRegistry as RoutesRegistry
from .server.templating import use_templates as use_templates
from .server.websocket import WebSocket as WebSocket
from .server.websocket import WebSocketDisconnectError as WebSocketDisconnectError
from .server.websocket import WebSocketError as WebSocketError
from .server.websocket import WebSocketState as WebSocketState
from .url import URL as URL
from .url import InvalidURL as InvalidURL
26 changes: 0 additions & 26 deletions blacksheep/__init__.pyi

This file was deleted.

14 changes: 6 additions & 8 deletions blacksheep/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from .session import (
CircularRedirectError,
ClientSession,
ConnectionTimeout,
MaximumRedirectsExceededError,
MissingLocationForRedirect,
RequestTimeout,
)
from .session import CircularRedirectError as CircularRedirectError
from .session import ClientSession as ClientSession
from .session import ConnectionTimeout as ConnectionTimeout
from .session import MaximumRedirectsExceededError as MaximumRedirectsExceededError
from .session import MissingLocationForRedirect as MissingLocationForRedirect
from .session import RequestTimeout as RequestTimeout
12 changes: 1 addition & 11 deletions blacksheep/contents.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import uuid
from typing import (
Any,
AsyncIterable,
Callable,
Coroutine,
Dict,
List,
Optional,
Tuple,
Union,
)
from typing import Any, AsyncIterable, Callable, Dict, List, Optional, Tuple, Union

class Content:
def __init__(self, content_type: bytes, data: bytes):
Expand Down
6 changes: 4 additions & 2 deletions blacksheep/server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from .application import Application
from .routing import Route, Router
from .application import Application as Application
from .routing import Route as Route
from .routing import Router as Router
from .routing import RoutesRegistry as RoutesRegistry
9 changes: 3 additions & 6 deletions blacksheep/server/authorization/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from typing import Any, Awaitable, Callable, Optional, Sequence, Tuple

from guardpost.asynchronous.authorization import (
AsyncRequirement,
AuthorizationStrategy,
Policy,
)
from guardpost.synchronous.authorization import Requirement, UnauthorizedError
from guardpost.asynchronous.authorization import AsyncRequirement, AuthorizationStrategy
from guardpost.authorization import Policy, UnauthorizedError
from guardpost.synchronous.authorization import Requirement

from blacksheep import Request, Response, TextContent

Expand Down
7 changes: 7 additions & 0 deletions blacksheep/server/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@


class ContentDispositionType(Enum):
"""
Represents the type for a Content-Disposition header (inline or attachment).
The Content-Disposition response header is a header indicating if the content
is expected to be displayed inline in the browser as part of a Web page
or as an attachment, that is downloaded and saved locally.
"""

INLINE = "inline"
ATTACHMENT = "attachment"

Expand Down
16 changes: 12 additions & 4 deletions itests/app_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@

import uvicorn

from blacksheep import Content, Cookie, Request, Response
from blacksheep.server import Application
from blacksheep.server.bindings import FromQuery
from blacksheep.server.responses import ContentDispositionType, file, json, text
from blacksheep import (
Application,
Content,
ContentDispositionType,
Cookie,
FromQuery,
Request,
Response,
file,
json,
text,
)
from itests.utils import CrashTest, ensure_folder

app = Application(show_error_details=True)
Expand Down

0 comments on commit 2c6b613

Please sign in to comment.