diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cd00a972..94796dc3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,7 +41,7 @@ jobs: - name: Install dependencies run: | - pip install cython==0.29.34 + pip install cython==3.0.2 pip install -r requirements.txt pip install flake8 @@ -176,7 +176,8 @@ jobs: - name: Install build dependencies run: | - pip install --upgrade cython build + pip install cython==3.0.2 + pip install --upgrade build - name: Compile Cython extensions run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index e57c9567..a6cb52b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ 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.0a11] - 2023-09-19 :warning: + +- Resolves bug in `2.0a10` caused by incompatibility issue with `Cython 3`. +- Pins `Cython` to `3.0.2` in the build job. + ## [2.0a10] - 2023-08-21 :broccoli: - Add support for `.jinja` extension by @thearchitector. diff --git a/blacksheep/__init__.py b/blacksheep/__init__.py index 58b61208..ad9f2e5d 100644 --- a/blacksheep/__init__.py +++ b/blacksheep/__init__.py @@ -3,7 +3,7 @@ used types to reduce the verbosity of the imports statements. """ __author__ = "Roberto Prevato " -__version__ = "2.0a10" +__version__ = "2.0a11" from .contents import Content as Content from .contents import FormContent as FormContent diff --git a/blacksheep/messages.pxd b/blacksheep/messages.pxd index bf53c122..f4ec92ca 100644 --- a/blacksheep/messages.pxd +++ b/blacksheep/messages.pxd @@ -16,7 +16,7 @@ from .url cimport URL cdef class Message: - cdef list __headers + cdef list _raw_headers cdef public Content content cdef object __weakref__ diff --git a/blacksheep/messages.pyi b/blacksheep/messages.pyi index 00e42aa7..0ebaee25 100644 --- a/blacksheep/messages.pyi +++ b/blacksheep/messages.pyi @@ -127,7 +127,6 @@ class Response(Message): headers: Optional[List[HeaderType]] = None, content: Optional[Content] = None, ) -> None: - self.__headers = headers or [] self.status = status self.content = content def __repr__(self) -> str: ... diff --git a/blacksheep/messages.pyx b/blacksheep/messages.pyx index 82cec697..8dfe2d15 100644 --- a/blacksheep/messages.pyx +++ b/blacksheep/messages.pyx @@ -29,14 +29,14 @@ cpdef str parse_charset(bytes value): cdef class Message: def __init__(self, list headers): - self.__headers = headers or [] + self._raw_headers = headers or [] @property def headers(self): cdef str key = '_headers' if key in self.__dict__: return self.__dict__[key] - self.__dict__[key] = Headers(self.__headers) + self.__dict__[key] = Headers(self._raw_headers) return self.__dict__[key] cpdef Message with_content(self, Content content): @@ -46,7 +46,7 @@ cdef class Message: cpdef bytes get_first_header(self, bytes key): cdef tuple header key = key.lower() - for header in self.__headers: + for header in self._raw_headers: if header[0].lower() == key: return header[1] @@ -54,7 +54,7 @@ cdef class Message: cdef list results = [] cdef tuple header key = key.lower() - for header in self.__headers: + for header in self._raw_headers: if header[0].lower() == key: results.append(header[1]) return results @@ -63,7 +63,7 @@ cdef class Message: cdef list results = [] cdef tuple header key = key.lower() - for header in self.__headers: + for header in self._raw_headers: if header[0].lower() == key: results.append(header) return results @@ -80,22 +80,22 @@ cdef class Message: cdef tuple header cdef list to_remove = [] key = key.lower() - for header in self.__headers: + for header in self._raw_headers: if header[0].lower() == key: to_remove.append(header) for header in to_remove: - self.__headers.remove(header) + self._raw_headers.remove(header) cdef void remove_headers(self, list headers): cdef tuple header for header in headers: - self.__headers.remove(header) + self._raw_headers.remove(header) cdef bint _has_header(self, bytes key): cdef bytes existing_key, existing_value key = key.lower() - for existing_key, existing_value in self.__headers: + for existing_key, existing_value in self._raw_headers: if existing_key.lower() == key: return True return False @@ -104,18 +104,18 @@ cdef class Message: return self._has_header(key) cdef void _add_header(self, bytes key, bytes value): - self.__headers.append((key, value)) + self._raw_headers.append((key, value)) cdef void _add_header_if_missing(self, bytes key, bytes value): if not self._has_header(key): - self.__headers.append((key, value)) + self._raw_headers.append((key, value)) cpdef void add_header(self, bytes key, bytes value): - self.__headers.append((key, value)) + self._raw_headers.append((key, value)) cpdef void set_header(self, bytes key, bytes value): self.remove_header(key) - self.__headers.append((key, value)) + self._raw_headers.append((key, value)) cpdef bytes content_type(self): if self.content and self.content.type: @@ -267,7 +267,7 @@ cdef class Request(Message): list headers ): cdef URL _url = URL(url) if url else None - self.__headers = headers or [] + self._raw_headers = headers or [] self.method = method self._url = _url self._session = None @@ -473,7 +473,7 @@ cdef class Request(Message): if existing_cookie: self.set_header(b"cookie", existing_cookie + b";" + new_value) else: - self.__headers.append((b"cookie", new_value)) + self._raw_headers.append((b"cookie", new_value)) @property def etag(self): @@ -499,7 +499,7 @@ cdef class Response(Message): list headers = None, Content content = None ): - self.__headers = headers or [] + self._raw_headers = headers or [] self.status = status self.content = content @@ -541,7 +541,7 @@ cdef class Response(Message): return None def set_cookie(self, Cookie cookie): - self.__headers.append((b'set-cookie', write_cookie_for_response(cookie))) + self._raw_headers.append((b'set-cookie', write_cookie_for_response(cookie))) def set_cookies(self, list cookies): cdef Cookie cookie diff --git a/blacksheep/scribe.pyx b/blacksheep/scribe.pyx index b10899b4..2848c0a3 100644 --- a/blacksheep/scribe.pyx +++ b/blacksheep/scribe.pyx @@ -160,7 +160,7 @@ cpdef bytes write_request_without_body(Request request): ensure_host_header(request) - extend_data_with_headers(request.__headers, data) + extend_data_with_headers(request._raw_headers, data) data.extend(b'\r\n') return bytes(data) @@ -172,7 +172,7 @@ cpdef bytes write_small_request(Request request): ensure_host_header(request) set_headers_for_content(request) - extend_data_with_headers(request.__headers, data) + extend_data_with_headers(request._raw_headers, data) data.extend(b'\r\n') if request.content: data.extend(request.content.body) @@ -183,7 +183,7 @@ cdef bytes write_small_response(Response response): cdef bytearray data = bytearray() data.extend(STATUS_LINES[response.status]) set_headers_for_content(response) - extend_data_with_headers(response.__headers, data) + extend_data_with_headers(response._raw_headers, data) data.extend(b'\r\n') if response.content: data.extend(response.content.body) @@ -236,7 +236,7 @@ async def write_request(Request request): set_headers_for_content(request) yield HTTP_METHODS[request.method] + b' ' + write_request_uri(request) + b' HTTP/1.1\r\n' + \ - write_headers(request.__headers) + b'\r\n' + write_headers(request._raw_headers) + b'\r\n' content = request.content @@ -297,7 +297,7 @@ async def write_response(Response response): set_headers_for_content(response) yield STATUS_LINES[response.status] + \ - write_headers(response.__headers) + b'\r\n' + write_headers(response._raw_headers) + b'\r\n' async for chunk in write_response_content(response): yield chunk @@ -312,7 +312,7 @@ async def send_asgi_response(Response response, object send): await send({ 'type': 'http.response.start', 'status': response.status, - 'headers': response.__headers + 'headers': response._raw_headers }) if content: diff --git a/requirements.txt b/requirements.txt index bec617e3..26aa06a5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ charset-normalizer==3.1.0 click==8.1.3 coverage==6.5.0 cryptography==41.0.0 -Cython==0.29.34; platform_system != "Windows" +Cython==3.0.2; platform_system != "Windows" essentials==1.1.5 essentials-openapi==1.0.6 Flask==2.2.3