Skip to content

Commit

Permalink
Moves items which user's don't need to access into more private file …
Browse files Browse the repository at this point in the history
…names
  • Loading branch information
stumpylog committed Oct 15, 2023
1 parent 403b189 commit 81825b1
Show file tree
Hide file tree
Showing 22 changed files with 61 additions and 49 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ endpoint. All the routes use the same format and general idea.
Converting a single HTML file into a PDF:

```python
from gotenberg_client import GotenbergClient

with GotenbergClient("http://localhost:3000") as client:
with client.chromium.html_to_pdf() as route:
response = route.index("my-index.html").run()
Expand All @@ -65,6 +67,8 @@ with GotenbergClient("http://localhost:3000") as client:
Converting an HTML file with additional resources into a PDF:

```python
from gotenberg_client import GotenbergClient

with GotenbergClient("http://localhost:3000") as client:
with client.chromium.html_to_pdf() as route:
response = route.index("my-index.html").resource("image.png").resource("style.css").run()
Expand All @@ -74,6 +78,7 @@ with GotenbergClient("http://localhost:3000") as client:
Converting an HTML file with additional resources into a PDF/A1a format:

```python
from gotenberg_client import GotenbergClient
from gotenberg_client.options import PdfAFormat

with GotenbergClient("http://localhost:3000") as client:
Expand All @@ -85,6 +90,7 @@ with GotenbergClient("http://localhost:3000") as client:
Converting a URL into PDF, in landscape format

```python
from gotenberg_client import GotenbergClient
from gotenberg_client.options import PageOrientation

with GotenbergClient("http://localhost:3000") as client:
Expand All @@ -98,6 +104,8 @@ used as context manager. If for some reason you cannot, you should `.close` the
routes:

