jaseci 1.4.2.6__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.

Files changed (187) hide show
  1. jaseci/__init__.py +3 -37
  2. jaseci-2.0.0.dist-info/METADATA +65 -0
  3. jaseci-2.0.0.dist-info/RECORD +4 -0
  4. {jaseci-1.4.2.6.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
  5. jaseci/VERSION +0 -1
  6. jaseci/cli_tools/__init__.py +0 -0
  7. jaseci/cli_tools/book_tools.py +0 -457
  8. jaseci/cli_tools/jsctl.py +0 -500
  9. jaseci/cli_tools/tests/__init__.py +0 -0
  10. jaseci/cli_tools/tests/test_jsctl.py +0 -556
  11. jaseci/extens/__init__.py +0 -0
  12. jaseci/extens/act_lib/__init__.py +0 -0
  13. jaseci/extens/act_lib/date.py +0 -118
  14. jaseci/extens/act_lib/elastic.py +0 -87
  15. jaseci/extens/act_lib/file.py +0 -77
  16. jaseci/extens/act_lib/file_handler.py +0 -190
  17. jaseci/extens/act_lib/internal.py +0 -19
  18. jaseci/extens/act_lib/jaseci.py +0 -62
  19. jaseci/extens/act_lib/mail.py +0 -10
  20. jaseci/extens/act_lib/maths.py +0 -168
  21. jaseci/extens/act_lib/net.py +0 -192
  22. jaseci/extens/act_lib/rand.py +0 -83
  23. jaseci/extens/act_lib/regex.py +0 -85
  24. jaseci/extens/act_lib/request.py +0 -170
  25. jaseci/extens/act_lib/std.py +0 -236
  26. jaseci/extens/act_lib/storage.py +0 -53
  27. jaseci/extens/act_lib/stripe.py +0 -338
  28. jaseci/extens/act_lib/task.py +0 -14
  29. jaseci/extens/act_lib/tests/__init__.py +0 -0
  30. jaseci/extens/act_lib/tests/std_test_code.py +0 -37
  31. jaseci/extens/act_lib/tests/test_date.py +0 -26
  32. jaseci/extens/act_lib/tests/test_elastic.py +0 -159
  33. jaseci/extens/act_lib/tests/test_file.py +0 -116
  34. jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
  35. jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
  36. jaseci/extens/act_lib/tests/test_maths.py +0 -147
  37. jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
  38. jaseci/extens/act_lib/tests/test_regex.py +0 -61
  39. jaseci/extens/act_lib/tests/test_std.py +0 -51
  40. jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
  41. jaseci/extens/act_lib/tests/test_url.py +0 -32
  42. jaseci/extens/act_lib/tests/test_vector.py +0 -36
  43. jaseci/extens/act_lib/tests/test_webtool.py +0 -44
  44. jaseci/extens/act_lib/tests/test_zlib.py +0 -24
  45. jaseci/extens/act_lib/url.py +0 -80
  46. jaseci/extens/act_lib/vector.py +0 -158
  47. jaseci/extens/act_lib/webtool.py +0 -29
  48. jaseci/extens/act_lib/zip.py +0 -34
  49. jaseci/extens/api/__init__.py +0 -0
  50. jaseci/extens/api/actions_api.py +0 -171
  51. jaseci/extens/api/alias_api.py +0 -140
  52. jaseci/extens/api/architype_api.py +0 -197
  53. jaseci/extens/api/config_api.py +0 -129
  54. jaseci/extens/api/global_api.py +0 -85
  55. jaseci/extens/api/graph_api.py +0 -168
  56. jaseci/extens/api/health_api.py +0 -21
  57. jaseci/extens/api/interface.py +0 -269
  58. jaseci/extens/api/jac_api.py +0 -172
  59. jaseci/extens/api/jsorc_api.py +0 -317
  60. jaseci/extens/api/logger_api.py +0 -90
  61. jaseci/extens/api/master_api.py +0 -134
  62. jaseci/extens/api/object_api.py +0 -102
  63. jaseci/extens/api/prometheus_api.py +0 -75
  64. jaseci/extens/api/queue_api.py +0 -141
  65. jaseci/extens/api/sentinel_api.py +0 -271
  66. jaseci/extens/api/share_api.py +0 -64
  67. jaseci/extens/api/super_api.py +0 -65
  68. jaseci/extens/api/tests/__init__.py +0 -0
  69. jaseci/extens/api/tests/test_architype_api.py +0 -66
  70. jaseci/extens/api/tests/test_global_api.py +0 -179
  71. jaseci/extens/api/tests/test_graph_api.py +0 -64
  72. jaseci/extens/api/tests/test_logger_api.py +0 -43
  73. jaseci/extens/api/tests/test_object_api.py +0 -20
  74. jaseci/extens/api/tests/test_sentinel_api.py +0 -66
  75. jaseci/extens/api/tests/test_uncommon.py +0 -107
  76. jaseci/extens/api/tests/test_user_api.py +0 -32
  77. jaseci/extens/api/tests/test_walker_api.py +0 -316
  78. jaseci/extens/api/user_api.py +0 -166
  79. jaseci/extens/api/walker_api.py +0 -299
  80. jaseci/extens/api/webhook_api.py +0 -77
  81. jaseci/extens/svc/__init__.py +0 -0
  82. jaseci/extens/svc/elastic_svc.py +0 -366
  83. jaseci/extens/svc/kube_svc.py +0 -432
  84. jaseci/extens/svc/mail_svc.py +0 -156
  85. jaseci/extens/svc/prome_svc.py +0 -378
  86. jaseci/extens/svc/redis_svc.py +0 -63
  87. jaseci/extens/svc/storage_svc.py +0 -193
  88. jaseci/extens/svc/stripe_svc.py +0 -51
  89. jaseci/extens/svc/task_svc.py +0 -155
  90. jaseci/extens/svc/tasks.py +0 -302
  91. jaseci/jac/__init__.py +0 -0
  92. jaseci/jac/interpreter/__init__.py +0 -0
  93. jaseci/jac/interpreter/architype_interp.py +0 -219
  94. jaseci/jac/interpreter/interp.py +0 -1784
  95. jaseci/jac/interpreter/sentinel_interp.py +0 -260
  96. jaseci/jac/interpreter/tests/__init__.py +0 -0
  97. jaseci/jac/interpreter/tests/test_interp.py +0 -42
  98. jaseci/jac/interpreter/walker_interp.py +0 -249
  99. jaseci/jac/ir/__init__.py +0 -0
  100. jaseci/jac/ir/ast.py +0 -73
  101. jaseci/jac/ir/ast_builder.py +0 -249
  102. jaseci/jac/ir/jac_code.py +0 -151
  103. jaseci/jac/ir/passes/__init__.py +0 -6
  104. jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
  105. jaseci/jac/ir/passes/codegen_pass.py +0 -244
  106. jaseci/jac/ir/passes/ir_pass.py +0 -29
  107. jaseci/jac/ir/passes/printer_pass.py +0 -23
  108. jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
  109. jaseci/jac/ir/passes/schedule.py +0 -23
  110. jaseci/jac/ir/passes/stats_pass.py +0 -16
  111. jaseci/jac/jac.g4 +0 -450
  112. jaseci/jac/jac_parse/__init__.py +0 -0
  113. jaseci/jac/jac_parse/jacLexer.py +0 -809
  114. jaseci/jac/jac_parse/jacListener.py +0 -853
  115. jaseci/jac/jac_parse/jacParser.py +0 -9192
  116. jaseci/jac/jac_set.py +0 -120
  117. jaseci/jac/jsci_vm/__init__.py +0 -0
  118. jaseci/jac/jsci_vm/disasm.py +0 -94
  119. jaseci/jac/jsci_vm/inst_ptr.py +0 -31
  120. jaseci/jac/jsci_vm/machine.py +0 -188
  121. jaseci/jac/jsci_vm/op_codes.py +0 -82
  122. jaseci/jac/jsci_vm/tests/__init__.py +0 -0
  123. jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
  124. jaseci/jac/machine/__init__.py +0 -0
  125. jaseci/jac/machine/jac_scope.py +0 -86
  126. jaseci/jac/machine/jac_value.py +0 -227
  127. jaseci/jac/machine/machine_state.py +0 -386
  128. jaseci/jac/tests/__init__.py +0 -0
  129. jaseci/jac/tests/book_code.py +0 -624
  130. jaseci/jac/tests/test_book.py +0 -380
  131. jaseci/jac/tests/test_lang_14.py +0 -49
  132. jaseci/jsorc/__init__.py +0 -7
  133. jaseci/jsorc/jsorc.py +0 -642
  134. jaseci/jsorc/jsorc_settings.py +0 -211
  135. jaseci/jsorc/jsorc_utils.py +0 -298
  136. jaseci/jsorc/live_actions.py +0 -365
  137. jaseci/jsorc/manifests/__init__.py +0 -0
  138. jaseci/jsorc/manifests/database.yaml +0 -109
  139. jaseci/jsorc/manifests/elastic.yaml +0 -6029
  140. jaseci/jsorc/manifests/prometheus.yaml +0 -1383
  141. jaseci/jsorc/manifests/redis.yaml +0 -64
  142. jaseci/jsorc/memory.py +0 -258
  143. jaseci/jsorc/redis.py +0 -140
  144. jaseci/jsorc/remote_actions.py +0 -158
  145. jaseci/jsorc/tests/__init__.py +0 -0
  146. jaseci/jsorc/tests/test_actions.py +0 -542
  147. jaseci/jsorc/tests/test_jsorc.py +0 -112
  148. jaseci/prim/__init__.py +0 -0
  149. jaseci/prim/ability.py +0 -94
  150. jaseci/prim/architype.py +0 -90
  151. jaseci/prim/edge.py +0 -173
  152. jaseci/prim/element.py +0 -233
  153. jaseci/prim/graph.py +0 -27
  154. jaseci/prim/master.py +0 -67
  155. jaseci/prim/node.py +0 -533
  156. jaseci/prim/obj_mixins.py +0 -238
  157. jaseci/prim/sentinel.py +0 -282
  158. jaseci/prim/super_master.py +0 -31
  159. jaseci/prim/walker.py +0 -261
  160. jaseci/svc/__init__.py +0 -0
  161. jaseci/tests/__init__.py +0 -0
  162. jaseci/tests/infer.py +0 -39
  163. jaseci/tests/jac_test_code.py +0 -1293
  164. jaseci/tests/jac_test_progs.py +0 -774
  165. jaseci/tests/test_core.py +0 -153
  166. jaseci/tests/test_jac.py +0 -824
  167. jaseci/tests/test_node.py +0 -89
  168. jaseci/tests/test_progs.py +0 -702
  169. jaseci/tests/test_stack.py +0 -220
  170. jaseci/tests/test_stripe.py +0 -225
  171. jaseci/utils/__init__.py +0 -0
  172. jaseci/utils/actions/__init__.py +0 -0
  173. jaseci/utils/actions/actions_manager.py +0 -254
  174. jaseci/utils/actions/actions_optimizer.py +0 -517
  175. jaseci/utils/actions/actions_state.py +0 -95
  176. jaseci/utils/file_handler.py +0 -171
  177. jaseci/utils/gprof2dot.py +0 -3786
  178. jaseci/utils/id_list.py +0 -169
  179. jaseci/utils/json_handler.py +0 -70
  180. jaseci/utils/log_utils.py +0 -57
  181. jaseci/utils/test_core.py +0 -62
  182. jaseci/utils/utils.py +0 -387
  183. jaseci-1.4.2.6.dist-info/LICENSE +0 -21
  184. jaseci-1.4.2.6.dist-info/METADATA +0 -39
  185. jaseci-1.4.2.6.dist-info/RECORD +0 -185
  186. jaseci-1.4.2.6.dist-info/entry_points.txt +0 -3
  187. jaseci-1.4.2.6.dist-info/top_level.txt +0 -1
@@ -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
@@ -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,219 +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
-
8
- from jaseci.prim.node import Node
9
- from jaseci.prim.edge import Edge
10
- from jaseci.prim.walker import Walker
11
- from jaseci.jac.interpreter.interp import Interp
12
- from jaseci.jac.machine.jac_scope import JacScope
13
- from jaseci.jac.machine.jac_value import JacValue
14
-
15
-
16
- class ArchitypeInterp(Interp):
17
- """Jac interpreter mixin for objects that will execute Jac code"""
18
-
19
- def run_architype(self, jac_ast):
20
- """
21
- architype:
22
- KW_NODE NAME (COLON NAME)* attr_block
23
- | KW_EDGE NAME (COLON NAME)* attr_block
24
- | KW_TYPE NAME struct_block
25
- | KW_GRAPH NAME graph_block
26
- | KW_ASYNC? KW_WALKER NAME namespaces? walker_block;
27
- """
28
- if jac_ast is None: # Using defaults
29
- if self.kind == "node" and self.name in ["root", "generic"]:
30
- return Node(
31
- m_id=self._m_id,
32
- h=self._h,
33
- kind=self.kind,
34
- name=self.name,
35
- parent=self.parent(),
36
- )
37
- elif self.kind == "edge" and self.name in ["generic"]:
38
- return Edge(
39
- m_id=self._m_id,
40
- h=self._h,
41
- kind=self.kind,
42
- name=self.name,
43
- parent=self.parent(),
44
- )
45
-
46
- kid = self.set_cur_ast(jac_ast)
47
-
48
- self.push_scope(JacScope(parent=self, name=f"spawn:{jac_ast.loc_str()}"))
49
- if kid[0].name == "KW_NODE":
50
- item = Node(
51
- m_id=self._m_id,
52
- h=self._h,
53
- kind=kid[0].token_text(),
54
- name=kid[1].token_text(),
55
- parent=self.parent(),
56
- )
57
- self.build_object_with_supers(item, kid[-1])
58
- elif kid[0].name == "KW_EDGE":
59
- item = Edge(
60
- m_id=self._m_id,
61
- h=self._h,
62
- kind=kid[0].token_text(),
63
- name=kid[1].token_text(),
64
- parent=self.parent(),
65
- )
66
- self.build_object_with_supers(item, kid[-1])
67
- elif kid[0].name == "KW_TYPE":
68
- item = self.run_struct_block(kid[-1])
69
- elif kid[0].name == "KW_GRAPH":
70
- item = self.run_graph_block(kid[-1])
71
- elif kid[0].name == "KW_WALKER":
72
- item = Walker(
73
- m_id=self._m_id,
74
- h=self._h,
75
- code_ir=jac_ast,
76
- name=kid[1].token_text(),
77
- kind=kid[0].token_text(),
78
- parent=self.parent(),
79
- is_async=self.is_async,
80
- )
81
- if kid[2].name == "namespaces":
82
- item.namespaces = self.run_namespaces(jac_ast.kid[2])
83
- self.build_object_with_supers(item, kid[-1])
84
- elif jac_ast.name == "graph_block": # usedi n jac tests
85
- item = self.run_graph_block(jac_ast)
86
- self.pop_scope()
87
- return item
88
-
89
- def run_namespaces(self, jac_ast):
90
- """
91
- namespaces: COLON name_list;
92
- """
93
- return self.run_name_list(jac_ast.kid[1])
94
-
95
- def run_walker_block(self, jac_ast, obj):
96
- """
97
- walker_block:
98
- LBRACE attr_stmt* walk_entry_block? (
99
- statement
100
- | walk_activity_block
101
- )* walk_exit_block? RBRACE;
102
- """
103
- kid = self.set_cur_ast(jac_ast)
104
- for i in kid:
105
- if i.name == "attr_stmt":
106
- self.run_attr_stmt(jac_ast=i, obj=obj)
107
-
108
- def run_attr_block(self, jac_ast, obj):
109
- """
110
- attr_block:
111
- LBRACE (attr_stmt)* RBRACE
112
- | COLON (attr_stmt)* SEMI
113
- | SEMI;
114
- """
115
- kid = self.set_cur_ast(jac_ast)
116
- for i in kid:
117
- if i.name == "attr_stmt":
118
- self.run_attr_stmt(i, obj)
119
-
120
- def run_attr_stmt(self, jac_ast, obj):
121
- """
122
- attr_stmt: has_stmt | can_stmt;
123
- """
124
- kid = self.set_cur_ast(jac_ast)
125
- if kid[0].name == "has_stmt":
126
- self.run_has_stmt(kid[0], obj)
127
- # Can statements in architype handled in architype load
128
-
129
- def run_has_stmt(self, jac_ast, obj):
130
- """
131
- has_stmt: KW_HAS has_assign (COMMA has_assign)* SEMI;
132
- """
133
- kid = self.set_cur_ast(jac_ast)
134
- for i in kid:
135
- if i.name == "has_assign":
136
- self.run_has_assign(i, obj)
137
-
138
- def run_has_assign(self, jac_ast, obj):
139
- """
140
- has_assign: KW_PRIVATE? KW_ANCHOR? (NAME | NAME EQ expression);
141
- """
142
- kid = self.set_cur_ast(jac_ast)
143
- while kid[0].name in ["KW_PRIVATE", "KW_ANCHOR"]:
144
- kid = kid[1:]
145
- var_name = kid[0].token_text()
146
- var_val = None # jac's null
147
- if len(kid) > 1:
148
- self.run_expression(kid[2])
149
- var_val = self.pop().value
150
- if isinstance(obj, dict):
151
- obj[var_name] = var_val
152
- # Runs only once for walkers
153
- elif var_name not in obj.context.keys() or obj.j_type != "walker":
154
- JacValue(
155
- self, ctx=obj, name=var_name, value=var_val, create_mode=True
156
- ).write(kid[0], force=True)
157
-
158
- def run_struct_block(self, jac_ast):
159
- """
160
- struct_block: LBRACE (has_stmt)* RBRACE | COLON has_stmt | SEMI;
161
- """
162
- kid = self.set_cur_ast(jac_ast)
163
- ret = {}
164
- for i in kid:
165
- if i.name == "has_stmt":
166
- self.run_has_stmt(i, ret)
167
- return ret
168
-
169
- def run_graph_block(self, jac_ast):
170
- """
171
- graph_block:
172
- LBRACE has_root can_block KW_SPAWN code_block RBRACE
173
- | COLON has_root can_block KW_SPAWN code_block SEMI;
174
- """
175
- kid = self.set_cur_ast(jac_ast)
176
- root_name = self.run_has_root(kid[1])
177
- try:
178
- for ability in self.get_all_abilities().obj_list():
179
- self._jac_scope.add_action(ability)
180
-
181
- self.run_code_block(kid[4])
182
- except Exception as e:
183
- self.rt_error(f"Internal Exception: {e}", self._cur_jac_ast)
184
- local_state = self._jac_scope.local_scope
185
- if root_name in local_state.keys():
186
- obj = local_state[root_name]
187
- if not isinstance(obj, Node):
188
- self.rt_error(f"{root_name} is {type(obj)} not node!", kid[3])
189
- return obj
190
- else:
191
- self.rt_error("Graph didn't produce root node!", kid[3])
192
-
193
- def run_has_root(self, jac_ast):
194
- """
195
- has_root: KW_HAS KW_ANCHOR NAME SEMI;
196
- """
197
- kid = self.set_cur_ast(jac_ast)
198
- return kid[2].token_text()
199
-
200
- # Helper Functions ##################
201
-
202
- def build_object_with_supers(self, item, jac_ast):
203
- for i in self.super_archs:
204
- super_jac_ast = (
205
- self.parent()
206
- .arch_ids.get_obj_by_name(name=i, kind=item.kind)
207
- .get_jac_ast()
208
- .kid[-1]
209
- )
210
- (
211
- self.run_attr_block(super_jac_ast, item)
212
- if not isinstance(item, Walker)
213
- else self.run_walker_block(super_jac_ast, item)
214
- )
215
- (
216
- self.run_attr_block(jac_ast, item)
217
- if not isinstance(item, Walker)
218
- else self.run_walker_block(jac_ast, item)
219
- )