velocity-python 0.0.71__py3-none-any.whl → 0.0.73__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.73"
2
2
 
3
3
  from . import aws
4
4
  from . import db
velocity/misc/format.py CHANGED
@@ -1,7 +1,7 @@
1
1
  import decimal
2
2
  import json
3
- from datetime import datetime, date, time, timedelta
4
3
  from typing import Union
4
+ from types import FunctionType, MethodType
5
5
 
6
6
 
7
7
  def gallons(data: Union[None, str, float, decimal.Decimal]) -> str:
@@ -56,24 +56,32 @@ def human_delta(tdelta: timedelta) -> str:
56
56
 
57
57
 
58
58
  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."""
59
+ """Serializes an object to JSON, handling special types and reporting any unserializable values."""
60
60
 
61
61
  class JsonEncoder(json.JSONEncoder):
62
62
  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)
63
+ try:
64
+ if hasattr(obj, "to_json"):
65
+ return obj.to_json()
66
+ elif isinstance(obj, decimal.Decimal):
67
+ return float(obj)
68
+ elif isinstance(obj, datetime):
69
+ return obj.strftime(f"{datefmt} {timefmt}")
70
+ elif isinstance(obj, date):
71
+ return obj.strftime(datefmt)
72
+ elif isinstance(obj, time):
73
+ return obj.strftime(timefmt)
74
+ elif isinstance(obj, timedelta):
75
+ return str(obj) # Or use `human_delta(obj)` if defined
76
+ elif isinstance(obj, (FunctionType, MethodType)):
77
+ return f"WARNING: unserializable: method {obj.__name__}"
78
+ else:
79
+ return f"WARNING: unserializable: {type(obj).__name__}" + (
80
+ f" ({getattr(obj, '__name__', '')})"
81
+ if hasattr(obj, "__name__")
82
+ else ""
83
+ )
84
+ except Exception as e:
85
+ return f"WARNING: unserializable: {type(obj).__name__} (error: {e})"
78
86
 
79
- return json.dumps(o, cls=JsonEncoder)
87
+ 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.73
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=cWjkThkpvM0EN3Ra60b8xJkrPT6uwoye_7v53gYL6kE,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=Cu5XkcaTooiE58NmBrIbiHREcM3rnokXpvl4vr2rSyc,3194
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.73.dist-info/licenses/LICENSE,sha256=aoN245GG8s9oRUU89KNiGTU4_4OtnNmVi4hQeChg6rM,1076
45
+ velocity_python-0.0.73.dist-info/METADATA,sha256=LjATZS6tCNxLtwItLmcXoZ9b8Fj7dal_8cc7r1tTCCs,8541
46
+ velocity_python-0.0.73.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
47
+ velocity_python-0.0.73.dist-info/top_level.txt,sha256=JW2vJPmodgdgSz7H6yoZvnxF8S3fTMIv-YJWCT1sNW0,9
48
+ velocity_python-0.0.73.dist-info/RECORD,,