From b9a19839ffb0d464d2ad9924c7e4faf06db465e6 Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Wed, 24 Jan 2024 19:47:39 -0800 Subject: [PATCH] Removes the inheritance in favor of ignoring mypy in these cases --- .docker/docker-compose.ci-test-edge.yml | 9 +++ .docker/docker-compose.ci-test.yml | 2 +- src/gotenberg_client/_base.py | 15 ++--- src/gotenberg_client/_convert/common.py | 74 ++++++++++++------------- 4 files changed, 52 insertions(+), 48 deletions(-) diff --git a/.docker/docker-compose.ci-test-edge.yml b/.docker/docker-compose.ci-test-edge.yml index 9037ee7..aec42a5 100644 --- a/.docker/docker-compose.ci-test-edge.yml +++ b/.docker/docker-compose.ci-test-edge.yml @@ -14,3 +14,12 @@ services: - "gotenberg" - "--log-level=warn" - "--log-format=text" + nginx-webserver: + image: docker.io/nginx:1-alpine + hostname: nginx-webserver + container_name: nginx-webserver + ports: + - "8888:80" + restart: unless-stopped + volumes: + - ./content:/usr/share/nginx/html:ro diff --git a/.docker/docker-compose.ci-test.yml b/.docker/docker-compose.ci-test.yml index 37bb0fc..348dbfb 100644 --- a/.docker/docker-compose.ci-test.yml +++ b/.docker/docker-compose.ci-test.yml @@ -5,7 +5,7 @@ version: "3" services: gotenberg-client-test-server: - image: docker.io/gotenberg/gotenberg:8.0.1 + image: docker.io/gotenberg/gotenberg:8.0.2 hostname: gotenberg-client-test-server container_name: gotenberg-client-test-server network_mode: host diff --git a/src/gotenberg_client/_base.py b/src/gotenberg_client/_base.py index a9cb260..3ddf8d3 100644 --- a/src/gotenberg_client/_base.py +++ b/src/gotenberg_client/_base.py @@ -9,7 +9,6 @@ from types import TracebackType from typing import Dict from typing import Optional -from typing import Protocol from typing import Type from typing import Union @@ -29,11 +28,7 @@ class UnreachableCodeError(Exception): pass -class HasFormData(Protocol): - _form_data: Dict[str, str] - - -class PdfFormatMixin(HasFormData): +class PdfFormatMixin: """ https://gotenberg.dev/docs/routes#pdfa-chromium https://gotenberg.dev/docs/routes#pdfa-libreoffice @@ -44,11 +39,11 @@ def pdf_format(self, pdf_format: PdfAFormat) -> Self: All routes provide the option to configure the output PDF as a PDF/A format """ - self._form_data.update(pdf_format.to_form()) + self._form_data.update(pdf_format.to_form()) # type: ignore[attr-defined,misc] return self -class PfdUniversalAccessMixin(HasFormData): +class PfdUniversalAccessMixin: """ https://gotenberg.dev/docs/routes#pdfa-chromium https://gotenberg.dev/docs/routes#pdfa-libreoffice @@ -57,11 +52,11 @@ class PfdUniversalAccessMixin(HasFormData): """ def enable_universal_access(self) -> Self: - self._form_data.update({"pdfua": "true"}) + self._form_data.update({"pdfua": "true"}) # type: ignore[attr-defined,misc] return self def disable_universal_access(self) -> Self: - self._form_data.update({"pdfua": "true"}) + self._form_data.update({"pdfua": "true"}) # type: ignore[attr-defined,misc] return self diff --git a/src/gotenberg_client/_convert/common.py b/src/gotenberg_client/_convert/common.py index 91c533b..f61f002 100644 --- a/src/gotenberg_client/_convert/common.py +++ b/src/gotenberg_client/_convert/common.py @@ -19,27 +19,27 @@ logger = logging.getLogger() -class PageSizeMixin(BaseRoute): +class PageSizeMixin: """ https://gotenberg.dev/docs/routes#page-properties-chromium """ def size(self, size: PageSize) -> Self: - self._form_data.update(size.to_form()) + self._form_data.update(size.to_form()) # type: ignore[attr-defined,misc] return self -class MarginMixin(BaseRoute): +class MarginMixin: """ https://gotenberg.dev/docs/routes#page-properties-chromium """ def margins(self, margins: Margin) -> Self: - self._form_data.update(margins.to_form()) + self._form_data.update(margins.to_form()) # type: ignore[attr-defined,misc] return self -class PageOrientMixin(BaseRoute): +class PageOrientMixin: """ https://gotenberg.dev/docs/routes#page-properties-chromium """ @@ -48,11 +48,11 @@ def orient(self, orient: PageOrientation) -> Self: """ Sets the page orientation, either Landscape or portrait """ - self._form_data.update(orient.to_form()) + self._form_data.update(orient.to_form()) # type: ignore[attr-defined,misc] return self -class PageRangeMixin(BaseRoute): +class PageRangeMixin: """ https://gotenberg.dev/docs/routes#page-properties-chromium """ @@ -62,53 +62,53 @@ def page_ranges(self, ranges: str) -> Self: Sets the page range string, allowing either some range or just a few pages """ - self._form_data.update({"nativePageRanges": ranges}) + self._form_data.update({"nativePageRanges": ranges}) # type: ignore[attr-defined,misc] return self -class CssPageSizeMixin(BaseRoute): +class CssPageSizeMixin: """ https://gotenberg.dev/docs/routes#page-properties-chromium """ def prefer_css_page_size(self) -> Self: - self._form_data.update({"preferCssPageSize": "true"}) + self._form_data.update({"preferCssPageSize": "true"}) # type: ignore[attr-defined,misc] return self def prefer_set_page_size(self) -> Self: - self._form_data.update({"preferCssPageSize": "false"}) + self._form_data.update({"preferCssPageSize": "false"}) # type: ignore[attr-defined,misc] return self -class BackgroundControlMixin(BaseRoute): +class BackgroundControlMixin: """ https://gotenberg.dev/docs/routes#page-properties-chromium """ def background_graphics(self) -> Self: - self._form_data.update({"printBackground": "true"}) + self._form_data.update({"printBackground": "true"}) # type: ignore[attr-defined,misc] return self def no_background_graphics(self) -> Self: - self._form_data.update({"printBackground": "false"}) + self._form_data.update({"printBackground": "false"}) # type: ignore[attr-defined,misc] return self def hide_background(self) -> Self: - self._form_data.update({"omitBackground": "true"}) + self._form_data.update({"omitBackground": "true"}) # type: ignore[attr-defined,misc] return self def show_background(self) -> Self: - self._form_data.update({"omitBackground": "false"}) + self._form_data.update({"omitBackground": "false"}) # type: ignore[attr-defined,misc] return self -class ScaleMixin(BaseRoute): +class ScaleMixin: """ https://gotenberg.dev/docs/routes#page-properties-chromium """ def scale(self, scale: Union[int, float]) -> Self: - self._form_data.update({"scale": str(scale)}) + self._form_data.update({"scale": str(scale)}) # type: ignore[attr-defined,misc] return self @@ -127,61 +127,61 @@ class PagePropertiesMixin( """ -class HeaderFooterMixin(BaseRoute): +class HeaderFooterMixin: """ https://gotenberg.dev/docs/routes#header-footer-chromium """ def header(self, header: Path) -> Self: - self._add_file_map(header, "header.html") + self._add_file_map(header, "header.html") # type: ignore[attr-defined] return self def footer(self, footer: Path) -> Self: - self._add_file_map(footer, "footer.html") + self._add_file_map(footer, "footer.html") # type: ignore[attr-defined] return self -class RenderControlMixin(BaseRoute): +class RenderControlMixin: """ https://gotenberg.dev/docs/routes#wait-before-rendering-chromium """ def render_wait(self, wait: Union[int, float]) -> Self: - self._form_data.update({"waitDelay": str(wait)}) + self._form_data.update({"waitDelay": str(wait)}) # type: ignore[attr-defined,misc] return self def render_expr(self, expr: str) -> Self: - self._form_data.update({"waitForExpression": expr}) + self._form_data.update({"waitForExpression": expr}) # type: ignore[attr-defined,misc] return self -class EmulatedMediaMixin(BaseRoute): +class EmulatedMediaMixin: """ https://gotenberg.dev/docs/routes#emulated-media-type-chromium """ def media_type(self, media_type: EmulatedMediaType) -> Self: - self._form_data.update(media_type.to_form()) + self._form_data.update(media_type.to_form()) # type: ignore[attr-defined,misc] return self -class CustomHTTPHeaderMixin(BaseRoute): +class CustomHTTPHeaderMixin: """ https://gotenberg.dev/docs/routes#custom-http-headers-chromium """ def user_agent(self, agent: str) -> Self: warn("The Gotenberg userAgent field is deprecated", DeprecationWarning, stacklevel=2) - self._form_data.update({"userAgent": agent}) + self._form_data.update({"userAgent": agent}) # type: ignore[attr-defined,misc] return self def headers(self, headers: Dict[str, str]) -> Self: json_str = json.dumps(headers) - self._form_data.update({"extraHttpHeaders": json_str}) + self._form_data.update({"extraHttpHeaders": json_str}) # type: ignore[attr-defined,misc] return self -class InvalidStatusCodesMixin(BaseRoute): +class InvalidStatusCodesMixin: """ https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium """ @@ -191,33 +191,33 @@ def fail_on_status_codes(self, codes: Iterable[int]) -> Self: logger.warning("fail_on_status_codes was given not codes, ignoring") return self codes_str = ",".join([str(x) for x in codes]) - self._form_data.update({"failOnHttpStatusCodes": f"[{codes_str}]"}) + self._form_data.update({"failOnHttpStatusCodes": f"[{codes_str}]"}) # type: ignore[attr-defined,misc] return self -class ConsoleExceptionMixin(BaseRoute): +class ConsoleExceptionMixin: """ https://gotenberg.dev/docs/routes#console-exceptions-chromium """ def fail_on_exceptions(self) -> Self: - self._form_data.update({"failOnConsoleExceptions": "true"}) + self._form_data.update({"failOnConsoleExceptions": "true"}) # type: ignore[attr-defined,misc] return self def dont_fail_on_exceptions(self) -> Self: - self._form_data.update({"failOnConsoleExceptions": "false"}) + self._form_data.update({"failOnConsoleExceptions": "false"}) # type: ignore[attr-defined,misc] return self -class PerformanceModeMixin(BaseRoute): +class PerformanceModeMixin: """ https://gotenberg.dev/docs/routes#performance-mode-chromium """ def skip_network_idle(self) -> Self: - self._form_data.update({"skipNetworkIdleEvent": "false"}) + self._form_data.update({"skipNetworkIdleEvent": "false"}) # type: ignore[attr-defined,misc] return self def use_network_idle(self) -> Self: - self._form_data.update({"skipNetworkIdleEvent": "false"}) + self._form_data.update({"skipNetworkIdleEvent": "false"}) # type: ignore[attr-defined,misc] return self