Skip to content

Commit

Permalink
Merge branch 'release/0.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
stumpylog committed Dec 11, 2023
2 parents c867eb5 + 7f7141c commit 458d15f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .docker/docker-compose.ci-test-edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

version: "3"
services:
gotenberg-client-test-server:
gotenberg-client-test-edge-server:
image: docker.io/gotenberg/gotenberg:edge
hostname: gotenberg-client-test-server
container_name: gotenberg-client-test-server
hostname: gotenberg-client-test-edge-server
container_name: gotenberg-client-test-edge-server
network_mode: host
restart: unless-stopped
command:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
docker compose --file ${GITHUB_WORKSPACE}/.docker/docker-compose.ci-test.yml up --detach
echo "Wait for container to be started"
sleep 5
docker inspect gotenberg-client-test-server
-
name: Install poppler-utils
run: |
Expand Down Expand Up @@ -113,6 +114,7 @@ jobs:
docker compose --file ${GITHUB_WORKSPACE}/.docker/docker-compose.ci-test-edge.yml up --detach
echo "Wait for container to be started"
sleep 5
docker inspect gotenberg-client-test-edge-server
-
name: Install poppler-utils
run: |
Expand All @@ -131,6 +133,7 @@ jobs:
pip install --upgrade hatch
-
name: Run tests
continue-on-error: true
run: hatch run cov
-
name: Stop containers
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ 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.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.1] - 2023-12-11

### Fixed

- Implemented an internal workaround for older Gotenberg versions and their handling of non-latin filenames.
- When detected, the files will be copied into a temporary directory and the filename cleaned
- Gotenberg 8.0.0 will start implementing something similar once released
- The pulled Gotenberg image is now inspected, allowing local re-creation of failures against specific digests
- The `:edge` tag testing is now allowed to fail

## [0.4.0] - 2023-12-04

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/gotenberg_client/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023-present Trenton H <[email protected]>
#
# SPDX-License-Identifier: MPL-2.0
__version__ = "0.4.0"
__version__ = "0.4.1"
16 changes: 16 additions & 0 deletions src/gotenberg_client/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
from contextlib import ExitStack
from pathlib import Path
from tempfile import TemporaryDirectory
from types import TracebackType
from typing import Dict
from typing import Optional
Expand Down Expand Up @@ -102,8 +103,23 @@ def _add_file_map(self, filepath: Path, name: Optional[str] = None) -> None:
"""
if name is None:
name = filepath.name

if name in self._file_map: # pragma: no cover
logger.warning(f"{name} has already been provided, overwriting anyway")

try:
name.encode("utf8").decode("ascii")
except UnicodeDecodeError:
logger.warning(f"filename {name} includes non-ascii characters, compensating for Gotenberg")
tmp_dir = self._stack.enter_context(TemporaryDirectory())
# Filename can be fixed, the directory is random
new_path = Path(tmp_dir) / Path(name).with_name(f"clean-filename-copy{filepath.suffix}")
logger.warning(f"New path {new_path}")
new_path.write_bytes(filepath.read_bytes())
filepath = new_path
name = new_path.name
logger.warning(f"New name {name}")

self._file_map[name] = filepath

def pdf_format(self, pdf_format: PdfAFormat) -> Self:
Expand Down
24 changes: 24 additions & 0 deletions tests/test_misc_stuff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import shutil
import tempfile
import uuid
from pathlib import Path

from httpx import codes

Expand Down Expand Up @@ -43,3 +46,24 @@ def test_output_filename(
assert resp.headers["Content-Type"] == "application/pdf"
assert "Content-Disposition" in resp.headers
assert f"{filename}.pdf" in resp.headers["Content-Disposition"]

def test_libre_office_convert_cyrillic(self, client: GotenbergClient):
"""
Gotenberg versions before 8.0.0 could not internally handle filenames with
non-ASCII characters. This replicates such a thing against 1 endpoint to
verify the workaround inside this library
"""
test_file = SAMPLE_DIR / "sample.odt"

with tempfile.TemporaryDirectory() as temp_dir:
copy = shutil.copy(
test_file,
Path(temp_dir) / "Карточка партнера Тауберг Альфа.odt", # noqa: RUF001
)

with client.libre_office.to_pdf() as route:
resp = call_run_with_server_error_handling(route.convert(copy))

assert resp.status_code == codes.OK
assert "Content-Type" in resp.headers
assert resp.headers["Content-Type"] == "application/pdf"

0 comments on commit 458d15f

Please sign in to comment.