Skip to content

Commit

Permalink
Fix #305 in v1, re-format code (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoPrevato authored Feb 17, 2023
1 parent b06a222 commit bfb5d67
Show file tree
Hide file tree
Showing 23 changed files with 10 additions and 46 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +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.10] - 2023-02-17 :heart:
- Fixes bug #305 (`ClientSession ssl=False` not working as intended).
- Applies formatting from the most recent of Black.

## [1.2.9] - 2023-01-01 :fireworks:
- Fix invalid OpenAPI doc for route parameter with pattern (#286) - [antipooh](https://github.com/antipooh)'s contribution.
- Fix a bug related to nullable boolean values https://github.com/Neoteroi/BlackSheep/commit/363616b7fa4cb69bf698c25768e9de04e36feb69 [jack-fireworkhq](https://github.com/jack-fireworkhq)'s contribution.
Expand Down
2 changes: 1 addition & 1 deletion blacksheep/client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

INSECURE_SSLCONTEXT = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS_CLIENT)
INSECURE_SSLCONTEXT.check_hostname = False
INSECURE_SSLCONTEXT.verify_mode = ssl.CERT_NONE


class IncomingContent(Content):
Expand Down Expand Up @@ -80,7 +81,6 @@ def __init__(self, response, transport):


class ClientConnection(asyncio.Protocol):