```python
from gotenberg_client import GotenbergClient

try:
client = GotenbergClient("http://localhost:3000")
try:
Expand Down
3 changes: 3 additions & 0 deletions src/gotenberg_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2023-present Trenton H <[email protected]>
#
# SPDX-License-Identifier: MPL-2.0
from gotenberg_client._client import GotenbergClient

__all__ = ["GotenbergClient"]
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from httpx._types import RequestFiles

from gotenberg_client._types_compat import Self
from gotenberg_client._utils import guess_mime_type
from gotenberg_client.options import PdfAFormat
from gotenberg_client.utils import guess_mime_type

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

from httpx import Client

from gotenberg_client.convert.chromium import ChromiumApi
from gotenberg_client.convert.libre_office import LibreOfficeApi
from gotenberg_client.convert.pdfa import PdfAApi
from gotenberg_client.health import HealthCheckApi
from gotenberg_client.merge import MergeApi
from gotenberg_client._convert.chromium import ChromiumApi
from gotenberg_client._convert.libre_office import LibreOfficeApi
from gotenberg_client._convert.pdfa import PdfAApi
from gotenberg_client._health import HealthCheckApi
from gotenberg_client._merge import MergeApi


class GotenbergClient:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from typing import List
from typing import Union

from gotenberg_client._base import BaseApi
from gotenberg_client._convert.common import ConvertBaseRoute
from gotenberg_client._types_compat import Self
from gotenberg_client.base import BaseApi
from gotenberg_client.convert.common import ConvertBaseRoute
from gotenberg_client.options import EmulatedMediaType
from gotenberg_client.options import Margin
from gotenberg_client.options import PageSize
Expand All @@ -28,25 +28,6 @@ def __bool__(self) -> bool:
FORCE_MULTIPART: Final = ForceMultipartDict()


# Define common paper sizes as shortcuts
A0: Final = PageSize(width=33.1, height=46.8)
A1: Final = PageSize(width=23.4, height=33.1)
A2: Final = PageSize(width=16.54, height=23.4)
A3: Final = PageSize(width=11.7, height=16.54)
A4: Final = PageSize(width=8.5, height=11)
A5: Final = PageSize(width=5.83, height=8.27)
A6: Final = PageSize(width=4.13, height=5.83)
Letter = A4
Legal: Final = PageSize(width=8.5, height=14)
Tabloid: Final = PageSize(width=11, height=17)
Ledge: Final = PageSize(width=17, height=11)


Gotenberg_Default_Margines: Final = Margin(0.39, 0.39, 0.39, 0.39)
Word_Default_Margins: Final = Margin(top=1.0, bottom=1.0, left=1.0, right=1.0)
Word_Narrow_Margins: Final = Margin(top=0.5, bottom=0.5, left=0.5, right=0.5)


class ChromiumBaseRoute(ConvertBaseRoute):
"""
https://gotenberg.dev/docs/routes#convert-with-chromium
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# SPDX-License-Identifier: MPL-2.0
import logging

from gotenberg_client._base import BaseRoute
from gotenberg_client._types_compat import Self
from gotenberg_client.base import BaseRoute
from gotenberg_client.options import PageOrientation

logger = logging.getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from pathlib import Path
from typing import List

from gotenberg_client._base import BaseApi
from gotenberg_client._convert.common import ConvertBaseRoute
from gotenberg_client._types_compat import Self
from gotenberg_client.base import BaseApi
from gotenberg_client.convert.common import ConvertBaseRoute


class LibreOfficeConvertRoute(ConvertBaseRoute):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from pathlib import Path
from typing import List

from gotenberg_client._base import BaseApi
from gotenberg_client._convert.common import ConvertBaseRoute
from gotenberg_client._types_compat import Self
from gotenberg_client.base import BaseApi
from gotenberg_client.convert.common import ConvertBaseRoute


class PdfAConvertRoute(ConvertBaseRoute):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import TypedDict
from typing import no_type_check

from gotenberg_client.base import BaseApi
from gotenberg_client._base import BaseApi

_TIME_RE = re.compile(
r"(?P<year>\d{4})-"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from pathlib import Path
from typing import List

from gotenberg_client.base import BaseApi
from gotenberg_client.base import BaseRoute
from gotenberg_client._base import BaseApi
from gotenberg_client._base import BaseRoute


class MergeRoute(BaseRoute):
Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 21 additions & 1 deletion src/gotenberg_client/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import dataclasses
import enum
from typing import Dict
from typing import Final
from typing import Optional
from typing import Union

from gotenberg_client.utils import optional_to_form
from gotenberg_client._utils import optional_to_form


@enum.unique
Expand Down Expand Up @@ -52,6 +53,20 @@ def to_form(self) -> Dict[str, str]:
return data


# Define common paper sizes as shortcuts
A0: Final = PageSize(width=33.1, height=46.8)
A1: Final = PageSize(width=23.4, height=33.1)
A2: Final = PageSize(width=16.54, height=23.4)
A3: Final = PageSize(width=11.7, height=16.54)
A4: Final = PageSize(width=8.5, height=11)
A5: Final = PageSize(width=5.83, height=8.27)
A6: Final = PageSize(width=4.13, height=5.83)
Letter = A4
Legal: Final = PageSize(width=8.5, height=14)
Tabloid: Final = PageSize(width=11, height=17)
Ledge: Final = PageSize(width=17, height=11)


@dataclasses.dataclass
class Margin:
top: Optional[Union[float, int]] = None
Expand All @@ -67,6 +82,11 @@ def to_form(self) -> Dict[str, str]:
return data


Gotenberg_Default_Margins: Final = Margin(0.39, 0.39, 0.39, 0.39)
Word_Default_Margins: Final = Margin(top=1.0, bottom=1.0, left=1.0, right=1.0)
Word_Narrow_Margins: Final = Margin(top=0.5, bottom=0.5, left=0.5, right=0.5)


@enum.unique
class EmulatedMediaType(str, enum.Enum):
Print = enum.auto()
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from gotenberg_client.client import GotenbergClient
from gotenberg_client._client import GotenbergClient

GOTENBERG_URL: Final[str] = os.getenv("GOTENBERG_URL", "http://localhost:3000")

Expand Down
6 changes: 3 additions & 3 deletions tests/test_convert_chromium_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from httpx import codes
from pytest_httpx import HTTPXMock

from gotenberg_client.client import GotenbergClient
from gotenberg_client.convert.chromium import A4
from gotenberg_client.convert.chromium import Margin
from gotenberg_client._client import GotenbergClient
from gotenberg_client._convert.chromium import Margin
from gotenberg_client.options import A4
from gotenberg_client.options import PageOrientation
from gotenberg_client.options import PdfAFormat
from tests.conftest import SAMPLE_DIR
Expand Down
2 changes: 1 addition & 1 deletion tests/test_convert_chromium_markdown.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from httpx import codes

from gotenberg_client.client import GotenbergClient
from gotenberg_client._client import GotenbergClient
from tests.conftest import SAMPLE_DIR


Expand Down
4 changes: 2 additions & 2 deletions tests/test_convert_chromium_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from httpx import codes
from pytest_httpx import HTTPXMock

from gotenberg_client.client import GotenbergClient
from gotenberg_client.convert.chromium import EmulatedMediaType
from gotenberg_client._client import GotenbergClient
from gotenberg_client._convert.chromium import EmulatedMediaType
from tests.utils import verify_stream_contains


Expand Down
4 changes: 2 additions & 2 deletions tests/test_convert_libre_office.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import pytest
from httpx import codes

from gotenberg_client.client import GotenbergClient
from gotenberg_client._client import GotenbergClient
from gotenberg_client._utils import guess_mime_type_stdlib
from gotenberg_client.options import PdfAFormat
from gotenberg_client.utils import guess_mime_type_stdlib
from tests.conftest import SAMPLE_DIR
from tests.conftest import SAVE_DIR
from tests.conftest import SAVE_OUTPUTS
Expand Down
2 changes: 1 addition & 1 deletion tests/test_convert_pdf_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from httpx import codes

from gotenberg_client.client import GotenbergClient
from gotenberg_client._client import GotenbergClient
from gotenberg_client.options import PdfAFormat
from tests.conftest import SAMPLE_DIR
from tests.conftest import SAVE_DIR
Expand Down
4 changes: 2 additions & 2 deletions tests/test_health.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from gotenberg_client.client import GotenbergClient
from gotenberg_client.health import StatusOptions
from gotenberg_client._client import GotenbergClient
from gotenberg_client._health import StatusOptions


class TestHealthStatus:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
from httpx import codes

from gotenberg_client.client import GotenbergClient
from gotenberg_client._client import GotenbergClient
from gotenberg_client.options import PdfAFormat
from tests.conftest import SAMPLE_DIR
from tests.conftest import SAVE_DIR
Expand Down

0 comments on commit 81825b1

Please sign in to comment.