jsonb 1.0.0__tar.gz
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.
- jsonb-1.0.0/LICENSE +21 -0
- jsonb-1.0.0/PKG-INFO +27 -0
- jsonb-1.0.0/README.md +10 -0
- jsonb-1.0.0/jsonb/__init__.py +190 -0
- jsonb-1.0.0/jsonb.egg-info/PKG-INFO +27 -0
- jsonb-1.0.0/jsonb.egg-info/SOURCES.txt +10 -0
- jsonb-1.0.0/jsonb.egg-info/dependency_links.txt +1 -0
- jsonb-1.0.0/jsonb.egg-info/top_level.txt +1 -0
- jsonb-1.0.0/jsonb.egg-info/zip-safe +1 -0
- jsonb-1.0.0/setup.cfg +7 -0
- jsonb-1.0.0/setup.py +25 -0
jsonb-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Ouroboros Coding Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
jsonb-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: jsonb
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: JSON Better - A Python Library Used to simplify encoding/decoding JSON while handling special types
|
|
5
|
+
Home-page: https://github.com/ouroboroscoding/jsonb
|
|
6
|
+
Author: Chris Nasr - Ouroboros Coding Inc.
|
|
7
|
+
Author-email: chris@ouroboroscoding.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Source, https://github.com/ouroboroscoding/jsonb
|
|
10
|
+
Project-URL: Tracker, https://github.com/ouroboroscoding/jsonb/issues
|
|
11
|
+
Keywords: jsonb
|
|
12
|
+
Platform: UNKNOWN
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
|
|
17
|
+
# JSON Better
|
|
18
|
+
A Python Library Used to simplify encoding/decoding JSON while handling special types
|
|
19
|
+
|
|
20
|
+
# Install
|
|
21
|
+
```
|
|
22
|
+
pip install jsonb
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
# Requires
|
|
26
|
+
jsonb requires python 3.10 or higher
|
|
27
|
+
|
jsonb-1.0.0/README.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# coding=utf8
|
|
2
|
+
"""JSON Better
|
|
3
|
+
|
|
4
|
+
Wrapper for Python json module which handles custom types
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
__author__ = "Chris Nasr"
|
|
8
|
+
__copyright__ = "Ouroboros Coding Inc."
|
|
9
|
+
__email__ = "chris@ouroboroscoding.com"
|
|
10
|
+
__created__ = "2023-03-15"
|
|
11
|
+
|
|
12
|
+
# Python modules
|
|
13
|
+
import json
|
|
14
|
+
from datetime import datetime
|
|
15
|
+
from decimal import Decimal
|
|
16
|
+
import os
|
|
17
|
+
|
|
18
|
+
def add_class(cls, constructor: callable, callback: callable):
|
|
19
|
+
"""Add Class
|
|
20
|
+
|
|
21
|
+
Allows adding a class to be processed by a special callback
|
|
22
|
+
|
|
23
|
+
Arguments
|
|
24
|
+
constructor (type): The class to be processed by the callback
|
|
25
|
+
callback (function): The callback to pass instances of the class
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
None
|
|
29
|
+
"""
|
|
30
|
+
__Encoder.add_class(constructor, callback)
|
|
31
|
+
|
|
32
|
+
def decode(s: str):
|
|
33
|
+
"""Decode
|
|
34
|
+
|
|
35
|
+
Handles decoding JSON, as a string, into objects/values
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
s (str): The JSON to decode
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
mixed
|
|
42
|
+
"""
|
|
43
|
+
return json.loads(s, parse_float=Decimal)
|
|
44
|
+
|
|
45
|
+
def decodef(f):
|
|
46
|
+
"""Decode File
|
|
47
|
+
|
|
48
|
+
Handles decoding JSON, from a file, into objects/values
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
f (_io.TextIOWrapper): An instance of a file object with read/write
|
|
52
|
+
methods
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
mixed
|
|
56
|
+
"""
|
|
57
|
+
return json.load(f, parse_float=Decimal)
|
|
58
|
+
|
|
59
|
+
def encode(o: any, indent = None):
|
|
60
|
+
"""Encode
|
|
61
|
+
|
|
62
|
+
Handles encoding objects/values into a JSON string
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
o (any): The object or value to encode
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
str
|
|
69
|
+
"""
|
|
70
|
+
return json.dumps(o, cls=__Encoder, indent=indent)
|
|
71
|
+
|
|
72
|
+
def encodef(o, f, indent=None):
|
|
73
|
+
"""Encode File
|
|
74
|
+
|
|
75
|
+
Handles encoding objects/values into JSON and storing them in the given file
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
o (mixed): The object or value to encode
|
|
79
|
+
f (_io.TextIOWrapper): An instance of a file object with read/write
|
|
80
|
+
methods
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
None
|
|
84
|
+
"""
|
|
85
|
+
return json.dump(o, f, cls=__Encoder, indent=indent)
|
|
86
|
+
|
|
87
|
+
# load function
|
|
88
|
+
def load(filepath):
|
|
89
|
+
"""Load
|
|
90
|
+
|
|
91
|
+
Loads a data structure from a JSON file given a full or relative path to it
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
filepath (str): The path to the file to load
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
mixed
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
# If ~ is present
|
|
101
|
+
if '~' in filepath:
|
|
102
|
+
filepath = os.path.expanduser(filepath)
|
|
103
|
+
|
|
104
|
+
# Load the file
|
|
105
|
+
with open(filepath, 'r') as oFile:
|
|
106
|
+
|
|
107
|
+
# Convert it to a python variable and return it
|
|
108
|
+
return decode(oFile.read())
|
|
109
|
+
|
|
110
|
+
# store function
|
|
111
|
+
def store(data, filepath, indent=None):
|
|
112
|
+
"""Store
|
|
113
|
+
|
|
114
|
+
Converts an object/value into JSON and stores it in the file path given
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
filepath (str): The full or relative path to the file
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
None
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
# If ~ is present
|
|
124
|
+
if '~' in filepath:
|
|
125
|
+
filepath = os.path.expanduser(filepath)
|
|
126
|
+
|
|
127
|
+
# Open a file to write the data
|
|
128
|
+
with open(filepath, 'w') as oFile:
|
|
129
|
+
|
|
130
|
+
# Write the JSON to the file
|
|
131
|
+
oFile.write(encode(data, indent))
|
|
132
|
+
|
|
133
|
+
class __Encoder(json.JSONEncoder):
|
|
134
|
+
"""Encoder
|
|
135
|
+
|
|
136
|
+
Handles encoding types the default JSON encoder can't handle
|
|
137
|
+
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
__classes = [
|
|
141
|
+
[datetime, lambda x: x.strftime('%Y-%m-%d %H:%M:%S')],
|
|
142
|
+
[Decimal, lambda x: '{0:f}'.format(x)]
|
|
143
|
+
]
|
|
144
|
+
"""Classes
|
|
145
|
+
|
|
146
|
+
Holds the classes which will be processed differently then
|
|
147
|
+
regular data types"""
|
|
148
|
+
|
|
149
|
+
@classmethod
|
|
150
|
+
def add_class(cls, constructor: callable, callback: callable):
|
|
151
|
+
"""Add Class
|
|
152
|
+
|
|
153
|
+
Allows adding a class to be processed by a special callback
|
|
154
|
+
|
|
155
|
+
Arguments
|
|
156
|
+
constructor (type): The class to be processed by the callback
|
|
157
|
+
callback (function): The callback to pass instances of the class
|
|
158
|
+
|
|
159
|
+
Returns:
|
|
160
|
+
None
|
|
161
|
+
"""
|
|
162
|
+
|
|
163
|
+
# Append the new class to the list
|
|
164
|
+
cls.__classes.append([constructor, callback])
|
|
165
|
+
|
|
166
|
+
# default method
|
|
167
|
+
def default(self, obj):
|
|
168
|
+
"""Default
|
|
169
|
+
|
|
170
|
+
Called when the regular Encoder can't figure out what to do with the
|
|
171
|
+
type
|
|
172
|
+
|
|
173
|
+
Args:
|
|
174
|
+
obj (mixed): An unknown object or value that needs to be encoded
|
|
175
|
+
|
|
176
|
+
Returns:
|
|
177
|
+
str
|
|
178
|
+
"""
|
|
179
|
+
|
|
180
|
+
# Go through each class
|
|
181
|
+
for l in self.__classes:
|
|
182
|
+
|
|
183
|
+
# If the types match
|
|
184
|
+
if isinstance(obj, l[0]):
|
|
185
|
+
|
|
186
|
+
# Return the result of the custom callback
|
|
187
|
+
return l[1](obj)
|
|
188
|
+
|
|
189
|
+
# Bubble back up to the parent default
|
|
190
|
+
return json.JSONEncoder.default(self, obj)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: jsonb
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: JSON Better - A Python Library Used to simplify encoding/decoding JSON while handling special types
|
|
5
|
+
Home-page: https://github.com/ouroboroscoding/jsonb
|
|
6
|
+
Author: Chris Nasr - Ouroboros Coding Inc.
|
|
7
|
+
Author-email: chris@ouroboroscoding.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Source, https://github.com/ouroboroscoding/jsonb
|
|
10
|
+
Project-URL: Tracker, https://github.com/ouroboroscoding/jsonb/issues
|
|
11
|
+
Keywords: jsonb
|
|
12
|
+
Platform: UNKNOWN
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
|
|
17
|
+
# JSON Better
|
|
18
|
+
A Python Library Used to simplify encoding/decoding JSON while handling special types
|
|
19
|
+
|
|
20
|
+
# Install
|
|
21
|
+
```
|
|
22
|
+
pip install jsonb
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
# Requires
|
|
26
|
+
jsonb requires python 3.10 or higher
|
|
27
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
jsonb
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
jsonb-1.0.0/setup.cfg
ADDED
jsonb-1.0.0/setup.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from setuptools import setup
|
|
2
|
+
|
|
3
|
+
with open('README.md', 'r') as oF:
|
|
4
|
+
long_description=oF.read()
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name='jsonb',
|
|
8
|
+
version='1.0.0',
|
|
9
|
+
description='JSON Better - A Python Library Used to simplify encoding/decoding JSON while handling special types',
|
|
10
|
+
long_description=long_description,
|
|
11
|
+
long_description_content_type='text/markdown',
|
|
12
|
+
url='https://github.com/ouroboroscoding/jsonb',
|
|
13
|
+
project_urls={
|
|
14
|
+
'Source': 'https://github.com/ouroboroscoding/jsonb',
|
|
15
|
+
'Tracker': 'https://github.com/ouroboroscoding/jsonb/issues'
|
|
16
|
+
},
|
|
17
|
+
keywords=['jsonb'],
|
|
18
|
+
author='Chris Nasr - Ouroboros Coding Inc.',
|
|
19
|
+
author_email='chris@ouroboroscoding.com',
|
|
20
|
+
license='MIT',
|
|
21
|
+
packages=['jsonb'],
|
|
22
|
+
python_requires='>=3.10',
|
|
23
|
+
install_requires=[],
|
|
24
|
+
zip_safe=True
|
|
25
|
+
)
|