python-ubercode-utils 1.0.10__tar.gz → 2.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.
- {python-ubercode-utils-1.0.10/python_ubercode_utils.egg-info → python-ubercode-utils-2.0.0}/PKG-INFO +1 -1
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0/python_ubercode_utils.egg-info}/PKG-INFO +1 -1
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/setup.py +1 -1
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/test/test_data.py +5 -7
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/ubercode/utils/convert.py +28 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/ubercode/utils/data.py +14 -23
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/LICENSE +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/MANIFEST.in +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/README.md +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/python_ubercode_utils.egg-info/SOURCES.txt +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/python_ubercode_utils.egg-info/dependency_links.txt +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/python_ubercode_utils.egg-info/not-zip-safe +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/python_ubercode_utils.egg-info/top_level.txt +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/setup.cfg +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/test/test_convert.py +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/test/test_cursor.py +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/test/test_dataframe.py +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/test/test_environment.py +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/test/test_logging.py +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/test/test_urls.py +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/ubercode/__init__.py +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/ubercode/utils/__init__.py +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/ubercode/utils/cursor.py +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/ubercode/utils/dataframe.py +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/ubercode/utils/environment.py +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/ubercode/utils/logging.py +0 -0
- {python-ubercode-utils-1.0.10 → python-ubercode-utils-2.0.0}/ubercode/utils/urls.py +0 -0
|
@@ -4,7 +4,7 @@ with open("README.md", "r") as fh:
|
|
|
4
4
|
long_description = fh.read()
|
|
5
5
|
|
|
6
6
|
setuptools.setup(name='python-ubercode-utils',
|
|
7
|
-
version='
|
|
7
|
+
version='2.0.0',
|
|
8
8
|
description='Core python utilities for all apps',
|
|
9
9
|
long_description=long_description,
|
|
10
10
|
long_description_content_type="text/markdown",
|
|
@@ -49,12 +49,10 @@ class TestJSON(unittest.TestCase):
|
|
|
49
49
|
"""
|
|
50
50
|
# test we can construct from a json string
|
|
51
51
|
json = JSON(json_string=json_string)
|
|
52
|
-
self.assertEqual(len(json.
|
|
52
|
+
self.assertEqual(len(json.data['people']), 3)
|
|
53
53
|
# test we can construct by chaining and reading file
|
|
54
54
|
json2 = JSON().from_json_file(str(file_path))
|
|
55
|
-
self.assertEqual(json.
|
|
56
|
-
# test the dict matches the to_dict() result
|
|
57
|
-
self.assertEqual(json.json_dict, json.to_dict())
|
|
55
|
+
self.assertEqual(json.data, json2.data)
|
|
58
56
|
# test encoding
|
|
59
57
|
json_string = """
|
|
60
58
|
{
|
|
@@ -92,11 +90,11 @@ class TestJSON(unittest.TestCase):
|
|
|
92
90
|
}
|
|
93
91
|
"""
|
|
94
92
|
json = JSON(json_string=json_string, encode_ampersands=True)
|
|
95
|
-
self.assertEqual(len(json.
|
|
96
|
-
first_name = json.
|
|
93
|
+
self.assertEqual(len(json.data['people']), 3)
|
|
94
|
+
first_name = json.data['people'][0]['firstName']
|
|
97
95
|
self.assertEqual(first_name, "Joe & Baker")
|
|
98
96
|
# make sure the second name isn't double encoded
|
|
99
|
-
second_name = json.
|
|
97
|
+
second_name = json.data['people'][1]['firstName']
|
|
100
98
|
self.assertEqual(second_name, "James &")
|
|
101
99
|
# test the str function
|
|
102
100
|
result = "{'people': [{'firstName': 'Joe & Baker', 'lastName': 'Jackson', 'gender': 'male', 'age': 28, 'number': '7349282382', 'groups': ['members', 'student']}, {'firstName': 'James &', 'lastName': 'Smith', 'gender': 'male', 'age': 32, 'number': '5678568567', 'groups': ['members', 'professional']}, {'firstName': 'Emily', 'lastName': 'Jones', 'gender': 'female', 'age': 24, 'number': '456754675'}]}"
|
|
@@ -250,3 +250,31 @@ def to_mask(value: str or None) -> str or None:
|
|
|
250
250
|
_mask += value[-_iqtr:]
|
|
251
251
|
return _mask
|
|
252
252
|
|
|
253
|
+
def obj_to_str(obj, property_filter_list=None):
|
|
254
|
+
"""
|
|
255
|
+
Mostly used for debugging. Very useful to print the properties of an object on a line; condensing reasonably
|
|
256
|
+
|
|
257
|
+
:param obj: the object to inspect properties for
|
|
258
|
+
:param property_filter_list: any property names we want to omit
|
|
259
|
+
:return: a string containing the outputted properties
|
|
260
|
+
"""
|
|
261
|
+
attbuf = ""
|
|
262
|
+
for key, value in vars(obj).items():
|
|
263
|
+
if property_filter_list and key in property_filter_list:
|
|
264
|
+
continue
|
|
265
|
+
if not key.startswith('__'):
|
|
266
|
+
if len(attbuf) > 0:
|
|
267
|
+
attbuf += ", "
|
|
268
|
+
# show the first 50 chars and last 25 chars
|
|
269
|
+
this_content = str(value)
|
|
270
|
+
this_content = this_content.replace('\n', ' ').replace('\r', '').strip()
|
|
271
|
+
if this_content:
|
|
272
|
+
if len(this_content) > 150:
|
|
273
|
+
attbuf += str(key) + ": [" + this_content[0:25] + " ... " + this_content[
|
|
274
|
+
len(this_content) - 25:len(
|
|
275
|
+
this_content)] + "]"
|
|
276
|
+
else:
|
|
277
|
+
attbuf += str(key) + ": " + this_content or ""
|
|
278
|
+
else:
|
|
279
|
+
attbuf += str(key) + ": " + this_content or ""
|
|
280
|
+
return "[" + attbuf + "]"
|
|
@@ -11,10 +11,9 @@ from collections import defaultdict
|
|
|
11
11
|
|
|
12
12
|
class JSON:
|
|
13
13
|
""" simple json class to encapsulate basic json operations """
|
|
14
|
-
# the base implementation will be dict
|
|
15
|
-
json_dict = {}
|
|
16
|
-
|
|
17
14
|
def __init__(self, json_string: str or None = None, encode_ampersands: bool = False):
|
|
15
|
+
# data is core python objects (list, dict, object, etc) from the core python JSON.loads
|
|
16
|
+
self.data = None
|
|
18
17
|
self.encode_ampersands = encode_ampersands
|
|
19
18
|
self.from_json_string(json_string)
|
|
20
19
|
|
|
@@ -28,7 +27,7 @@ class JSON:
|
|
|
28
27
|
if self.encode_ampersands:
|
|
29
28
|
regex = re.compile(r"&(?!amp;|lt;|gt;)")
|
|
30
29
|
json_string = regex.sub("&", json_string)
|
|
31
|
-
self.
|
|
30
|
+
self.data = json.loads(json_string)
|
|
32
31
|
return self
|
|
33
32
|
|
|
34
33
|
def from_json_file(self, json_file_path: str):
|
|
@@ -43,26 +42,18 @@ class JSON:
|
|
|
43
42
|
if self.encode_ampersands:
|
|
44
43
|
regex = re.compile(r"&(?!amp;|lt;|gt;)")
|
|
45
44
|
json_string = regex.sub("&", json_string)
|
|
46
|
-
self.
|
|
45
|
+
self.data = json.loads(json_string)
|
|
47
46
|
return self
|
|
48
47
|
|
|
49
|
-
def to_dict(self) -> dict:
|
|
50
|
-
"""
|
|
51
|
-
output to dict
|
|
52
|
-
:return: dict
|
|
53
|
-
"""
|
|
54
|
-
return self.json_dict
|
|
55
|
-
|
|
56
48
|
def __str__(self):
|
|
57
|
-
return str(self.
|
|
49
|
+
return str(self.data)
|
|
58
50
|
|
|
59
51
|
|
|
60
52
|
class XML:
|
|
61
|
-
""" simple xml class to encapsulate basic xml operations """
|
|
62
|
-
# the base implementation will be Etree from the base python lib
|
|
63
|
-
xml_tree = None
|
|
64
|
-
|
|
53
|
+
""" simple xml class to encapsulate basic xml operations using build in python ETree """
|
|
65
54
|
def __init__(self, xml_string: str or None = None, encode_ampersands: bool = False):
|
|
55
|
+
# data is core python ElementTree object
|
|
56
|
+
self.data = None
|
|
66
57
|
self.encode_ampersands = encode_ampersands
|
|
67
58
|
self.from_xml_string(xml_string)
|
|
68
59
|
|
|
@@ -76,7 +67,7 @@ class XML:
|
|
|
76
67
|
if self.encode_ampersands:
|
|
77
68
|
regex = re.compile(r"&(?!amp;|lt;|gt;)")
|
|
78
69
|
xml_string = regex.sub("&", xml_string)
|
|
79
|
-
self.
|
|
70
|
+
self.data = Etree.fromstring(xml_string)
|
|
80
71
|
return self
|
|
81
72
|
|
|
82
73
|
def from_xml_file(self, xml_file_path: str):
|
|
@@ -96,7 +87,7 @@ class XML:
|
|
|
96
87
|
else:
|
|
97
88
|
tree = Etree.parse(xml_file_path)
|
|
98
89
|
tree = tree.getroot()
|
|
99
|
-
self.
|
|
90
|
+
self.data = tree
|
|
100
91
|
return self
|
|
101
92
|
|
|
102
93
|
def to_dict(self) -> dict:
|
|
@@ -104,10 +95,10 @@ class XML:
|
|
|
104
95
|
output to dict
|
|
105
96
|
:return: dict
|
|
106
97
|
"""
|
|
107
|
-
return XML.tree_to_dict(self.
|
|
98
|
+
return XML.tree_to_dict(self.data)
|
|
108
99
|
|
|
109
100
|
@staticmethod
|
|
110
|
-
def tree_to_dict(t) -> dict:
|
|
101
|
+
def tree_to_dict(t: Etree) -> dict:
|
|
111
102
|
"""
|
|
112
103
|
Convert an etree structure to a dictionary of values
|
|
113
104
|
:param t: etree instance
|
|
@@ -133,6 +124,6 @@ class XML:
|
|
|
133
124
|
return d
|
|
134
125
|
|
|
135
126
|
def __str__(self):
|
|
136
|
-
if self.
|
|
137
|
-
return Etree.tostring(self.
|
|
127
|
+
if self.data:
|
|
128
|
+
return Etree.tostring(self.data, encoding='unicode')
|
|
138
129
|
return ""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|