Skip to content

Commit 71d6836

Browse files
committed
recovered version upload_file_from_bytes
1 parent 43fbd48 commit 71d6836

3 files changed

Lines changed: 55 additions & 16 deletions

File tree

navigator/actions/google/maps.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44
Interface for interacting with Google Maps API.
55
66
Heavy mapping dependencies (``polyline``, ``matplotlib``, ``cartopy``) have
7-
moved to the ``navigator-api[google]`` extra. They are imported lazily at
8-
first use via the ``_import_*`` helpers below, which raise a clear,
9-
actionable :class:`ImportError` when the extra is not installed.
7+
moved to the ``navigator-api[google]`` extra:
8+
9+
* ``polyline`` is imported at module load. If the extra is not installed,
10+
a warning is logged and the module-level ``polyline`` is set to ``None``;
11+
calls that depend on it will fail at use time.
12+
* ``matplotlib`` and ``cartopy`` are imported lazily via the ``_import_*``
13+
helpers below, which raise a clear, actionable :class:`ImportError` when
14+
the extra is not installed.
1015
"""
16+
import logging
1117
import string
1218
import datetime
1319
from datetime import timezone
@@ -27,16 +33,14 @@
2733
)
2834

2935

30-
def _import_polyline():
31-
"""Return :mod:`polyline` (lazy) or raise a helpful ImportError."""
32-
try:
33-
import polyline # type: ignore[import-not-found]
34-
except ImportError as exc:
35-
raise ImportError(
36-
f"polyline is required for Google Maps route decoding. "
37-
f"{_EXTRA_HINT}"
38-
) from exc
39-
return polyline
36+
try:
37+
import polyline # type: ignore[import-not-found]
38+
except ImportError:
39+
logging.warning(
40+
"polyline is required for Google Maps route decoding. %s",
41+
_EXTRA_HINT,
42+
)
43+
polyline = None
4044

4145

4246
def _import_matplotlib():
@@ -336,7 +340,6 @@ async def get_route(
336340
if result['status'] == 'OK':
337341
# Extracting route, duration, and distance information
338342
route = result['routes'][0]
339-
polyline = _import_polyline()
340343
encoded_polyline = route['overview_polyline']['points']
341344
decoded_polyline = polyline.decode(encoded_polyline)
342345
map_url = self.get_google_map(

navigator/utils/file/s3.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,45 @@ async def find_files(
565565
return results
566566

567567
# ------------------------------------------------------------------ #
568-
# Backward-compatible web-serving helpers #
568+
# Backward-compatible helpers #
569569
# ------------------------------------------------------------------ #
570570

571+
async def upload_file_from_bytes(
572+
self,
573+
file_obj: bytes,
574+
destination_key: str,
575+
content_type: str = "application/octet-stream",
576+
) -> str:
577+
"""Upload a raw bytes payload to S3 under ``destination_key``.
578+
579+
Backward-compatible helper preserved from the pre-FEAT-002 API.
580+
Applies the manager prefix and uses multipart upload when the payload
581+
exceeds ``multipart_threshold``.
582+
583+
Args:
584+
file_obj: Raw bytes to upload.
585+
destination_key: Target S3 key (without manager prefix).
586+
content_type: MIME type for the object. Defaults to
587+
``"application/octet-stream"``.
588+
589+
Returns:
590+
The ``destination_key`` as provided (unprefixed), matching the
591+
original contract.
592+
"""
593+
key = self._prefixed(destination_key)
594+
size = len(file_obj)
595+
if size >= self.multipart_threshold:
596+
await self._multipart_upload_bytes(file_obj, key, content_type)
597+
else:
598+
async with await self._s3_client() as s3:
599+
await s3.put_object(
600+
Bucket=self.bucket_name,
601+
Key=key,
602+
Body=file_obj,
603+
ContentType=content_type,
604+
)
605+
return destination_key
606+
571607
def setup(self, app, route: str = "/data", base_url: str = None):
572608
"""Set up web-serving for this manager (backward compat).
573609

navigator/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
__description__ = (
55
"Navigator Web Framework based on aiohttp, " "with batteries included."
66
)
7-
__version__ = "3.0.0"
7+
__version__ = "3.0.1"
88
__copyright__ = "Copyright (c) 2018-2026 Jesus Lara"
99
__author__ = "Jesus Lara"
1010
__author_email__ = "jesuslarag@gmail.com"

0 commit comments

Comments
 (0)