__slots__ = (
"loop",
"pool",
Expand Down
2 changes: 0 additions & 2 deletions blacksheep/client/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def not_ip_address(value: str):


class StoredCookie:

__slots__ = ("cookie", "persistent", "creation_time", "expiry_time")

def __init__(self, cookie: Cookie):
Expand Down Expand Up @@ -203,7 +202,6 @@ def _get_cookies_checking_exp(
schema: str, cookies: Dict[str, StoredCookie]
) -> Iterable[Cookie]:
for cookie_name, stored_cookie in cookies.copy().items():

if stored_cookie.is_expired():
del cookies[cookie_name]
continue
Expand Down
7 changes: 3 additions & 4 deletions blacksheep/client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def __contains__(self, item: Any) -> bool:


class ClientRequestContext:

__slots__ = ("path", "cookies")

def __init__(self, request, cookies: Optional[CookieJar] = None):
Expand Down Expand Up @@ -345,17 +344,17 @@ async def _send_core(self, request: Request) -> Response:

return response

async def _send_using_connection(self, request) -> Response:
async def _send_using_connection(self, request, attempt: int = 1) -> Response:
connection = await self.get_connection(request.url)

try:
return await asyncio.wait_for(
connection.send(request), self.request_timeout
)
except ConnectionClosedError as connection_closed_error:
if connection_closed_error.can_retry:
if connection_closed_error.can_retry and attempt < 4:
await asyncio.sleep(self.delay_before_retry)
return await self._send_using_connection(request)
return await self._send_using_connection(request, attempt + 1)
raise
except TimeoutError:
raise RequestTimeout(request.url, self.request_timeout)
Expand Down
1 change: 0 additions & 1 deletion blacksheep/common/files/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class FileInfo:

__slots__ = ("etag", "size", "mime", "modified_time")

def __init__(self, size: int, etag: str, mime: str, modified_time: str):
Expand Down
1 change: 0 additions & 1 deletion blacksheep/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def parse_multipart(value: bytes) -> Generator[FormPart, None, None]:
default_charset = None

for part_bytes in split_multipart(value):

try:
yield parse_part(part_bytes, default_charset)
except CharsetPart as charset:
Expand Down
1 change: 0 additions & 1 deletion blacksheep/ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def _parse_range_value(range_value: str):


class Range:

__slots__ = ("_unit", "_parts")

def __init__(self, unit: str, parts: Sequence[RangePart]):
Expand Down
1 change: 0 additions & 1 deletion blacksheep/server/files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ def validate_source_path(source_folder: str) -> None:


class ServeFilesOptions:

__slots__ = (
"source_folder",
"extensions",
Expand Down
1 change: 0 additions & 1 deletion blacksheep/server/openapi/docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def parse_docstring(self, docstring: str) -> DocstringInfo:


def type_repr_to_type(type_repr: str) -> Optional[Type]:

array_match = _array_rx.match(type_repr)

if array_match:
Expand Down
4 changes: 0 additions & 4 deletions blacksheep/server/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def __init__(self, parameter_pattern_name: str, matched_parameter: str) -> None:


class RouteMatch:

__slots__ = ("values", "pattern", "handler")

def __init__(self, route: "Route", values: Optional[Dict[str, bytes]]):
Expand All @@ -98,7 +97,6 @@ def _get_parameter_pattern_fragment(


class Route:

__slots__ = (
"handler",
"pattern",
Expand Down Expand Up @@ -378,7 +376,6 @@ def ws(self, pattern) -> Callable[..., Any]:


class Router(RouterBase):

__slots__ = ("routes", "_map", "_fallback")

def __init__(self):
Expand Down Expand Up @@ -478,7 +475,6 @@ def get_matching_route(self, method: AnyStr, value: AnyStr) -> Optional[Route]:


class RegisteredRoute:

__slots__ = ("method", "pattern", "handler")

def __init__(self, method: str, pattern: str, handler: Callable):
Expand Down
2 changes: 0 additions & 2 deletions itests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ async def test_post_form(session, data):

@pytest.mark.asyncio
async def test_post_multipart_form_with_files(session):

if os.path.exists("out"):
shutil.rmtree("out")

Expand Down Expand Up @@ -192,7 +191,6 @@ async def test_post_multipart_form_with_files(session):

@pytest.mark.asyncio
async def test_post_multipart_form_with_images(session):

if os.path.exists("out"):
shutil.rmtree("out")

Expand Down
1 change: 0 additions & 1 deletion itests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ def test_post_form_urlencoded(session_1, data, echoed):


def test_post_multipart_form_with_files(session_1):

if os.path.exists("out"):
shutil.rmtree("out")

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def readme():

setup(
name="blacksheep",
version="1.2.9",
version="1.2.10",
description="Fast web framework for Python asyncio",
long_description=readme(),
long_description_content_type="text/markdown",
Expand Down
6 changes: 0 additions & 6 deletions tests/client/test_redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def get_scenarios(fn):
async def test_non_url_redirect(
responses, expected_status, expected_location, pools_factory
):

async with ClientSession(
base_url=b"http://localhost:8080", pools=pools_factory(responses)
) as client:
Expand Down Expand Up @@ -109,7 +108,6 @@ async def test_non_url_redirect(
),
)
async def test_good_redirect(responses, expected_response_body, pools_factory):

async with ClientSession(
base_url=b"http://localhost:8080", pools=pools_factory(responses)
) as client:
Expand Down Expand Up @@ -137,7 +135,6 @@ async def test_good_redirect(responses, expected_response_body, pools_factory):
],
)
async def test_not_follow_redirect(responses, expected_location, pools_factory):

async with ClientSession(
base_url=b"http://localhost:8080",
pools=pools_factory(responses),
Expand Down Expand Up @@ -186,7 +183,6 @@ async def test_not_follow_redirect(responses, expected_location, pools_factory):
async def test_maximum_number_of_redirects_detection(
responses, maximum_redirects, pools_factory
):

async with ClientSession(
base_url=b"http://localhost:8080", pools=pools_factory(responses)
) as client:
Expand Down Expand Up @@ -245,11 +241,9 @@ async def test_maximum_number_of_redirects_detection(
async def test_circular_redirect_detection(
responses, expected_error_message, pools_factory
):

async with ClientSession(
base_url=b"http://localhost:8080", pools=pools_factory(responses)
) as client:

with pytest.raises(CircularRedirectError) as error:
await client.get(b"/")

Expand Down
3 changes: 1 addition & 2 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2659,7 +2659,6 @@ async def home(foo: FromRoute[parameter_type]):
async def test_valid_header_parameter_parse(
parameter_type, parameter, expected_value, app
):

T = TypeVar("T")

class XFooHeader(FromHeader[T]):
Expand Down Expand Up @@ -3897,7 +3896,7 @@ def decorator(next_handler):
async def wrapped(*args, **kwargs) -> Response:
response = ensure_response(await next_handler(*args, **kwargs))

for (name, value) in additional_headers:
for name, value in additional_headers:
response.add_header(name.encode(), value.encode())

return response
Expand Down
7 changes: 0 additions & 7 deletions tests/test_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def __init__(self, a: str, b: List[str]):

@pytest.mark.asyncio
async def test_from_body_json_binding():

request = Request("POST", b"/", [JSONContentType]).with_content(
JSONContent({"a": "world", "b": 9000})
)
Expand All @@ -73,7 +72,6 @@ async def test_from_body_json_binding():

@pytest.mark.asyncio
async def test_from_body_json_binding_extra_parameters_strategy():

request = Request("POST", b"/", [JSONContentType]).with_content(
JSONContent(
{
Expand All @@ -95,7 +93,6 @@ async def test_from_body_json_binding_extra_parameters_strategy():

@pytest.mark.asyncio
async def test_from_body_json_with_converter():

request = Request("POST", b"/", [JSONContentType]).with_content(
JSONContent(
{
Expand Down Expand Up @@ -459,7 +456,6 @@ async def test_identity_binder():

@pytest.mark.asyncio
async def test_from_body_form_binding_urlencoded():

request = Request("POST", b"/", []).with_content(
FormContent({"a": "world", "b": 9000})
)
Expand All @@ -475,7 +471,6 @@ async def test_from_body_form_binding_urlencoded():

@pytest.mark.asyncio
async def test_from_body_form_binding_urlencoded_keys_duplicates():

request = Request("POST", b"/", []).with_content(
FormContent([("a", "world"), ("b", "one"), ("b", "two"), ("b", "three")])
)
Expand All @@ -491,7 +486,6 @@ async def test_from_body_form_binding_urlencoded_keys_duplicates():

@pytest.mark.asyncio
async def test_from_body_form_binding_multipart():

request = Request("POST", b"/", []).with_content(
MultiPartFormData([FormPart(b"a", b"world"), FormPart(b"b", b"9000")])
)
Expand All @@ -506,7 +500,6 @@ async def test_from_body_form_binding_multipart():

@pytest.mark.asyncio
async def test_from_body_form_binding_multipart_keys_duplicates():

request = Request("POST", b"/", []).with_content(
MultiPartFormData(
[
Expand Down
4 changes: 0 additions & 4 deletions tests/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ async def test_controller_with_base_route_as_string_attribute(app):
get = app.controllers_router.get

class Home(Controller):

route = "/home"

def greet(self):
Expand Down Expand Up @@ -500,7 +499,6 @@ async def test_application_raises_for_invalid_route_class_attribute(app):
get = app.controllers_router.get

class Home(Controller):

route = False

def greet(self):
Expand Down Expand Up @@ -622,7 +620,6 @@ async def test_controllers_with_duplicate_routes_with_base_route_throw(
# and another handler

class A(Controller):

route = "home"

@get(first_pattern)
Expand Down Expand Up @@ -652,7 +649,6 @@ async def test_controller_with_duplicate_route_with_base_route_throw(
# and another handler

class A(Controller):

route = "home"

@get(first_pattern)
Expand Down
1 change: 0 additions & 1 deletion tests/test_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ def test_parse_cookie_separators(value, expected_name, expected_value, expected_


def test_raise_for_value_exceeding_length():

with pytest.raises(CookieValueExceedsMaximumLength):
Cookie("crash", "A" * 4967)

Expand Down
1 change: 0 additions & 1 deletion tests/test_cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ async def test_non_cors_options_request(app):

@pytest.mark.asyncio
async def test_use_cors_raises_for_started_app(app):

await app.start()

with pytest.raises(ApplicationAlreadyStartedCORSError):
Expand Down
1 change: 0 additions & 1 deletion tests/test_files_serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,6 @@ async def test_serve_files_multiple_folders(files2_index_contents, app):


def test_validate_source_path_raises_for_invalid_path():

with pytest.raises(InvalidArgument):
validate_source_path("./not-existing")

Expand Down
1 change: 0 additions & 1 deletion tests/test_openapi_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ def check_consistency(cls, v, values):


class PydConstrained(BaseModel):

a: PositiveInt
b: NegativeFloat
big_int: conint(gt=1000, lt=1024)
Expand Down
2 changes: 0 additions & 2 deletions tests/test_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def test_range_eq_not_implemented(item):


def test_range_part_raises_if_start_gt_end():

with pytest.raises(ValueError):
RangePart(400, 300)

Expand All @@ -155,7 +154,6 @@ def test_range_part_raises_if_start_gt_end():


def test_range_part_raises_if_any_part_is_negative():

with pytest.raises(ValueError):
RangePart(-100, 0)

Expand Down
1 change: 0 additions & 1 deletion tests/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,5 @@ def test_base_url(value, expected_base_url):


def test_raises_for_invalid_scheme():

with pytest.raises(InvalidURL):
URL(b"file://D:/a/b/c")

0 comments on commit bfb5d67

Please sign in to comment.