eodag 3.6.0__py3-none-any.whl → 3.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
eodag/utils/__init__.py CHANGED
@@ -36,6 +36,7 @@ import re
36
36
  import shutil
37
37
  import ssl
38
38
  import string
39
+ import struct
39
40
  import sys
40
41
  import types
41
42
  import unicodedata
@@ -61,18 +62,7 @@ from typing import (
61
62
  Union,
62
63
  cast,
63
64
  )
64
-
65
- # All modules using these should import them from utils package
66
- from urllib.parse import ( # noqa; noqa
67
- parse_qs,
68
- parse_qsl,
69
- quote,
70
- unquote,
71
- urlencode,
72
- urljoin,
73
- urlparse,
74
- urlsplit,
75
- )
65
+ from urllib.parse import urlparse, urlsplit
76
66
  from urllib.request import url2pathname
77
67
 
78
68
  if sys.version_info >= (3, 12):
@@ -80,7 +70,6 @@ if sys.version_info >= (3, 12):
80
70
  else:
81
71
  from typing_extensions import Unpack # noqa
82
72
 
83
-
84
73
  import click
85
74
  import orjson
86
75
  import shapefile
@@ -224,14 +213,13 @@ class FloatRange(click.types.FloatParamType):
224
213
  ):
225
214
  if self.min is None:
226
215
  self.fail(
227
- "%s is bigger than the maximum valid value " "%s." % (rv, self.max),
216
+ "%s is bigger than the maximum valid value %s." % (rv, self.max),
228
217
  param,
229
218
  ctx,
230
219
  )
231
220
  elif self.max is None:
232
221
  self.fail(
233
- "%s is smaller than the minimum valid value "
234
- "%s." % (rv, self.min),
222
+ "%s is smaller than the minimum valid value %s." % (rv, self.min),
235
223
  param,
236
224
  ctx,
237
225
  )
@@ -387,27 +375,29 @@ def merge_mappings(mapping1: dict[Any, Any], mapping2: dict[Any, Any]) -> None:
387
375
  # `m1_keys_lowercase.get(key, key)`
388
376
  current_value = mapping1.get(m1_keys_lowercase.get(key, key))
389
377
  if current_value is not None:
390
- current_value_type = type(current_value)
391
- new_value_type = type(value)
392
378
  try:
393
379
  # If current or new value is a list (search queryable parameter), simply replace current with new
394
380
  if (
395
- new_value_type == list
396
- and current_value_type != list
397
- or new_value_type != list
398
- and current_value_type == list
381
+ isinstance(value, list)
382
+ and not isinstance(current_value, list)
383
+ or not isinstance(value, list)
384
+ and isinstance(current_value, list)
399
385
  ):
400
386
  mapping1[m1_keys_lowercase.get(key, key)] = value
401
387
  else:
402
388
  mapping1[m1_keys_lowercase.get(key, key)] = cast_scalar_value(
403
- value, current_value_type
389
+ value, type(current_value)
404
390
  )
405
391
  except (TypeError, ValueError):
406
392
  # Ignore any override value that does not have the same type
407
393
  # as the default value
408
394
  logger.debug(
409
- f"Ignored '{key}' setting override from '{current_value}' to '{value}', "
410
- f"(could not cast {new_value_type} to {current_value_type})"
395
+ "Ignored '%s' setting override from '%s' to '%s', (could not cast %s to %s)",
396
+ key,
397
+ current_value,
398
+ value,
399
+ type(value),
400
+ type(current_value),
411
401
  )
412
402
  pass
413
403
  else:
@@ -1451,8 +1441,7 @@ def cast_scalar_value(value: Any, new_type: Any) -> Any:
1451
1441
  # case
1452
1442
  if value.capitalize() not in ("True", "False"):
1453
1443
  raise ValueError(
1454
- "Only true or false strings (case insensitive) are "
1455
- "allowed for booleans"
1444
+ "Only true or false strings (case insensitive) are allowed for booleans"
1456
1445
  )
1457
1446
  # Get the real Python value of the boolean. e.g: value='tRuE'
1458
1447
  # => eval(value.capitalize())=True.
@@ -1505,6 +1494,7 @@ def guess_extension(type: str) -> Optional[str]:
1505
1494
  return mimetypes.guess_extension(type, strict=False)
1506
1495
 
1507
1496
 
1497
+ @functools.lru_cache(maxsize=2)
1508
1498
  def get_ssl_context(ssl_verify: bool) -> ssl.SSLContext:
1509
1499
  """
1510
1500
  Returns an SSL context based on ``ssl_verify`` argument.
@@ -1572,3 +1562,27 @@ def remove_str_array_quotes(input_str: str) -> str:
1572
1562
  continue
1573
1563
  output_str += input_str[i]
1574
1564
  return output_str
1565
+
1566
+
1567
+ def parse_le_uint32(data: bytes) -> int:
1568
+ """
1569
+ Parse little-endian unsigned 4-byte integer.
1570
+
1571
+ >>> parse_le_uint32(b'\\x01\\x00\\x00\\x00')
1572
+ 1
1573
+ >>> parse_le_uint32(b'\\xff\\xff\\xff\\xff')
1574
+ 4294967295
1575
+ """
1576
+ return struct.unpack("<I", data)[0]
1577
+
1578
+
1579
+ def parse_le_uint16(data: bytes) -> int:
1580
+ """
1581
+ Parse little-endian unsigned 2-byte integer.
1582
+
1583
+ >>> parse_le_uint16(b'\\x01\\x00')
1584
+ 1
1585
+ >>> parse_le_uint16(b'\\xff\\xff')
1586
+ 65535
1587
+ """
1588
+ return struct.unpack("<H", data)[0]
eodag/utils/exceptions.py CHANGED
@@ -79,6 +79,10 @@ class STACOpenerError(EodagError):
79
79
  """An error indicating that a STAC file could not be opened"""
80
80
 
81
81
 
82
+ class InvalidDataError(EodagError):
83
+ """Raised when data is invalid, malformed, or corrupt and cannot be processed as expected."""
84
+
85
+
82
86
  class RequestError(EodagError):
83
87
  """An error indicating that a request has failed. Usually eodag functions
84
88
  and methods should catch and skip this"""