svg-ultralight 0.24.0__py3-none-any.whl → 0.26.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.
Potentially problematic release.
This version of svg-ultralight might be problematic. Click here for more details.
- svg_ultralight/__init__.py +6 -1
- svg_ultralight/bounding_boxes/type_bounding_box.py +0 -7
- svg_ultralight/string_conversion.py +19 -12
- {svg_ultralight-0.24.0.dist-info → svg_ultralight-0.26.0.dist-info}/METADATA +1 -1
- {svg_ultralight-0.24.0.dist-info → svg_ultralight-0.26.0.dist-info}/RECORD +7 -7
- {svg_ultralight-0.24.0.dist-info → svg_ultralight-0.26.0.dist-info}/WHEEL +0 -0
- {svg_ultralight-0.24.0.dist-info → svg_ultralight-0.26.0.dist-info}/top_level.txt +0 -0
svg_ultralight/__init__.py
CHANGED
|
@@ -26,7 +26,11 @@ from svg_ultralight.metadata import new_metadata
|
|
|
26
26
|
from svg_ultralight.nsmap import NSMAP, new_qname
|
|
27
27
|
from svg_ultralight.query import pad_text
|
|
28
28
|
from svg_ultralight.root_elements import new_svg_root_around_bounds
|
|
29
|
-
from svg_ultralight.string_conversion import
|
|
29
|
+
from svg_ultralight.string_conversion import (
|
|
30
|
+
format_number,
|
|
31
|
+
format_numbers,
|
|
32
|
+
format_numbers_in_string,
|
|
33
|
+
)
|
|
30
34
|
|
|
31
35
|
__all__ = [
|
|
32
36
|
"BoundElement",
|
|
@@ -37,6 +41,7 @@ __all__ = [
|
|
|
37
41
|
"deepcopy_element",
|
|
38
42
|
"format_number",
|
|
39
43
|
"format_numbers",
|
|
44
|
+
"format_numbers_in_string",
|
|
40
45
|
"new_element",
|
|
41
46
|
"new_metadata",
|
|
42
47
|
"new_qname",
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
|
-
import warnings
|
|
10
9
|
from dataclasses import dataclass
|
|
11
10
|
|
|
12
11
|
from svg_ultralight.bounding_boxes.supports_bounds import SupportsBounds
|
|
@@ -286,12 +285,6 @@ class BoundingBox(SupportsBounds):
|
|
|
286
285
|
:return: a bounding box around self and other bounding boxes
|
|
287
286
|
:raises DeprecationWarning:
|
|
288
287
|
"""
|
|
289
|
-
warnings.warn(
|
|
290
|
-
"Method a.merge(b, c) is deprecated. "
|
|
291
|
-
+ "Use classmethod BoundingBox.merged(a, b, c) instead.",
|
|
292
|
-
category=DeprecationWarning,
|
|
293
|
-
stacklevel=1,
|
|
294
|
-
)
|
|
295
288
|
return BoundingBox.merged(self, *others)
|
|
296
289
|
|
|
297
290
|
@classmethod
|
|
@@ -11,6 +11,7 @@ Rounding some numbers to ensure quality svg rendering:
|
|
|
11
11
|
from __future__ import annotations
|
|
12
12
|
|
|
13
13
|
import re
|
|
14
|
+
from contextlib import suppress
|
|
14
15
|
from enum import Enum
|
|
15
16
|
from typing import TYPE_CHECKING, cast
|
|
16
17
|
|
|
@@ -71,15 +72,26 @@ def _is_float_or_float_str(data: float | str) -> bool:
|
|
|
71
72
|
return True
|
|
72
73
|
|
|
73
74
|
|
|
74
|
-
def
|
|
75
|
+
def format_numbers_in_string(data: float | str) -> str:
|
|
75
76
|
"""Find and format floats in a string.
|
|
76
77
|
|
|
77
|
-
:param data: string with floats
|
|
78
|
+
:param data: string with floats or a float value
|
|
78
79
|
:return: string with floats formatted to limited precision
|
|
79
80
|
|
|
80
|
-
|
|
81
|
+
Works as a more robust version of format_number. Will correctly handle input
|
|
82
|
+
floats in exponential notation. This should work for any parameter value in an
|
|
83
|
+
svg except 'text', 'id' and for any other value except hex color codes. The
|
|
84
|
+
function will fail with input strings like 'ice3.14bucket', because 'e3.14' will
|
|
85
|
+
be identified as a float. SVG param values will not have such strings, but the
|
|
86
|
+
'text' attribute could. This function will not handle that case. Do not attempt
|
|
87
|
+
to reformat 'text' attribute values.
|
|
81
88
|
"""
|
|
82
|
-
|
|
89
|
+
with suppress(ValueError):
|
|
90
|
+
# try as a regular number to strip spaces from simple float strings
|
|
91
|
+
return format_number(data)
|
|
92
|
+
if str(data).startswith("#"):
|
|
93
|
+
return str(data)
|
|
94
|
+
words = re.split(r"([^\d.eE-]+)", str(data))
|
|
83
95
|
words = [format_number(w) if _is_float_or_float_str(w) else w for w in words]
|
|
84
96
|
return "".join(words)
|
|
85
97
|
|
|
@@ -114,15 +126,10 @@ def _fix_key_and_format_val(key: str, val: str | float) -> tuple[str, str]:
|
|
|
114
126
|
else:
|
|
115
127
|
key_ = key.rstrip("_").replace("_", "-")
|
|
116
128
|
|
|
117
|
-
if key_
|
|
118
|
-
|
|
119
|
-
return key_, _format_datastring(val)
|
|
120
|
-
msg = f"Expected string for 'd' attribute, got {val} of type {type(val)}"
|
|
121
|
-
raise ValueError(msg)
|
|
129
|
+
if key_ in {"id", "text"}:
|
|
130
|
+
return key_, str(val)
|
|
122
131
|
|
|
123
|
-
|
|
124
|
-
return key_, format_number(val)
|
|
125
|
-
return key_, str(val)
|
|
132
|
+
return key_, format_numbers_in_string(val)
|
|
126
133
|
|
|
127
134
|
|
|
128
135
|
def format_attr_dict(**attributes: str | float) -> dict[str, str]:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
svg_ultralight/__init__.py,sha256=
|
|
1
|
+
svg_ultralight/__init__.py,sha256=5n-7C9idISTR56-AqZ834DpmYGgPUBdtFK7iIekiCqc,1627
|
|
2
2
|
svg_ultralight/animate.py,sha256=JSrBm-59BcNXDF0cGgl4-C89eBunjevZnwZxIWt48TU,1112
|
|
3
3
|
svg_ultralight/inkscape.py,sha256=M8yTxXOu4NlXnhsMycvEJiIDpnDeiZ_bZakJBM38ZoU,9152
|
|
4
4
|
svg_ultralight/layout.py,sha256=TTETT_8WLBXnQxDGXdAeczCFN5pFo5kKY3Q6zv4FPX4,12238
|
|
@@ -8,18 +8,18 @@ svg_ultralight/nsmap.py,sha256=y63upO78Rr-JJT56RWWZuyrsILh6HPoY4GhbYnK1A0g,1244
|
|
|
8
8
|
svg_ultralight/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
svg_ultralight/query.py,sha256=PFyhR9v60JkuksRb0LVkml67nmOxfZW9eCtL-JoH52Y,7270
|
|
10
10
|
svg_ultralight/root_elements.py,sha256=rUc26ec-FLAUgO5iOF3aOeKZC7CjiTw7TGyGAj33yNU,3219
|
|
11
|
-
svg_ultralight/string_conversion.py,sha256=
|
|
11
|
+
svg_ultralight/string_conversion.py,sha256=WEmpf75RJmJ2lfJluagAz2wPsz6wM8XvTEwkq4U0vEc,7353
|
|
12
12
|
svg_ultralight/unit_conversion.py,sha256=g07nhzXdjPvGcJmkhLdFbeDLrSmbI8uFoVgPo7G62Bg,9258
|
|
13
13
|
svg_ultralight/bounding_boxes/__init__.py,sha256=qUEn3r4s-1QNHaguhWhhaNfdP4tl_B6YEqxtiTFuzhQ,78
|
|
14
14
|
svg_ultralight/bounding_boxes/supports_bounds.py,sha256=1yqmZ7PH1bBH-LTIUDzSvKFXkPLXfJM7jJNz0bXurZ4,3926
|
|
15
15
|
svg_ultralight/bounding_boxes/type_bound_element.py,sha256=VKiN4UnC2XlPKapWRHxgtqhO4BuVoe6YkLrirlEP09w,5714
|
|
16
|
-
svg_ultralight/bounding_boxes/type_bounding_box.py,sha256=
|
|
16
|
+
svg_ultralight/bounding_boxes/type_bounding_box.py,sha256=OqvS6LhfMwnoE4PUwAmHlY0tjY-2YQZQiLY6O2U3vfs,10378
|
|
17
17
|
svg_ultralight/bounding_boxes/type_padded_text.py,sha256=FnwHD54qPMlyOB0yhRgZShQWA_riaaTS9GwD9HnbPm4,14119
|
|
18
18
|
svg_ultralight/constructors/__init__.py,sha256=YcnO0iBQc19aL8Iemw0Y452MBMBIT2AN5nZCnoGxpn0,327
|
|
19
19
|
svg_ultralight/constructors/new_element.py,sha256=VtMz9sPn9rMk6rui5Poysy3vezlOaS-tGIcGbu-SXmY,3406
|
|
20
20
|
svg_ultralight/strings/__init__.py,sha256=Zalrf-ThFz7b7xKELx5lb2gOlBgV-6jk_k_EeSdVCVk,295
|
|
21
21
|
svg_ultralight/strings/svg_strings.py,sha256=RYKMxOHq9abbZyGcFqsElBGLrBX-EjjNxln3s_ibi30,1296
|
|
22
|
-
svg_ultralight-0.
|
|
23
|
-
svg_ultralight-0.
|
|
24
|
-
svg_ultralight-0.
|
|
25
|
-
svg_ultralight-0.
|
|
22
|
+
svg_ultralight-0.26.0.dist-info/METADATA,sha256=5SIJniz8QdUQVaARRpewHQv6lkmLnetygXSSnVCNmUg,8871
|
|
23
|
+
svg_ultralight-0.26.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
24
|
+
svg_ultralight-0.26.0.dist-info/top_level.txt,sha256=se-6yqM_0Yg5orJKvKWdjQZ4iR4G_EjhL7oRgju-fdY,15
|
|
25
|
+
svg_ultralight-0.26.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|