python-sdk-remote 0.0.182__py3-none-any.whl → 0.0.183b1__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.
@@ -1,4 +1,3 @@
1
- # TODO Rename the file to environment_variable_exception.py
2
1
  class EnvironmentVariableException(Exception):
3
2
  """Raised when a required environment variable is missing or empty.
4
3
 
@@ -0,0 +1,82 @@
1
+ import re
2
+ import unicodedata
3
+
4
+ # Characters that are illegal in filenames on Windows / most filesystems,
5
+ # plus the ASCII control characters (0x00-0x1F).
6
+ _INVALID_CHARS_PATTERN = re.compile(r'[<>:"/\\|?*\x00-\x1f]')
7
+ _WHITESPACE_PATTERN = re.compile(r'\s+')
8
+
9
+ # Names reserved by Windows (case-insensitive), with or without an extension.
10
+ _RESERVED_NAMES = {
11
+ "CON", "PRN", "AUX", "NUL",
12
+ *(f"COM{i}" for i in range(1, 10)),
13
+ *(f"LPT{i}" for i in range(1, 10)),
14
+ }
15
+
16
+ MAX_FILENAME_LENGTH = 255
17
+
18
+
19
+ def convert_to_valid_filename(
20
+ string: str,
21
+ replacement: str = "_",
22
+ max_length: int = MAX_FILENAME_LENGTH,
23
+ fallback: str = "file",
24
+ ) -> str:
25
+ """Convert an arbitrary string into a filename that is safe to use across
26
+ Windows, macOS and Linux.
27
+
28
+ - Normalises unicode and collapses runs of whitespace into ``replacement``.
29
+ - Replaces characters that are illegal on common filesystems.
30
+ - Strips leading/trailing dots, spaces and ``replacement`` characters.
31
+ - Avoids Windows reserved device names (CON, NUL, COM1, ...).
32
+ - Truncates to ``max_length`` characters while keeping the extension.
33
+ - Returns ``fallback`` when nothing usable remains.
34
+ """
35
+ if not isinstance(string, str):
36
+ string = str(string)
37
+
38
+ filename = unicodedata.normalize("NFKC", string)
39
+ filename = _INVALID_CHARS_PATTERN.sub(replacement, filename)
40
+ filename = _WHITESPACE_PATTERN.sub(replacement, filename)
41
+
42
+ # Trim characters that are problematic at the edges of a filename,
43
+ # repeating until stable so e.g. "_.._" collapses fully.
44
+ edge_chars = " .\t\n\r\f\v" + (replacement or "")
45
+ previous = None
46
+ while filename != previous:
47
+ previous = filename
48
+ filename = filename.strip(edge_chars)
49
+
50
+ if not filename:
51
+ return fallback
52
+
53
+ root, dot, extension = filename.partition(".")
54
+ if root.upper() in _RESERVED_NAMES:
55
+ root = f"{root}{replacement}"
56
+ filename = root + dot + extension
57
+
58
+ if len(filename) > max_length:
59
+ root, dot, extension = filename.rpartition(".")
60
+ if dot and len(extension) < max_length:
61
+ keep = max_length - len(dot) - len(extension)
62
+ filename = root[:keep] + dot + extension
63
+ else:
64
+ filename = filename[:max_length]
65
+ filename = filename.strip(" .")
66
+
67
+ return filename or fallback
68
+
69
+ # def convert_to_valid_filename(name: str) -> str:
70
+ # """Reduce ``name`` to characters that are safe for a single path component.
71
+
72
+ # Every run of characters outside ``[A-Za-z0-9._-]`` (path separators,
73
+ # whitespace, shell metacharacters, ...) collapses to a single underscore and
74
+ # leading / trailing ``.``, ``-`` and ``_`` are trimmed. A falsy input or one
75
+ # that is left empty after sanitising yields ``"unnamed"`` so a usable name is
76
+ # always returned.
77
+ # """
78
+ # if not name:
79
+ # return _FALLBACK_FILENAME
80
+ # sanitized = _INVALID_FILENAME_CHARACTERS_PATTERN.sub("_", str(name))
81
+ # sanitized = sanitized.strip("._-")
82
+ # return sanitized or _FALLBACK_FILENAME
@@ -17,7 +17,7 @@ from .version import PACKAGE_VERSION
17
17
 
18
18
  from .mini_logger import MiniLogger as logger
19
19
 
20
- from .exceptions import EnvironmentVariableException
20
+ from .environment_variable_exception import EnvironmentVariableException
21
21
 
22
22
  load_dotenv()
23
23
  # Load environment variables from .env file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-sdk-remote
