jaseci 1.4.2.5__py3-none-any.whl → 2.0.0__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 jaseci might be problematic. Click here for more details.
- jaseci/__init__.py +3 -37
- jaseci-2.0.0.dist-info/METADATA +65 -0
- jaseci-2.0.0.dist-info/RECORD +4 -0
- {jaseci-1.4.2.5.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
- jaseci/VERSION +0 -1
- jaseci/cli_tools/__init__.py +0 -0
- jaseci/cli_tools/book_tools.py +0 -457
- jaseci/cli_tools/jsctl.py +0 -500
- jaseci/cli_tools/tests/__init__.py +0 -0
- jaseci/cli_tools/tests/test_jsctl.py +0 -556
- jaseci/extens/__init__.py +0 -0
- jaseci/extens/act_lib/__init__.py +0 -0
- jaseci/extens/act_lib/date.py +0 -117
- jaseci/extens/act_lib/elastic.py +0 -87
- jaseci/extens/act_lib/file.py +0 -76
- jaseci/extens/act_lib/file_handler.py +0 -189
- jaseci/extens/act_lib/internal.py +0 -18
- jaseci/extens/act_lib/jaseci.py +0 -61
- jaseci/extens/act_lib/mail.py +0 -10
- jaseci/extens/act_lib/maths.py +0 -168
- jaseci/extens/act_lib/net.py +0 -191
- jaseci/extens/act_lib/rand.py +0 -82
- jaseci/extens/act_lib/regex.py +0 -85
- jaseci/extens/act_lib/request.py +0 -169
- jaseci/extens/act_lib/std.py +0 -235
- jaseci/extens/act_lib/storage.py +0 -53
- jaseci/extens/act_lib/stripe.py +0 -337
- jaseci/extens/act_lib/task.py +0 -13
- jaseci/extens/act_lib/tests/__init__.py +0 -0
- jaseci/extens/act_lib/tests/std_test_code.py +0 -37
- jaseci/extens/act_lib/tests/test_date.py +0 -26
- jaseci/extens/act_lib/tests/test_elastic.py +0 -159
- jaseci/extens/act_lib/tests/test_file.py +0 -116
- jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
- jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
- jaseci/extens/act_lib/tests/test_maths.py +0 -147
- jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
- jaseci/extens/act_lib/tests/test_regex.py +0 -61
- jaseci/extens/act_lib/tests/test_std.py +0 -51
- jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
- jaseci/extens/act_lib/tests/test_url.py +0 -32
- jaseci/extens/act_lib/tests/test_vector.py +0 -36
- jaseci/extens/act_lib/tests/test_webtool.py +0 -44
- jaseci/extens/act_lib/tests/test_zlib.py +0 -24
- jaseci/extens/act_lib/url.py +0 -79
- jaseci/extens/act_lib/vector.py +0 -157
- jaseci/extens/act_lib/webtool.py +0 -28
- jaseci/extens/act_lib/zip.py +0 -33
- jaseci/extens/api/__init__.py +0 -0
- jaseci/extens/api/actions_api.py +0 -170
- jaseci/extens/api/alias_api.py +0 -139
- jaseci/extens/api/architype_api.py +0 -196
- jaseci/extens/api/config_api.py +0 -129
- jaseci/extens/api/global_api.py +0 -84
- jaseci/extens/api/graph_api.py +0 -167
- jaseci/extens/api/health_api.py +0 -20
- jaseci/extens/api/interface.py +0 -268
- jaseci/extens/api/jac_api.py +0 -171
- jaseci/extens/api/jsorc_api.py +0 -316
- jaseci/extens/api/logger_api.py +0 -89
- jaseci/extens/api/master_api.py +0 -133
- jaseci/extens/api/object_api.py +0 -101
- jaseci/extens/api/prometheus_api.py +0 -74
- jaseci/extens/api/queue_api.py +0 -140
- jaseci/extens/api/sentinel_api.py +0 -270
- jaseci/extens/api/super_api.py +0 -64
- jaseci/extens/api/tests/__init__.py +0 -0
- jaseci/extens/api/tests/test_architype_api.py +0 -66
- jaseci/extens/api/tests/test_global_api.py +0 -179
- jaseci/extens/api/tests/test_graph_api.py +0 -64
- jaseci/extens/api/tests/test_logger_api.py +0 -43
- jaseci/extens/api/tests/test_object_api.py +0 -20
- jaseci/extens/api/tests/test_sentinel_api.py +0 -66
- jaseci/extens/api/tests/test_uncommon.py +0 -107
- jaseci/extens/api/tests/test_user_api.py +0 -32
- jaseci/extens/api/tests/test_walker_api.py +0 -316
- jaseci/extens/api/user_api.py +0 -144
- jaseci/extens/api/walker_api.py +0 -298
- jaseci/extens/api/webhook_api.py +0 -74
- jaseci/extens/svc/__init__.py +0 -0
- jaseci/extens/svc/elastic_svc.py +0 -366
- jaseci/extens/svc/kube_svc.py +0 -432
- jaseci/extens/svc/mail_svc.py +0 -156
- jaseci/extens/svc/prome_svc.py +0 -378
- jaseci/extens/svc/redis_svc.py +0 -63
- jaseci/extens/svc/storage_svc.py +0 -193
- jaseci/extens/svc/stripe_svc.py +0 -51
- jaseci/extens/svc/task_svc.py +0 -155
- jaseci/extens/svc/tasks.py +0 -302
- jaseci/jac/__init__.py +0 -0
- jaseci/jac/interpreter/__init__.py +0 -0
- jaseci/jac/interpreter/architype_interp.py +0 -214
- jaseci/jac/interpreter/interp.py +0 -1783
- jaseci/jac/interpreter/sentinel_interp.py +0 -257
- jaseci/jac/interpreter/tests/__init__.py +0 -0
- jaseci/jac/interpreter/tests/test_interp.py +0 -42
- jaseci/jac/interpreter/walker_interp.py +0 -248
- jaseci/jac/ir/__init__.py +0 -0
- jaseci/jac/ir/ast.py +0 -73
- jaseci/jac/ir/ast_builder.py +0 -249
- jaseci/jac/ir/jac_code.py +0 -152
- jaseci/jac/ir/passes/__init__.py +0 -6
- jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
- jaseci/jac/ir/passes/codegen_pass.py +0 -244
- jaseci/jac/ir/passes/ir_pass.py +0 -29
- jaseci/jac/ir/passes/printer_pass.py +0 -23
- jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
- jaseci/jac/ir/passes/schedule.py +0 -23
- jaseci/jac/ir/passes/stats_pass.py +0 -16
- jaseci/jac/jac.g4 +0 -450
- jaseci/jac/jac_parse/__init__.py +0 -0
- jaseci/jac/jac_parse/jacLexer.py +0 -809
- jaseci/jac/jac_parse/jacListener.py +0 -853
- jaseci/jac/jac_parse/jacParser.py +0 -9192
- jaseci/jac/jac_set.py +0 -119
- jaseci/jac/jsci_vm/__init__.py +0 -0
- jaseci/jac/jsci_vm/disasm.py +0 -94
- jaseci/jac/jsci_vm/inst_ptr.py +0 -31
- jaseci/jac/jsci_vm/machine.py +0 -188
- jaseci/jac/jsci_vm/op_codes.py +0 -82
- jaseci/jac/jsci_vm/tests/__init__.py +0 -0
- jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
- jaseci/jac/machine/__init__.py +0 -0
- jaseci/jac/machine/jac_scope.py +0 -85
- jaseci/jac/machine/jac_value.py +0 -226
- jaseci/jac/machine/machine_state.py +0 -383
- jaseci/jac/tests/__init__.py +0 -0
- jaseci/jac/tests/book_code.py +0 -624
- jaseci/jac/tests/test_book.py +0 -380
- jaseci/jac/tests/test_lang_14.py +0 -49
- jaseci/jsorc/__init__.py +0 -7
- jaseci/jsorc/jsorc.py +0 -642
- jaseci/jsorc/jsorc_settings.py +0 -211
- jaseci/jsorc/jsorc_utils.py +0 -298
- jaseci/jsorc/live_actions.py +0 -364
- jaseci/jsorc/manifests/__init__.py +0 -0
- jaseci/jsorc/manifests/database.yaml +0 -109
- jaseci/jsorc/manifests/elastic.yaml +0 -6024
- jaseci/jsorc/manifests/prometheus.yaml +0 -1383
- jaseci/jsorc/manifests/redis.yaml +0 -64
- jaseci/jsorc/memory.py +0 -258
- jaseci/jsorc/redis.py +0 -139
- jaseci/jsorc/remote_actions.py +0 -157
- jaseci/jsorc/tests/__init__.py +0 -0
- jaseci/jsorc/tests/test_actions.py +0 -542
- jaseci/jsorc/tests/test_jsorc.py +0 -112
- jaseci/prim/__init__.py +0 -0
- jaseci/prim/ability.py +0 -93
- jaseci/prim/architype.py +0 -89
- jaseci/prim/edge.py +0 -172
- jaseci/prim/element.py +0 -233
- jaseci/prim/graph.py +0 -26
- jaseci/prim/master.py +0 -64
- jaseci/prim/node.py +0 -532
- jaseci/prim/obj_mixins.py +0 -235
- jaseci/prim/sentinel.py +0 -281
- jaseci/prim/super_master.py +0 -31
- jaseci/prim/walker.py +0 -261
- jaseci/svc/__init__.py +0 -0
- jaseci/tests/__init__.py +0 -0
- jaseci/tests/infer.py +0 -39
- jaseci/tests/jac_test_code.py +0 -1293
- jaseci/tests/jac_test_progs.py +0 -774
- jaseci/tests/test_core.py +0 -153
- jaseci/tests/test_jac.py +0 -824
- jaseci/tests/test_node.py +0 -89
- jaseci/tests/test_progs.py +0 -702
- jaseci/tests/test_stack.py +0 -220
- jaseci/tests/test_stripe.py +0 -225
- jaseci/utils/__init__.py +0 -0
- jaseci/utils/actions/__init__.py +0 -0
- jaseci/utils/actions/actions_manager.py +0 -254
- jaseci/utils/actions/actions_optimizer.py +0 -516
- jaseci/utils/actions/actions_state.py +0 -95
- jaseci/utils/file_handler.py +0 -171
- jaseci/utils/gprof2dot.py +0 -3786
- jaseci/utils/id_list.py +0 -168
- jaseci/utils/json_handler.py +0 -70
- jaseci/utils/log_utils.py +0 -57
- jaseci/utils/test_core.py +0 -62
- jaseci/utils/utils.py +0 -387
- jaseci-1.4.2.5.dist-info/LICENSE +0 -21
- jaseci-1.4.2.5.dist-info/METADATA +0 -39
- jaseci-1.4.2.5.dist-info/RECORD +0 -184
- jaseci-1.4.2.5.dist-info/entry_points.txt +0 -3
- jaseci-1.4.2.5.dist-info/top_level.txt +0 -1
jaseci/extens/svc/task_svc.py
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
from celery import Celery
|
|
2
|
-
from celery.schedules import crontab
|
|
3
|
-
from celery.app.trace import build_tracer
|
|
4
|
-
from celery.app.control import Inspect
|
|
5
|
-
from celery.backends.base import DisabledBackend
|
|
6
|
-
|
|
7
|
-
from jaseci.jsorc.jsorc import JsOrc
|
|
8
|
-
from jaseci.jsorc.jsorc_utils import ManifestType
|
|
9
|
-
from .tasks import Queue, ScheduledWalker, ScheduledSequence
|
|
10
|
-
|
|
11
|
-
#################################################
|
|
12
|
-
# TASK APP #
|
|
13
|
-
#################################################
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@JsOrc.service(name="task", config="TASK_CONFIG")
|
|
17
|
-
class TaskService(JsOrc.CommonService):
|
|
18
|
-
###################################################
|
|
19
|
-
# INITIALIZER #
|
|
20
|
-
###################################################
|
|
21
|
-
|
|
22
|
-
def __init__(
|
|
23
|
-
self,
|
|
24
|
-
config: dict,
|
|
25
|
-
manifest: dict,
|
|
26
|
-
manifest_type: ManifestType = ManifestType.DEDICATED,
|
|
27
|
-
source: dict = {},
|
|
28
|
-
):
|
|
29
|
-
self.inspect: Inspect = None
|
|
30
|
-
self.queue: Queue = None
|
|
31
|
-
self.scheduled_walker: ScheduledWalker = None
|
|
32
|
-
self.scheduled_sequence: ScheduledSequence = None
|
|
33
|
-
|
|
34
|
-
super().__init__(config, manifest, manifest_type, source)
|
|
35
|
-
|
|
36
|
-
###################################################
|
|
37
|
-
# BUILDER #
|
|
38
|
-
###################################################
|
|
39
|
-
|
|
40
|
-
def run(self):
|
|
41
|
-
self.app = Celery("celery")
|
|
42
|
-
self.app.conf.update(**self.config)
|
|
43
|
-
|
|
44
|
-
# -------------------- TASKS -------------------- #
|
|
45
|
-
(
|
|
46
|
-
self.queue,
|
|
47
|
-
self.scheduled_walker,
|
|
48
|
-
self.scheduled_sequence,
|
|
49
|
-
) = self.register_tasks(Queue, ScheduledWalker, ScheduledSequence)
|
|
50
|
-
|
|
51
|
-
# ------------------ INSPECTOR ------------------ #
|
|
52
|
-
|
|
53
|
-
self.inspect = self.app.control.inspect()
|
|
54
|
-
self.ping()
|
|
55
|
-
|
|
56
|
-
def post_run(self):
|
|
57
|
-
self.spawn_daemon(
|
|
58
|
-
worker=self.app.Worker(quiet=self.quiet).start,
|
|
59
|
-
scheduler=self.app.Beat(socket_timeout=None, quiet=self.quiet).run,
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
def register_tasks(self, *tasks) -> tuple:
|
|
63
|
-
registered = []
|
|
64
|
-
for task in tasks:
|
|
65
|
-
task = self.app.register_task(task())
|
|
66
|
-
task.__trace__ = build_tracer(task.name, task, app=self.app)
|
|
67
|
-
registered.append(task)
|
|
68
|
-
return tuple(registered)
|
|
69
|
-
|
|
70
|
-
###################################################
|
|
71
|
-
# COMMON GETTER/SETTER #
|
|
72
|
-
###################################################
|
|
73
|
-
|
|
74
|
-
def get_by_task_id(self, task_id, wait=False, timeout=30):
|
|
75
|
-
task = self.app.AsyncResult(task_id)
|
|
76
|
-
|
|
77
|
-
if isinstance(task.backend, DisabledBackend):
|
|
78
|
-
return {
|
|
79
|
-
"status": "DISABLED",
|
|
80
|
-
"result": "result_backend is set to disabled!",
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
ret = {"status": task.state}
|
|
84
|
-
if task.ready():
|
|
85
|
-
ret["result"] = task.result
|
|
86
|
-
elif wait:
|
|
87
|
-
ret["status"] = "SUCCESS"
|
|
88
|
-
ret["result"] = task.get(timeout=timeout, disable_sync_subtasks=False)
|
|
89
|
-
|
|
90
|
-
return ret
|
|
91
|
-
|
|
92
|
-
def inspect_tasks(self):
|
|
93
|
-
return {
|
|
94
|
-
"scheduled": self.inspect.scheduled(),
|
|
95
|
-
"active": self.inspect.active(),
|
|
96
|
-
"reserved": self.inspect.reserved(),
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
def ping(self): # will throw exception
|
|
100
|
-
self.inspect.ping()
|
|
101
|
-
self.app.AsyncResult("").result
|
|
102
|
-
|
|
103
|
-
###################################################
|
|
104
|
-
# QUEUING #
|
|
105
|
-
###################################################
|
|
106
|
-
|
|
107
|
-
def add_queue(self, wlk, nd, *args):
|
|
108
|
-
return self.queue.delay(wlk.jid, nd.jid, args).task_id
|
|
109
|
-
|
|
110
|
-
###################################################
|
|
111
|
-
# SCHEDULED QUEUING #
|
|
112
|
-
###################################################
|
|
113
|
-
|
|
114
|
-
def add_scheduled_queue(
|
|
115
|
-
self, queue_type: object, name: str, schedule: dict, body: dict
|
|
116
|
-
):
|
|
117
|
-
return None
|
|
118
|
-
|
|
119
|
-
def get_scheduled_queues(
|
|
120
|
-
self,
|
|
121
|
-
limit: int = 10,
|
|
122
|
-
offset: int = 0,
|
|
123
|
-
asc: bool = True,
|
|
124
|
-
name: str = None,
|
|
125
|
-
master=False,
|
|
126
|
-
):
|
|
127
|
-
return []
|
|
128
|
-
|
|
129
|
-
def delete_scheduled_queue(self, scheduled_queue_id: int, master):
|
|
130
|
-
return None
|
|
131
|
-
|
|
132
|
-
###################################################
|
|
133
|
-
# CLEANER #
|
|
134
|
-
###################################################
|
|
135
|
-
|
|
136
|
-
def failed(self, error):
|
|
137
|
-
super().failed(error)
|
|
138
|
-
self.terminate_daemon("worker", "scheduler")
|
|
139
|
-
|
|
140
|
-
# ---------------- PROXY EVENTS ----------------- #
|
|
141
|
-
|
|
142
|
-
def on_delete(self):
|
|
143
|
-
self.terminate_daemon("worker", "scheduler")
|
|
144
|
-
|
|
145
|
-
###################################################
|
|
146
|
-
# UTILS #
|
|
147
|
-
###################################################
|
|
148
|
-
|
|
149
|
-
def get_task_name(self, task):
|
|
150
|
-
cls = type(task)
|
|
151
|
-
module = cls.__module__
|
|
152
|
-
name = cls.__qualname__
|
|
153
|
-
if module is not None and module != "__builtin__":
|
|
154
|
-
name = module + "." + name
|
|
155
|
-
return name
|
jaseci/extens/svc/tasks.py
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
from copy import deepcopy
|
|
3
|
-
from typing import Tuple
|
|
4
|
-
|
|
5
|
-
from celery import Task
|
|
6
|
-
from requests import get, post
|
|
7
|
-
from requests.exceptions import HTTPError
|
|
8
|
-
from jaseci.jsorc.jsorc import JsOrc
|
|
9
|
-
|
|
10
|
-
DEFAULT_MSG = "Skipping scheduled walker!"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class Queue(Task):
|
|
14
|
-
def run(self, wlk: str, nd: str, args):
|
|
15
|
-
hook = JsOrc.hook()
|
|
16
|
-
|
|
17
|
-
wlk = hook.get_obj_from_store(wlk)
|
|
18
|
-
wlk._to_await = True
|
|
19
|
-
|
|
20
|
-
nd = hook.get_obj_from_store(nd)
|
|
21
|
-
resp = wlk.run(nd, *args)
|
|
22
|
-
|
|
23
|
-
# commit to cache first then db instead of `commit()` only
|
|
24
|
-
# this is to support both jsctl and jsserv
|
|
25
|
-
wlk._h.commit_all_cache_sync()
|
|
26
|
-
wlk._h.commit(True)
|
|
27
|
-
|
|
28
|
-
wlk.destroy()
|
|
29
|
-
|
|
30
|
-
return {"anchor": wlk.anchor_value(), "response": resp}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class ScheduledWalker(Task):
|
|
34
|
-
def get_obj(self, jid):
|
|
35
|
-
return self.hook.get_obj_from_store(jid)
|
|
36
|
-
|
|
37
|
-
def run(self, mst, wlk="init", ctx: dict = {}, nd: str = None, snt: str = None):
|
|
38
|
-
self.hook = JsOrc.hook()
|
|
39
|
-
|
|
40
|
-
if mst:
|
|
41
|
-
mst = self.get_obj(mst)
|
|
42
|
-
else:
|
|
43
|
-
return f"{DEFAULT_MSG} mst (Master) is required!"
|
|
44
|
-
|
|
45
|
-
if mst is None:
|
|
46
|
-
return f"{DEFAULT_MSG} Invalid Master!"
|
|
47
|
-
|
|
48
|
-
try:
|
|
49
|
-
if not snt:
|
|
50
|
-
if mst.active_snt_id == "global":
|
|
51
|
-
global_snt_id = self.hook.get_glob("GLOB_SENTINEL")
|
|
52
|
-
snt = self.get_obj(global_snt_id)
|
|
53
|
-
elif mst.active_snt_id:
|
|
54
|
-
snt = self.get_obj(mst.active_snt_id)
|
|
55
|
-
elif snt in mst.alias_map:
|
|
56
|
-
snt = self.get_obj(mst.alias_map[snt])
|
|
57
|
-
else:
|
|
58
|
-
snt = self.get_obj(snt)
|
|
59
|
-
|
|
60
|
-
if not snt:
|
|
61
|
-
return f"{DEFAULT_MSG} Invalid Sentinel!"
|
|
62
|
-
|
|
63
|
-
if not nd:
|
|
64
|
-
if mst.active_gph_id:
|
|
65
|
-
nd = self.get_obj(mst.active_gph_id)
|
|
66
|
-
elif nd in mst.alias_map:
|
|
67
|
-
nd = self.get_obj(mst.alias_map[nd])
|
|
68
|
-
else:
|
|
69
|
-
nd = self.get_obj(nd)
|
|
70
|
-
|
|
71
|
-
if not nd:
|
|
72
|
-
return f"{DEFAULT_MSG} Invalid Node!"
|
|
73
|
-
|
|
74
|
-
resp = mst.walker_run(wlk, nd, ctx, ctx, snt, False, False)
|
|
75
|
-
|
|
76
|
-
mst._h.commit_all_cache_sync()
|
|
77
|
-
mst._h.commit(True)
|
|
78
|
-
|
|
79
|
-
return resp
|
|
80
|
-
except Exception as e:
|
|
81
|
-
return f"{DEFAULT_MSG} Error occured: {e}"
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
class ScheduledSequence(Task):
|
|
85
|
-
json_escape = re.compile(r"[^a-zA-Z0-9_]")
|
|
86
|
-
internal = re.compile(r"\(([a-zA-Z0-9_\.\[\]\$\#\@\!]*?)\)")
|
|
87
|
-
full = re.compile(r"^\{\{([a-zA-Z0-9_\.\[\]\$\#\(\)\@\!]*?)\}\}$")
|
|
88
|
-
partial = re.compile(r"\{\{([a-zA-Z0-9_\.\[\]\$\#\(\)\@\!]*?)\}\}")
|
|
89
|
-
|
|
90
|
-
def get_deep_value(self, data, keys, default):
|
|
91
|
-
if len(keys) == 0:
|
|
92
|
-
return data
|
|
93
|
-
|
|
94
|
-
key = keys.pop(0)
|
|
95
|
-
t = type(data)
|
|
96
|
-
|
|
97
|
-
if t is dict and key in data:
|
|
98
|
-
return self.get_deep_value(data[key], keys, default)
|
|
99
|
-
elif t is list and key.isnumeric():
|
|
100
|
-
return self.get_deep_value(data[int(key)], keys, default)
|
|
101
|
-
else:
|
|
102
|
-
return default
|
|
103
|
-
|
|
104
|
-
def get_value(self, holder: Tuple, keys: str, default=None):
|
|
105
|
-
while self.internal.search(keys):
|
|
106
|
-
for intern in self.internal.findall(keys):
|
|
107
|
-
keys = keys.replace(
|
|
108
|
-
"(" + intern + ")", self.get_value(holder, intern, "")
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
if keys:
|
|
112
|
-
keys = keys.split(".")
|
|
113
|
-
key = keys.pop(0)
|
|
114
|
-
if key == "#":
|
|
115
|
-
return self.get_deep_value(holder[0], keys, default)
|
|
116
|
-
elif key == "$":
|
|
117
|
-
t = type(holder[1])
|
|
118
|
-
if t is dict or t is list:
|
|
119
|
-
return self.get_deep_value(holder[1], keys, default)
|
|
120
|
-
else:
|
|
121
|
-
return holder[1]
|
|
122
|
-
elif key == "@":
|
|
123
|
-
t = type(holder[2])
|
|
124
|
-
if t is dict or t is list:
|
|
125
|
-
return self.get_deep_value(holder[2], keys, default)
|
|
126
|
-
else:
|
|
127
|
-
return holder[2]
|
|
128
|
-
elif key == "!":
|
|
129
|
-
return holder[3]
|
|
130
|
-
return default
|
|
131
|
-
|
|
132
|
-
def compare(self, condition, expected, actual):
|
|
133
|
-
if condition == "eq":
|
|
134
|
-
return actual == expected
|
|
135
|
-
elif condition == "ne":
|
|
136
|
-
return actual != expected
|
|
137
|
-
elif condition == "gt":
|
|
138
|
-
return actual > expected
|
|
139
|
-
elif condition == "gte":
|
|
140
|
-
return actual >= expected
|
|
141
|
-
elif condition == "lt":
|
|
142
|
-
return actual < expected
|
|
143
|
-
elif condition == "lte":
|
|
144
|
-
return actual <= expected
|
|
145
|
-
elif condition == "regex":
|
|
146
|
-
return re.compile(expected).match(actual)
|
|
147
|
-
|
|
148
|
-
def condition(self, holder: Tuple, filter):
|
|
149
|
-
for cons in filter["condition"].keys():
|
|
150
|
-
if not (filter["condition"][cons] is None) and not self.compare(
|
|
151
|
-
cons, filter["condition"][cons], self.get_value(holder, filter["by"])
|
|
152
|
-
):
|
|
153
|
-
return False
|
|
154
|
-
return True
|
|
155
|
-
|
|
156
|
-
def or_condition(self, holder: Tuple, filter):
|
|
157
|
-
for filt in filter:
|
|
158
|
-
if "condition" in filt and self.condition(holder, filt):
|
|
159
|
-
return True
|
|
160
|
-
elif "or" in filt and self.or_condition(holder, filt["or"]):
|
|
161
|
-
return True
|
|
162
|
-
elif "and" in filt and self.and_condition(holder, filt["and"]):
|
|
163
|
-
return True
|
|
164
|
-
return False
|
|
165
|
-
|
|
166
|
-
def and_condition(self, holder: Tuple, filter):
|
|
167
|
-
for filt in filter:
|
|
168
|
-
if "condition" in filt and not self.condition(holder, filt):
|
|
169
|
-
return False
|
|
170
|
-
elif "or" in filt and not self.or_condition(holder, filt["or"]):
|
|
171
|
-
return False
|
|
172
|
-
elif "and" in filt and not self.and_condition(holder, filt["and"]):
|
|
173
|
-
return False
|
|
174
|
-
return True
|
|
175
|
-
|
|
176
|
-
def deep_replace_str(self, holder: Tuple, data, key):
|
|
177
|
-
matcher = self.full.match(data[key])
|
|
178
|
-
if matcher:
|
|
179
|
-
data[key] = self.get_value(holder, matcher.group(1))
|
|
180
|
-
else:
|
|
181
|
-
for rep in self.partial.findall(data[key]):
|
|
182
|
-
data[key] = data[key].replace(
|
|
183
|
-
"{{" + rep + "}}", self.get_value(holder, rep, "")
|
|
184
|
-
)
|
|
185
|
-
|
|
186
|
-
def deep_replace_dict(self, holder: Tuple, data):
|
|
187
|
-
for key in data.keys():
|
|
188
|
-
if key != "__def_loop__":
|
|
189
|
-
t = type(data[key])
|
|
190
|
-
if t is str:
|
|
191
|
-
self.deep_replace_str(holder, data, key)
|
|
192
|
-
elif t is dict:
|
|
193
|
-
self.deep_replace_dict(holder, data[key])
|
|
194
|
-
|
|
195
|
-
def save(self, holder: Tuple, req, params):
|
|
196
|
-
if params in req:
|
|
197
|
-
holder[0][self.json_escape.sub("_", req[params])] = holder[1]
|
|
198
|
-
|
|
199
|
-
def trigger_interface(self, req: dict):
|
|
200
|
-
master = req.get("master")
|
|
201
|
-
if master is None:
|
|
202
|
-
caller = JsOrc.master()
|
|
203
|
-
trigger_type = "public"
|
|
204
|
-
else:
|
|
205
|
-
caller = JsOrc.hook().get_obj_from_store(master)
|
|
206
|
-
trigger_type = "general"
|
|
207
|
-
|
|
208
|
-
api = req.get("api")
|
|
209
|
-
body = req.get("body", {})
|
|
210
|
-
resp = getattr(caller, f"{trigger_type}_interface_to_api")(body, api)
|
|
211
|
-
|
|
212
|
-
caller._h.commit_all_cache_sync()
|
|
213
|
-
caller._h.commit(True)
|
|
214
|
-
|
|
215
|
-
return resp
|
|
216
|
-
|
|
217
|
-
def run(self, **kwargs):
|
|
218
|
-
requests = kwargs.get("requests")
|
|
219
|
-
persistence = kwargs.get("persistence", {})
|
|
220
|
-
container = kwargs.get("container", {"current": persistence})
|
|
221
|
-
index = container.get("index", "0")
|
|
222
|
-
|
|
223
|
-
if "parent_current" in container:
|
|
224
|
-
container["current"] = container["parent_current"]
|
|
225
|
-
|
|
226
|
-
for req in requests:
|
|
227
|
-
try:
|
|
228
|
-
self.deep_replace_dict(
|
|
229
|
-
(
|
|
230
|
-
persistence,
|
|
231
|
-
container["current"],
|
|
232
|
-
container.get("parent_current", {}),
|
|
233
|
-
index,
|
|
234
|
-
),
|
|
235
|
-
req,
|
|
236
|
-
)
|
|
237
|
-
self.save((persistence, req), req, "save_req_to")
|
|
238
|
-
|
|
239
|
-
method = req["method"].upper()
|
|
240
|
-
|
|
241
|
-
if method == "JAC":
|
|
242
|
-
container["current"] = self.trigger_interface(req)
|
|
243
|
-
else:
|
|
244
|
-
if method == "POST":
|
|
245
|
-
response = post(
|
|
246
|
-
req["api"],
|
|
247
|
-
json=req.get("body", {}),
|
|
248
|
-
headers=req.get("header", {}),
|
|
249
|
-
)
|
|
250
|
-
elif method == "GET":
|
|
251
|
-
response = get(req["api"], headers=req.get("header", {}))
|
|
252
|
-
response.raise_for_status()
|
|
253
|
-
if "application/json" in response.headers.get("Content-Type"):
|
|
254
|
-
container["current"] = response.json()
|
|
255
|
-
else:
|
|
256
|
-
container["current"] = response.text
|
|
257
|
-
|
|
258
|
-
if "__def_loop__" in req:
|
|
259
|
-
def_loop = req["__def_loop__"]
|
|
260
|
-
for idx, loop in enumerate(
|
|
261
|
-
self.get_value(
|
|
262
|
-
(persistence, container["current"]), def_loop["by"], []
|
|
263
|
-
)
|
|
264
|
-
):
|
|
265
|
-
if "filter" in def_loop and not self.and_condition(
|
|
266
|
-
(persistence, loop), def_loop["filter"]
|
|
267
|
-
):
|
|
268
|
-
continue
|
|
269
|
-
loop_container = {"parent_current": loop, "index": str(idx)}
|
|
270
|
-
self.run(
|
|
271
|
-
requests=deepcopy(def_loop["requests"]),
|
|
272
|
-
persistence=persistence,
|
|
273
|
-
container=loop_container,
|
|
274
|
-
)
|
|
275
|
-
|
|
276
|
-
self.save((persistence, container["current"]), req, "save_to")
|
|
277
|
-
|
|
278
|
-
except Exception as err:
|
|
279
|
-
container["current"] = (
|
|
280
|
-
{
|
|
281
|
-
"status": err.response.status_code,
|
|
282
|
-
"message": err.response.reason,
|
|
283
|
-
}
|
|
284
|
-
if isinstance(err, HTTPError)
|
|
285
|
-
else {
|
|
286
|
-
"worker_error": str(err),
|
|
287
|
-
}
|
|
288
|
-
)
|
|
289
|
-
|
|
290
|
-
self.save((persistence, container["current"]), req, "save_to")
|
|
291
|
-
|
|
292
|
-
if "ignore_error" not in req or not req["ignore_error"]:
|
|
293
|
-
if "parent_current" in container:
|
|
294
|
-
raise err
|
|
295
|
-
break
|
|
296
|
-
|
|
297
|
-
if "break" in req and self.and_condition(
|
|
298
|
-
(persistence, container["current"]), req["break"]
|
|
299
|
-
):
|
|
300
|
-
break
|
|
301
|
-
|
|
302
|
-
return persistence
|
jaseci/jac/__init__.py
DELETED
|
File without changes
|
|
File without changes
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Sentinel interpreter for jac code in AST form
|
|
3
|
-
|
|
4
|
-
This interpreter should be inhereted from the class that manages state
|
|
5
|
-
referenced through self.
|
|
6
|
-
"""
|
|
7
|
-
from jaseci.prim.node import Node
|
|
8
|
-
from jaseci.prim.edge import Edge
|
|
9
|
-
from jaseci.prim.walker import Walker
|
|
10
|
-
from jaseci.jac.interpreter.interp import Interp
|
|
11
|
-
from jaseci.jac.machine.jac_scope import JacScope
|
|
12
|
-
from jaseci.jac.machine.jac_value import JacValue
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class ArchitypeInterp(Interp):
|
|
16
|
-
"""Jac interpreter mixin for objects that will execute Jac code"""
|
|
17
|
-
|
|
18
|
-
def run_architype(self, jac_ast):
|
|
19
|
-
"""
|
|
20
|
-
architype:
|
|
21
|
-
KW_NODE NAME (COLON NAME)* attr_block
|
|
22
|
-
| KW_EDGE NAME (COLON NAME)* attr_block
|
|
23
|
-
| KW_TYPE NAME struct_block
|
|
24
|
-
| KW_GRAPH NAME graph_block
|
|
25
|
-
| KW_ASYNC? KW_WALKER NAME namespaces? walker_block;
|
|
26
|
-
"""
|
|
27
|
-
if jac_ast is None: # Using defaults
|
|
28
|
-
if self.kind == "node" and self.name in ["root", "generic"]:
|
|
29
|
-
return Node(
|
|
30
|
-
m_id=self._m_id,
|
|
31
|
-
h=self._h,
|
|
32
|
-
kind=self.kind,
|
|
33
|
-
name=self.name,
|
|
34
|
-
parent=self.parent(),
|
|
35
|
-
)
|
|
36
|
-
elif self.kind == "edge" and self.name in ["generic"]:
|
|
37
|
-
return Edge(
|
|
38
|
-
m_id=self._m_id,
|
|
39
|
-
h=self._h,
|
|
40
|
-
kind=self.kind,
|
|
41
|
-
name=self.name,
|
|
42
|
-
parent=self.parent(),
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
kid = self.set_cur_ast(jac_ast)
|
|
46
|
-
|
|
47
|
-
self.push_scope(JacScope(parent=self, name=f"spawn:{jac_ast.loc_str()}"))
|
|
48
|
-
if kid[0].name == "KW_NODE":
|
|
49
|
-
item = Node(
|
|
50
|
-
m_id=self._m_id,
|
|
51
|
-
h=self._h,
|
|
52
|
-
kind=kid[0].token_text(),
|
|
53
|
-
name=kid[1].token_text(),
|
|
54
|
-
parent=self.parent(),
|
|
55
|
-
)
|
|
56
|
-
self.build_object_with_supers(item, kid[-1])
|
|
57
|
-
elif kid[0].name == "KW_EDGE":
|
|
58
|
-
item = Edge(
|
|
59
|
-
m_id=self._m_id,
|
|
60
|
-
h=self._h,
|
|
61
|
-
kind=kid[0].token_text(),
|
|
62
|
-
name=kid[1].token_text(),
|
|
63
|
-
parent=self.parent(),
|
|
64
|
-
)
|
|
65
|
-
self.build_object_with_supers(item, kid[-1])
|
|
66
|
-
elif kid[0].name == "KW_TYPE":
|
|
67
|
-
item = self.run_struct_block(kid[-1])
|
|
68
|
-
elif kid[0].name == "KW_GRAPH":
|
|
69
|
-
item = self.run_graph_block(kid[-1])
|
|
70
|
-
elif kid[0].name == "KW_WALKER":
|
|
71
|
-
item = Walker(
|
|
72
|
-
m_id=self._m_id,
|
|
73
|
-
h=self._h,
|
|
74
|
-
code_ir=jac_ast,
|
|
75
|
-
name=kid[1].token_text(),
|
|
76
|
-
kind=kid[0].token_text(),
|
|
77
|
-
parent=self.parent(),
|
|
78
|
-
is_async=self.is_async,
|
|
79
|
-
)
|
|
80
|
-
if kid[2].name == "namespaces":
|
|
81
|
-
item.namespaces = self.run_namespaces(jac_ast.kid[2])
|
|
82
|
-
self.build_object_with_supers(item, kid[-1])
|
|
83
|
-
elif jac_ast.name == "graph_block": # usedi n jac tests
|
|
84
|
-
item = self.run_graph_block(jac_ast)
|
|
85
|
-
self.pop_scope()
|
|
86
|
-
return item
|
|
87
|
-
|
|
88
|
-
def run_namespaces(self, jac_ast):
|
|
89
|
-
"""
|
|
90
|
-
namespaces: COLON name_list;
|
|
91
|
-
"""
|
|
92
|
-
return self.run_name_list(jac_ast.kid[1])
|
|
93
|
-
|
|
94
|
-
def run_walker_block(self, jac_ast, obj):
|
|
95
|
-
"""
|
|
96
|
-
walker_block:
|
|
97
|
-
LBRACE attr_stmt* walk_entry_block? (
|
|
98
|
-
statement
|
|
99
|
-
| walk_activity_block
|
|
100
|
-
)* walk_exit_block? RBRACE;
|
|
101
|
-
"""
|
|
102
|
-
kid = self.set_cur_ast(jac_ast)
|
|
103
|
-
for i in kid:
|
|
104
|
-
if i.name == "attr_stmt":
|
|
105
|
-
self.run_attr_stmt(jac_ast=i, obj=obj)
|
|
106
|
-
|
|
107
|
-
def run_attr_block(self, jac_ast, obj):
|
|
108
|
-
"""
|
|
109
|
-
attr_block:
|
|
110
|
-
LBRACE (attr_stmt)* RBRACE
|
|
111
|
-
| COLON (attr_stmt)* SEMI
|
|
112
|
-
| SEMI;
|
|
113
|
-
"""
|
|
114
|
-
kid = self.set_cur_ast(jac_ast)
|
|
115
|
-
for i in kid:
|
|
116
|
-
if i.name == "attr_stmt":
|
|
117
|
-
self.run_attr_stmt(i, obj)
|
|
118
|
-
|
|
119
|
-
def run_attr_stmt(self, jac_ast, obj):
|
|
120
|
-
"""
|
|
121
|
-
attr_stmt: has_stmt | can_stmt;
|
|
122
|
-
"""
|
|
123
|
-
kid = self.set_cur_ast(jac_ast)
|
|
124
|
-
if kid[0].name == "has_stmt":
|
|
125
|
-
self.run_has_stmt(kid[0], obj)
|
|
126
|
-
# Can statements in architype handled in architype load
|
|
127
|
-
|
|
128
|
-
def run_has_stmt(self, jac_ast, obj):
|
|
129
|
-
"""
|
|
130
|
-
has_stmt: KW_HAS has_assign (COMMA has_assign)* SEMI;
|
|
131
|
-
"""
|
|
132
|
-
kid = self.set_cur_ast(jac_ast)
|
|
133
|
-
for i in kid:
|
|
134
|
-
if i.name == "has_assign":
|
|
135
|
-
self.run_has_assign(i, obj)
|
|
136
|
-
|
|
137
|
-
def run_has_assign(self, jac_ast, obj):
|
|
138
|
-
"""
|
|
139
|
-
has_assign: KW_PRIVATE? KW_ANCHOR? (NAME | NAME EQ expression);
|
|
140
|
-
"""
|
|
141
|
-
kid = self.set_cur_ast(jac_ast)
|
|
142
|
-
while kid[0].name in ["KW_PRIVATE", "KW_ANCHOR"]:
|
|
143
|
-
kid = kid[1:]
|
|
144
|
-
var_name = kid[0].token_text()
|
|
145
|
-
var_val = None # jac's null
|
|
146
|
-
if len(kid) > 1:
|
|
147
|
-
self.run_expression(kid[2])
|
|
148
|
-
var_val = self.pop().value
|
|
149
|
-
if isinstance(obj, dict):
|
|
150
|
-
obj[var_name] = var_val
|
|
151
|
-
# Runs only once for walkers
|
|
152
|
-
elif var_name not in obj.context.keys() or obj.j_type != "walker":
|
|
153
|
-
JacValue(
|
|
154
|
-
self, ctx=obj, name=var_name, value=var_val, create_mode=True
|
|
155
|
-
).write(kid[0], force=True)
|
|
156
|
-
|
|
157
|
-
def run_struct_block(self, jac_ast):
|
|
158
|
-
"""
|
|
159
|
-
struct_block: LBRACE (has_stmt)* RBRACE | COLON has_stmt | SEMI;
|
|
160
|
-
"""
|
|
161
|
-
kid = self.set_cur_ast(jac_ast)
|
|
162
|
-
ret = {}
|
|
163
|
-
for i in kid:
|
|
164
|
-
if i.name == "has_stmt":
|
|
165
|
-
self.run_has_stmt(i, ret)
|
|
166
|
-
return ret
|
|
167
|
-
|
|
168
|
-
def run_graph_block(self, jac_ast):
|
|
169
|
-
"""
|
|
170
|
-
graph_block:
|
|
171
|
-
LBRACE has_root can_block KW_SPAWN code_block RBRACE
|
|
172
|
-
| COLON has_root can_block KW_SPAWN code_block SEMI;
|
|
173
|
-
"""
|
|
174
|
-
kid = self.set_cur_ast(jac_ast)
|
|
175
|
-
root_name = self.run_has_root(kid[1])
|
|
176
|
-
try:
|
|
177
|
-
for ability in self.get_all_abilities().obj_list():
|
|
178
|
-
self._jac_scope.add_action(ability)
|
|
179
|
-
|
|
180
|
-
self.run_code_block(kid[4])
|
|
181
|
-
except Exception as e:
|
|
182
|
-
self.rt_error(f"Internal Exception: {e}", self._cur_jac_ast)
|
|
183
|
-
local_state = self._jac_scope.local_scope
|
|
184
|
-
if root_name in local_state.keys():
|
|
185
|
-
obj = local_state[root_name]
|
|
186
|
-
if not isinstance(obj, Node):
|
|
187
|
-
self.rt_error(f"{root_name} is {type(obj)} not node!", kid[3])
|
|
188
|
-
return obj
|
|
189
|
-
else:
|
|
190
|
-
self.rt_error("Graph didn't produce root node!", kid[3])
|
|
191
|
-
|
|
192
|
-
def run_has_root(self, jac_ast):
|
|
193
|
-
"""
|
|
194
|
-
has_root: KW_HAS KW_ANCHOR NAME SEMI;
|
|
195
|
-
"""
|
|
196
|
-
kid = self.set_cur_ast(jac_ast)
|
|
197
|
-
return kid[2].token_text()
|
|
198
|
-
|
|
199
|
-
# Helper Functions ##################
|
|
200
|
-
|
|
201
|
-
def build_object_with_supers(self, item, jac_ast):
|
|
202
|
-
for i in self.super_archs:
|
|
203
|
-
super_jac_ast = (
|
|
204
|
-
self.parent()
|
|
205
|
-
.arch_ids.get_obj_by_name(name=i, kind=item.kind)
|
|
206
|
-
.get_jac_ast()
|
|
207
|
-
.kid[-1]
|
|
208
|
-
)
|
|
209
|
-
self.run_attr_block(super_jac_ast, item) if not isinstance(
|
|
210
|
-
item, Walker
|
|
211
|
-
) else self.run_walker_block(super_jac_ast, item)
|
|
212
|
-
self.run_attr_block(jac_ast, item) if not isinstance(
|
|
213
|
-
item, Walker
|
|
214
|
-
) else self.run_walker_block(jac_ast, item)
|