velocity-python 0.0.71__py3-none-any.whl → 0.0.72__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 velocity-python might be problematic. Click here for more details.

velocity/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = version = "0.0.71"
1
+ __version__ = version = "0.0.72"
2
2
 
3
3
  from . import aws
4
4
  from . import db
velocity/misc/format.py CHANGED
@@ -55,25 +55,39 @@ def human_delta(tdelta: timedelta) -> str:
55
55
  return fmt.format(**d)
56
56
 
57
57
 
58
+ import json
59
+ import decimal
60
+ from datetime import datetime, date, time, timedelta
61
+ from types import FunctionType, MethodType
62
+
63
+
58
64
  def to_json(o, datefmt: str = "%Y-%m-%d", timefmt: str = "%H:%M:%S") -> str:
59
- """Serializes an object to JSON, handling special types like Decimal and datetime."""
65
+ """Serializes an object to JSON, handling special types and reporting any unserializable values."""
60
66
 
61
67
  class JsonEncoder(json.JSONEncoder):
62
68
  def default(self, obj):
63
- if hasattr(obj, "to_json"):
64
- return obj.to_json()
65
- elif obj is None:
66
- return None
67
- elif isinstance(obj, decimal.Decimal):
68
- return float(obj)
69
- elif isinstance(obj, datetime):
70
- return obj.strftime(f"{datefmt} {timefmt}")
71
- elif isinstance(obj, date):
72
- return obj.strftime(datefmt)
73
- elif isinstance(obj, time):
74
- return obj.strftime(timefmt)
75
- elif isinstance(obj, timedelta):
76
- return human_delta(obj)
77
- return super().default(obj)
78
-
79
- return json.dumps(o, cls=JsonEncoder)
69
+ try:
70
+ if hasattr(obj, "to_json"):
71
+ return obj.to_json()
72
+ elif isinstance(obj, decimal.Decimal):
73
+ return float(obj)
74
+ elif isinstance(obj, datetime):
75
+ return obj.strftime(f"{datefmt} {timefmt}")
76
+ elif isinstance(obj, date):
77
+ return obj.strftime(datefmt)
78
+ elif isinstance(obj, time):
79
+ return obj.strftime(timefmt)
80
+ elif isinstance(obj, timedelta):
81
+ return str(obj) # Or use `human_delta(obj)` if defined
82
+ elif isinstance(obj, (FunctionType, MethodType)):
83
+ return f"WARNING: unserializable: method {obj.__name__}"
84
+ else:
85
+ return f"WARNING: unserializable: {type(obj).__name__}" + (
86
+ f" ({getattr(obj, '__name__', '')})"
87
+ if hasattr(obj, "__name__")
88
+ else ""
89
+ )
90
+ except Exception as e:
91
+ return f"WARNING: unserializable: {type(obj).__name__} (error: {e})"
92
+
93
+ return json.dumps(o, cls=JsonEncoder, indent=2)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: velocity-python
3
- Version: 0.0.71
3
+ Version: 0.0.72
4
4
  Summary: A rapid application development library for interfacing with data storage
5
5
  Author-email: Paul Perez <pperez@codeclubs.org>
6
6
  Project-URL: Homepage, https://codeclubs.org/projects/velocity
@@ -1,4 +1,4 @@
1
- velocity/__init__.py,sha256=5wo7K-uWNzbQl7RRKSD2SzOdE4bgZJoh6Y4D-kJSmgc,88
1
+ velocity/__init__.py,sha256=beUkifH4urpDDW9fr3B9E_Vlhii9JT90MHOEUPyNd8g,88
2
2
  velocity/aws/__init__.py,sha256=GBTEr02whnCH3TG-BWCpUC3KfHY3uNxD21g0OvsVJnc,598
3
3
  velocity/aws/handlers/__init__.py,sha256=xnpFZJVlC2uoeeFW4zuPST8wA8ajaQDky5Y6iXZzi3A,172
4
4
  velocity/aws/handlers/context.py,sha256=UIjNR83y2NSIyK8HMPX8t5tpJHFNabiZvNgmmdQL3HA,1822
@@ -33,7 +33,7 @@ velocity/db/servers/postgres/types.py,sha256=Wa45ppVf_pdWul-jYWFRGMl6IdSq8dAp10S
33
33
  velocity/misc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
34
  velocity/misc/db.py,sha256=MPgt-kkukKR_Wh_S_5W-MyDgaeoZ4YLoDJ54wU2ppm4,2830
35
35
  velocity/misc/export.py,sha256=lATvwTe-Of6X7ZtzvJZiFghh9QlyMYZfDfQ_GJyt5yg,5197
36
- velocity/misc/format.py,sha256=fA5ai3kp-bLhPCCg7Yq9XPhUCE3In-jVZobjBGvmHDg,2649
36
+ velocity/misc/format.py,sha256=2IOTTpg-4FhYnaj5G1cTaLvH_j0CJpyOmvLg4mdOuYM,3329
37
37
  velocity/misc/mail.py,sha256=BrxDqeVsOd0epyJKwrHA-owzs6di2oLA_qJskoTux-c,2553
38
38
  velocity/misc/merge.py,sha256=EYtqwnckBllPO60tRALxFRuzmUQ7Wl0qZC6sCgyiZDA,1885
39
39
  velocity/misc/timer.py,sha256=cN3aS0t6HLlhYfF2Ir6ihJehxNrWf9ebaLzXUaWRKEA,1637
@@ -41,8 +41,8 @@ velocity/misc/tools.py,sha256=_bGneHHA_BV-kUonzw5H3hdJ5AOJRCKfzhgpkFbGqIo,1502
41
41
  velocity/misc/conv/__init__.py,sha256=MLYF58QHjzfDSxb1rdnmLnuEQCa3gnhzzZ30CwZVvQo,40
42
42
  velocity/misc/conv/iconv.py,sha256=d4_BucW8HTIkGNurJ7GWrtuptqUf-9t79ObzjJ5N76U,10603
43
43
  velocity/misc/conv/oconv.py,sha256=h5Lo05DqOQnxoD3y6Px_MQP_V-pBbWf8Hkgkb9Xp1jk,6032
44
- velocity_python-0.0.71.dist-info/licenses/LICENSE,sha256=aoN245GG8s9oRUU89KNiGTU4_4OtnNmVi4hQeChg6rM,1076
45
- velocity_python-0.0.71.dist-info/METADATA,sha256=TeqzaKYxa2-lZmGNwNAHE9XF9xVft2C1Gutljm_VZQ8,8541
46
- velocity_python-0.0.71.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
47
- velocity_python-0.0.71.dist-info/top_level.txt,sha256=JW2vJPmodgdgSz7H6yoZvnxF8S3fTMIv-YJWCT1sNW0,9
48
- velocity_python-0.0.71.dist-info/RECORD,,
44
+ velocity_python-0.0.72.dist-info/licenses/LICENSE,sha256=aoN245GG8s9oRUU89KNiGTU4_4OtnNmVi4hQeChg6rM,1076
45
+ velocity_python-0.0.72.dist-info/METADATA,sha256=l9HIHBZTq6tEsXKQaIfLp9eKCDSLFUyVKwQrJ9WQq6w,8541
46
+ velocity_python-0.0.72.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
47
+ velocity_python-0.0.72.dist-info/top_level.txt,sha256=JW2vJPmodgdgSz7H6yoZvnxF8S3fTMIv-YJWCT1sNW0,9
48
+ velocity_python-0.0.72.dist-info/RECORD,,