-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.py
63 lines (45 loc) · 1.2 KB
/
schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# --- custom decorators
'''
Serializable JSON attribute
'''
def json(cls = None, /, *, array = True, single = False):
def _process_json(cls, array):
cls.is_array = array
cls.is_single = single
return cls
def wrap(cls):
return _process_json(cls, array)
if cls is None:
return wrap
return wrap(cls)
'''
Serializable JSON with a base group
'''
def keyjson(cls: object = None, /, *, key_group: str, array = True, single = False):
def _wrap(cls: object):
cls.key_group = key_group
return json(cls, array = array, single = single)
if cls is None:
return _wrap
return _wrap(cls)
'''
A configurable file
'''
def configurable(cls: object = None, /, *, filename: str):
def _process_cfg(cls: object, filename: str) -> object:
cls.configure_name = filename
return cls
def wrap(cls: object):
return _process_cfg(cls, filename)
if cls is None:
return wrap
return wrap(cls)
# --- custom types, only useful for names
class strbool(type):
pass
class long(type):
pass
class intbool(type):
pass
class datetimeunix(type):
pass