kongalib 2.0.4__cp314-cp314-macosx_10_15_universal2.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 kongalib might be problematic. Click here for more details.
- _kongalib.cpython-314-darwin.so +0 -0
- kongalib/__init__.py +394 -0
- kongalib/async_client.py +813 -0
- kongalib/client.py +1045 -0
- kongalib/constants.json +1 -0
- kongalib/constants.py +187 -0
- kongalib/data_dictionary.py +203 -0
- kongalib/db.py +267 -0
- kongalib/expression.py +841 -0
- kongalib/json.py +114 -0
- kongalib/lex.py +1058 -0
- kongalib/scripting.py +766 -0
- kongalib/yacc.py +3276 -0
- kongalib-2.0.4.dist-info/METADATA +150 -0
- kongalib-2.0.4.dist-info/RECORD +21 -0
- kongalib-2.0.4.dist-info/WHEEL +6 -0
- kongalib-2.0.4.dist-info/licenses/LICENSE +165 -0
- kongalib-2.0.4.dist-info/top_level.txt +4 -0
- kongalib-2.0.4.dist-info/zip-safe +1 -0
- kongaui.py +507 -0
- kongautil.py +581 -0
kongalib/json.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# _ _ _ _
|
|
3
|
+
# | | | (_) |
|
|
4
|
+
# | | _____ _ __ __ _ __ _| |_| |__
|
|
5
|
+
# | |/ / _ \| '_ \ / _` |/ _` | | | '_ \
|
|
6
|
+
# | < (_) | | | | (_| | (_| | | | |_) |
|
|
7
|
+
# |_|\_\___/|_| |_|\__, |\__,_|_|_|_.__/
|
|
8
|
+
# __/ |
|
|
9
|
+
# |___/
|
|
10
|
+
#
|
|
11
|
+
# Konga client library, by EasyByte Software
|
|
12
|
+
#
|
|
13
|
+
# https://github.com/easybyte-software/kongalib
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from __future__ import print_function
|
|
17
|
+
|
|
18
|
+
from kongalib import JSONEncoder, JSONDecoder, Decimal
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Encoder(JSONEncoder):
|
|
23
|
+
def encode(self, obj):
|
|
24
|
+
self.reset()
|
|
25
|
+
self.write(obj)
|
|
26
|
+
return bytes(self.generate())
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Decoder(JSONDecoder):
|
|
30
|
+
def save_object(self, obj):
|
|
31
|
+
top, key = self.stack[-1]
|
|
32
|
+
if isinstance(top, list):
|
|
33
|
+
top.append(obj)
|
|
34
|
+
elif isinstance(top, dict):
|
|
35
|
+
top[key] = obj
|
|
36
|
+
else:
|
|
37
|
+
return True
|
|
38
|
+
|
|
39
|
+
def start_map(self):
|
|
40
|
+
obj = {}
|
|
41
|
+
self.save_object(obj)
|
|
42
|
+
self.stack.append([obj, None])
|
|
43
|
+
|
|
44
|
+
def end_map(self):
|
|
45
|
+
self.top = self.stack.pop()
|
|
46
|
+
|
|
47
|
+
def read_key(self, key):
|
|
48
|
+
self.stack[-1][1] = key
|
|
49
|
+
|
|
50
|
+
def start_array(self):
|
|
51
|
+
obj = []
|
|
52
|
+
self.save_object(obj)
|
|
53
|
+
self.stack.append([obj, None])
|
|
54
|
+
|
|
55
|
+
def end_array(self):
|
|
56
|
+
self.top = self.stack.pop()
|
|
57
|
+
|
|
58
|
+
def read(self, obj):
|
|
59
|
+
if self.save_object(obj):
|
|
60
|
+
self.stack.append([obj, None])
|
|
61
|
+
|
|
62
|
+
def decode(self, text):
|
|
63
|
+
self.stack = [ [None, None] ]
|
|
64
|
+
self.top = None
|
|
65
|
+
|
|
66
|
+
if isinstance(text, (str, bytes)):
|
|
67
|
+
self.parse(text)
|
|
68
|
+
else:
|
|
69
|
+
while True:
|
|
70
|
+
data = text.read(65536)
|
|
71
|
+
if not data:
|
|
72
|
+
break
|
|
73
|
+
self.parse(data)
|
|
74
|
+
self.complete_parse()
|
|
75
|
+
|
|
76
|
+
if len(self.stack) <= 1:
|
|
77
|
+
obj = self.top[0]
|
|
78
|
+
else:
|
|
79
|
+
obj = self.stack[1][0]
|
|
80
|
+
del self.stack
|
|
81
|
+
return obj
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def dumps(obj, encoding='utf-8', pretty=True):
|
|
85
|
+
return Encoder(encoding, pretty).encode(obj)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def dump(obj, fp, encoding='utf-8'):
|
|
89
|
+
fp.write(dumps(obj, encoding))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def loads(text, encoding='utf-8'):
|
|
93
|
+
return Decoder(encoding).decode(text)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
load = loads
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
if __name__ == '__main__':
|
|
101
|
+
from pprint import pprint
|
|
102
|
+
data = { 'a': 1, 'b': [ 1,2,3, { 'c': { 'd': [4,5,6]}} ], 'e': {'f': None}, 'g': Decimal("12.345678"), 'h': [ { 'h1': 1, 'h2': [ 1,2] }, { 'h3': 3, 'h4': [3,4,5] } ] }
|
|
103
|
+
|
|
104
|
+
saved = dumps(data)
|
|
105
|
+
print("SAVED:")
|
|
106
|
+
print(saved)
|
|
107
|
+
|
|
108
|
+
loaded = loads(saved)
|
|
109
|
+
print("LOADED:")
|
|
110
|
+
pprint(loaded)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|