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.

Files changed (186) 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.5.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 -117
  14. jaseci/extens/act_lib/elastic.py +0 -87
  15. jaseci/extens/act_lib/file.py +0 -76
  16. jaseci/extens/act_lib/file_handler.py +0 -189
  17. jaseci/extens/act_lib/internal.py +0 -18
  18. jaseci/extens/act_lib/jaseci.py +0 -61
  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 -191
  22. jaseci/extens/act_lib/rand.py +0 -82
  23. jaseci/extens/act_lib/regex.py +0 -85
  24. jaseci/extens/act_lib/request.py +0 -169
  25. jaseci/extens/act_lib/std.py +0 -235
  26. jaseci/extens/act_lib/storage.py +0 -53
  27. jaseci/extens/act_lib/stripe.py +0 -337
  28. jaseci/extens/act_lib/task.py +0 -13
  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 -79
  46. jaseci/extens/act_lib/vector.py +0 -157
  47. jaseci/extens/act_lib/webtool.py +0 -28
  48. jaseci/extens/act_lib/zip.py +0 -33
  49. jaseci/extens/api/__init__.py +0 -0
  50. jaseci/extens/api/actions_api.py +0 -170
  51. jaseci/extens/api/alias_api.py +0 -139
  52. jaseci/extens/api/architype_api.py +0 -196
  53. jaseci/extens/api/config_api.py +0 -129
  54. jaseci/extens/api/global_api.py +0 -84
  55. jaseci/extens/api/graph_api.py +0 -167
  56. jaseci/extens/api/health_api.py +0 -20
  57. jaseci/extens/api/interface.py +0 -268
  58. jaseci/extens/api/jac_api.py +0 -171
  59. jaseci/extens/api/jsorc_api.py +0 -316
  60. jaseci/extens/api/logger_api.py +0 -89
  61. jaseci/extens/api/master_api.py +0 -133
  62. jaseci/extens/api/object_api.py +0 -101
  63. jaseci/extens/api/prometheus_api.py +0 -74
  64. jaseci/extens/api/queue_api.py +0 -140
  65. jaseci/extens/api/sentinel_api.py +0 -270
  66. jaseci/extens/api/super_api.py +0 -64
  67. jaseci/extens/api/tests/__init__.py +0 -0
  68. jaseci/extens/api/tests/test_architype_api.py +0 -66
  69. jaseci/extens/api/tests/test_global_api.py +0 -179
  70. jaseci/extens/api/tests/test_graph_api.py +0 -64
  71. jaseci/extens/api/tests/test_logger_api.py +0 -43
  72. jaseci/extens/api/tests/test_object_api.py +0 -20
  73. jaseci/extens/api/tests/test_sentinel_api.py +0 -66
  74. jaseci/extens/api/tests/test_uncommon.py +0 -107
  75. jaseci/extens/api/tests/test_user_api.py +0 -32
  76. jaseci/extens/api/tests/test_walker_api.py +0 -316
  77. jaseci/extens/api/user_api.py +0 -144
  78. jaseci/extens/api/walker_api.py +0 -298
  79. jaseci/extens/api/webhook_api.py +0 -74
  80. jaseci/extens/svc/__init__.py +0 -0
  81. jaseci/extens/svc/elastic_svc.py +0 -366
  82. jaseci/extens/svc/kube_svc.py +0 -432
  83. jaseci/extens/svc/mail_svc.py +0 -156
  84. jaseci/extens/svc/prome_svc.py +0 -378
  85. jaseci/extens/svc/redis_svc.py +0 -63
  86. jaseci/extens/svc/storage_svc.py +0 -193
  87. jaseci/extens/svc/stripe_svc.py +0 -51
  88. jaseci/extens/svc/task_svc.py +0 -155
  89. jaseci/extens/svc/tasks.py +0 -302
  90. jaseci/jac/__init__.py +0 -0
  91. jaseci/jac/interpreter/__init__.py +0 -0
  92. jaseci/jac/interpreter/architype_interp.py +0 -214
  93. jaseci/jac/interpreter/interp.py +0 -1783
  94. jaseci/jac/interpreter/sentinel_interp.py +0 -257
  95. jaseci/jac/interpreter/tests/__init__.py +0 -0
  96. jaseci/jac/interpreter/tests/test_interp.py +0 -42
  97. jaseci/jac/interpreter/walker_interp.py +0 -248
  98. jaseci/jac/ir/__init__.py +0 -0
  99. jaseci/jac/ir/ast.py +0 -73
  100. jaseci/jac/ir/ast_builder.py +0 -249
  101. jaseci/jac/ir/jac_code.py +0 -152
  102. jaseci/jac/ir/passes/__init__.py +0 -6
  103. jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
  104. jaseci/jac/ir/passes/codegen_pass.py +0 -244
  105. jaseci/jac/ir/passes/ir_pass.py +0 -29
  106. jaseci/jac/ir/passes/printer_pass.py +0 -23
  107. jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
  108. jaseci/jac/ir/passes/schedule.py +0 -23
  109. jaseci/jac/ir/passes/stats_pass.py +0 -16
  110. jaseci/jac/jac.g4 +0 -450
  111. jaseci/jac/jac_parse/__init__.py +0 -0
  112. jaseci/jac/jac_parse/jacLexer.py +0 -809
  113. jaseci/jac/jac_parse/jacListener.py +0 -853
  114. jaseci/jac/jac_parse/jacParser.py +0 -9192
  115. jaseci/jac/jac_set.py +0 -119
  116. jaseci/jac/jsci_vm/__init__.py +0 -0
  117. jaseci/jac/jsci_vm/disasm.py +0 -94
  118. jaseci/jac/jsci_vm/inst_ptr.py +0 -31
  119. jaseci/jac/jsci_vm/machine.py +0 -188
  120. jaseci/jac/jsci_vm/op_codes.py +0 -82
  121. jaseci/jac/jsci_vm/tests/__init__.py +0 -0
  122. jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
  123. jaseci/jac/machine/__init__.py +0 -0
  124. jaseci/jac/machine/jac_scope.py +0 -85
  125. jaseci/jac/machine/jac_value.py +0 -226
  126. jaseci/jac/machine/machine_state.py +0 -383
  127. jaseci/jac/tests/__init__.py +0 -0
  128. jaseci/jac/tests/book_code.py +0 -624
  129. jaseci/jac/tests/test_book.py +0 -380
  130. jaseci/jac/tests/test_lang_14.py +0 -49
  131. jaseci/jsorc/__init__.py +0 -7
  132. jaseci/jsorc/jsorc.py +0 -642
  133. jaseci/jsorc/jsorc_settings.py +0 -211
  134. jaseci/jsorc/jsorc_utils.py +0 -298
  135. jaseci/jsorc/live_actions.py +0 -364
  136. jaseci/jsorc/manifests/__init__.py +0 -0
  137. jaseci/jsorc/manifests/database.yaml +0 -109
  138. jaseci/jsorc/manifests/elastic.yaml +0 -6024
  139. jaseci/jsorc/manifests/prometheus.yaml +0 -1383
  140. jaseci/jsorc/manifests/redis.yaml +0 -64
  141. jaseci/jsorc/memory.py +0 -258
  142. jaseci/jsorc/redis.py +0 -139
  143. jaseci/jsorc/remote_actions.py +0 -157
  144. jaseci/jsorc/tests/__init__.py +0 -0
  145. jaseci/jsorc/tests/test_actions.py +0 -542
  146. jaseci/jsorc/tests/test_jsorc.py +0 -112
  147. jaseci/prim/__init__.py +0 -0
  148. jaseci/prim/ability.py +0 -93
  149. jaseci/prim/architype.py +0 -89
  150. jaseci/prim/edge.py +0 -172
  151. jaseci/prim/element.py +0 -233
  152. jaseci/prim/graph.py +0 -26
  153. jaseci/prim/master.py +0 -64
  154. jaseci/prim/node.py +0 -532
  155. jaseci/prim/obj_mixins.py +0 -235
  156. jaseci/prim/sentinel.py +0 -281
  157. jaseci/prim/super_master.py +0 -31
  158. jaseci/prim/walker.py +0 -261
  159. jaseci/svc/__init__.py +0 -0
  160. jaseci/tests/__init__.py +0 -0
  161. jaseci/tests/infer.py +0 -39
  162. jaseci/tests/jac_test_code.py +0 -1293
  163. jaseci/tests/jac_test_progs.py +0 -774
  164. jaseci/tests/test_core.py +0 -153
  165. jaseci/tests/test_jac.py +0 -824
  166. jaseci/tests/test_node.py +0 -89
  167. jaseci/tests/test_progs.py +0 -702
  168. jaseci/tests/test_stack.py +0 -220
  169. jaseci/tests/test_stripe.py +0 -225
  170. jaseci/utils/__init__.py +0 -0
  171. jaseci/utils/actions/__init__.py +0 -0
  172. jaseci/utils/actions/actions_manager.py +0 -254
  173. jaseci/utils/actions/actions_optimizer.py +0 -516
  174. jaseci/utils/actions/actions_state.py +0 -95
  175. jaseci/utils/file_handler.py +0 -171
  176. jaseci/utils/gprof2dot.py +0 -3786
  177. jaseci/utils/id_list.py +0 -168
  178. jaseci/utils/json_handler.py +0 -70
  179. jaseci/utils/log_utils.py +0 -57
  180. jaseci/utils/test_core.py +0 -62
  181. jaseci/utils/utils.py +0 -387
  182. jaseci-1.4.2.5.dist-info/LICENSE +0 -21
  183. jaseci-1.4.2.5.dist-info/METADATA +0 -39
  184. jaseci-1.4.2.5.dist-info/RECORD +0 -184
  185. jaseci-1.4.2.5.dist-info/entry_points.txt +0 -3
  186. jaseci-1.4.2.5.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,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)