3
- Version: 0.0.182
3
+ Version: 0.0.183b1
4
4
  Summary: PyPI Package for Circles Python SDK Local Python
5
5
  Home-page: https://github.com/circles-zone/python-sdk-remote-python-package
6
6
  Author: Circles
@@ -2,7 +2,8 @@ python_sdk_remote/__init__.py,sha256=wBfMpAOPwxDMD4wdG74B5OboGVmC_fKGlEid4p8iAeY
2
2
  python_sdk_remote/constants.py,sha256=UBJta5-UdA1Y-owTesMB4TMht-ZvHApYwXAG8EtL6uE,1372
3
3
  python_sdk_remote/constants_src_mini_logger_and_logger.py,sha256=EB9-UIX-YRfLcFCT1VianrngcoTso397gF07a3WM3zk,437
4
4
  python_sdk_remote/datetime_range.py,sha256=5dCA6vSTnqp6pnd5exEVsmbeWpaee-oxfG0cE21eW_k,4376
5
- python_sdk_remote/exceptions.py,sha256=N4eiN-ijGW3hBOp6AnMy28NH_Ekbtu57b6ZcqzofkVw,347
5
+ python_sdk_remote/environment_variable_exception.py,sha256=kqLZmNT8yfPq-eWUSZvZPBY3sGsSH-igmbqa5EN9PDA,287
6
+ python_sdk_remote/filename.py,sha256=9pqqzCehZj2NIbiqkmij2pruOtdMb08JDX6ldrJ-olY,3054
6
7
  python_sdk_remote/generic_crud.py,sha256=jzmR27kr8Pnf4Gk90SKoxbM5ufLsOr2ofekRtcHw248,9907
7
8
  python_sdk_remote/http_response.py,sha256=T659q_iPt8SkT8k-T4ZfRy9VSh0uvHyluecqwZnhRqI,12888
8
9
  python_sdk_remote/is_test_data.py,sha256=ZVu7ylFMV2FO0w0Huxqo5AXyZZ8GwbqJn3bWMRVR5ZE,110
@@ -16,11 +17,11 @@ python_sdk_remote/our_objects_remote.py,sha256=fdgZwA8DaNA5G3thdUTCj7TRrO6xpqxvR
16
17
  python_sdk_remote/our_request.py,sha256=gPN0dM_CiMzjd3vl6rl1ShJpewBlDwdIREcd4-5j3kc,14132
17
18
  python_sdk_remote/our_request_old.py,sha256=eu0LqvjrhZMT9BHU67etg-iKOnC_MaGbSDq2hT3kfVM,13591
18
19
  python_sdk_remote/unified_json.py,sha256=AmeUzBsQh2N9z9XRo1Aya5qPvcV8dzRa4-O2jlCdaTg,1242
19
- python_sdk_remote/utilities.py,sha256=1nlrE6FXVIdQDtLmF7IR935D6HMKoXIdp5vXRu6t_sY,24305
20
+ python_sdk_remote/utilities.py,sha256=2iQQvUmwyez-bSKB1jTCtpHlt7TISdAAfmO2IlSrf94,24325
20
21
  python_sdk_remote/valid_json_versions.py,sha256=zVtvhsEDKkfK3o8crdcP6YWjLnzh-OykWGPT7vghb6k,147
21
22
  python_sdk_remote/validate_environment.py,sha256=VQKta418TmJwkUGXp0Rorhy65YANoNVgg86BIYPf2Wc,2321
22
23
  python_sdk_remote/version.py,sha256=nJV1jCPXMEluCrvcEBWwM8BS6DzFTv7pULfqjGXs3uA,421
23
- python_sdk_remote-0.0.182.dist-info/METADATA,sha256=eSy6qmQiRT7EHVZ7C_IgiEqtSb0BHoNDegL0hmfF-aY,762
24
- python_sdk_remote-0.0.182.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
25
- python_sdk_remote-0.0.182.dist-info/top_level.txt,sha256=JTpEq_svPlI5hTlPq30Ne-NkR-u5464gjVDP2U74PvE,18
26
- python_sdk_remote-0.0.182.dist-info/RECORD,,
24
+ python_sdk_remote-0.0.183b1.dist-info/METADATA,sha256=R8CKTluT0HDRhahxjskNR6sVOVon-LZtQsSsOGGZOQs,764
25
+ python_sdk_remote-0.0.183b1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
26
+ python_sdk_remote-0.0.183b1.dist-info/top_level.txt,sha256=JTpEq_svPlI5hTlPq30Ne-NkR-u5464gjVDP2U74PvE,18
27
+ python_sdk_remote-0.0.183b1.dist-info/RECORD,,