Skip to content

Commit

Permalink
Removes the inheritance in favor of ignoring mypy in these cases
Browse files Browse the repository at this point in the history
  • Loading branch information
stumpylog committed Feb 29, 2024
1 parent 9248fcf commit c3d08b6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 48 deletions.
9 changes: 9 additions & 0 deletions .docker/docker-compose.ci-test-edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .docker/docker-compose.ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions src/gotenberg_client/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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


Expand Down
74 changes: 37 additions & 37 deletions src/gotenberg_client/_convert/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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
"""
Expand All @@ -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


Expand All @@ -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
"""
Expand All @@ -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

0 comments on commit c3d08b6

Please sign in to comment.