osbot-utils 1.7.7__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.
- osbot_utils/__init__.py +1 -0
- osbot_utils/base_classes/Cache_Pickle.py +129 -0
- osbot_utils/base_classes/Kwargs_To_Disk.py +27 -0
- osbot_utils/base_classes/Kwargs_To_Self.py +308 -0
- osbot_utils/base_classes/Type_Safe__List.py +14 -0
- osbot_utils/base_classes/__init__.py +0 -0
- osbot_utils/context_managers/__init__.py +0 -0
- osbot_utils/context_managers/capture_duration.py +33 -0
- osbot_utils/decorators/__init__.py +0 -0
- osbot_utils/decorators/classes/__init__.py +0 -0
- osbot_utils/decorators/classes/singleton.py +9 -0
- osbot_utils/decorators/lists/__init__.py +0 -0
- osbot_utils/decorators/lists/filter_list.py +12 -0
- osbot_utils/decorators/lists/group_by.py +21 -0
- osbot_utils/decorators/lists/index_by.py +27 -0
- osbot_utils/decorators/methods/__init__.py +0 -0
- osbot_utils/decorators/methods/cache.py +19 -0
- osbot_utils/decorators/methods/cache_on_function.py +56 -0
- osbot_utils/decorators/methods/cache_on_self.py +78 -0
- osbot_utils/decorators/methods/cache_on_tmp.py +71 -0
- osbot_utils/decorators/methods/capture_exception.py +37 -0
- osbot_utils/decorators/methods/capture_status.py +20 -0
- osbot_utils/decorators/methods/catch.py +13 -0
- osbot_utils/decorators/methods/context.py +11 -0
- osbot_utils/decorators/methods/depreciated.py +79 -0
- osbot_utils/decorators/methods/function_type_check.py +62 -0
- osbot_utils/decorators/methods/obj_as_context.py +6 -0
- osbot_utils/decorators/methods/remove_return_value.py +22 -0
- osbot_utils/decorators/methods/required_fields.py +19 -0
- osbot_utils/fluent/Fluent_Dict.py +19 -0
- osbot_utils/fluent/Fluent_List.py +44 -0
- osbot_utils/fluent/__init__.py +1 -0
- osbot_utils/graphs/__init__.py +0 -0
- osbot_utils/graphs/mermaid/Mermaid.py +75 -0
- osbot_utils/graphs/mermaid/Mermaid__Edge.py +49 -0
- osbot_utils/graphs/mermaid/Mermaid__Graph.py +93 -0
- osbot_utils/graphs/mermaid/Mermaid__Node.py +69 -0
- osbot_utils/graphs/mermaid/Mermaid__Renderer.py +54 -0
- osbot_utils/graphs/mermaid/configs/Mermaid__Edge__Config.py +7 -0
- osbot_utils/graphs/mermaid/configs/Mermaid__Node__Config.py +9 -0
- osbot_utils/graphs/mermaid/configs/Mermaid__Render__Config.py +7 -0
- osbot_utils/graphs/mermaid/examples/Mermaid_Examples__FlowChart.py +98 -0
- osbot_utils/graphs/mermaid/models/Mermaid__Diagram_Direction.py +9 -0
- osbot_utils/graphs/mermaid/models/Mermaid__Diagram__Type.py +17 -0
- osbot_utils/graphs/mermaid/models/Mermaid__Node__Shape.py +30 -0
- osbot_utils/graphs/mgraph/MGraph.py +53 -0
- osbot_utils/graphs/mgraph/MGraph__Config.py +7 -0
- osbot_utils/graphs/mgraph/MGraph__Data.py +139 -0
- osbot_utils/graphs/mgraph/MGraph__Edge.py +27 -0
- osbot_utils/graphs/mgraph/MGraph__Node.py +33 -0
- osbot_utils/graphs/mgraph/MGraph__Random_Graphs.py +27 -0
- osbot_utils/graphs/mgraph/MGraph__Serializer.py +43 -0
- osbot_utils/graphs/mgraph/MGraphs.py +17 -0
- osbot_utils/graphs/mgraph/__init__.py +0 -0
- osbot_utils/helpers/CPrint.py +98 -0
- osbot_utils/helpers/Dict_To_Attr.py +7 -0
- osbot_utils/helpers/Local_Cache.py +111 -0
- osbot_utils/helpers/Local_Caches.py +54 -0
- osbot_utils/helpers/Print_Table.py +369 -0
- osbot_utils/helpers/Python_Audit.py +45 -0
- osbot_utils/helpers/Random_Seed.py +27 -0
- osbot_utils/helpers/SCP.py +58 -0
- osbot_utils/helpers/SSH.py +151 -0
- osbot_utils/helpers/Type_Registry.py +16 -0
- osbot_utils/helpers/__init__.py +0 -0
- osbot_utils/helpers/ast/Ast.py +35 -0
- osbot_utils/helpers/ast/Ast_Base.py +124 -0
- osbot_utils/helpers/ast/Ast_Data.py +28 -0
- osbot_utils/helpers/ast/Ast_Load.py +62 -0
- osbot_utils/helpers/ast/Ast_Merge.py +26 -0
- osbot_utils/helpers/ast/Ast_Node.py +117 -0
- osbot_utils/helpers/ast/Ast_Visit.py +85 -0
- osbot_utils/helpers/ast/Call_Tree.py +38 -0
- osbot_utils/helpers/ast/__init__.py +145 -0
- osbot_utils/helpers/ast/nodes/Ast_Add.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Alias.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_And.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Argument.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Arguments.py +10 -0
- osbot_utils/helpers/ast/nodes/Ast_Assert.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Assign.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Attribute.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Aug_Assign.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Bin_Op.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Bool_Op.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Break.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Call.py +17 -0
- osbot_utils/helpers/ast/nodes/Ast_Class_Def.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Compare.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Comprehension.py +10 -0
- osbot_utils/helpers/ast/nodes/Ast_Constant.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Continue.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Dict.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Eq.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Except_Handler.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Expr.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_For.py +10 -0
- osbot_utils/helpers/ast/nodes/Ast_Function_Def.py +17 -0
- osbot_utils/helpers/ast/nodes/Ast_Generator_Exp.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Gt.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_GtE.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_If.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_If_Exp.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Import.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Import_From.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_In.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Is.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Is_Not.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Keyword.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Lambda.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_List.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_List_Comp.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Load.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Lt.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_LtE.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Mod.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Module.py +20 -0
- osbot_utils/helpers/ast/nodes/Ast_Mult.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Name.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Not.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Not_Eq.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Not_In.py +6 -0
- osbot_utils/helpers/ast/nodes/Ast_Or.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Pass.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Pow.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Raise.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Return.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Set.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Slice.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Starred.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Store.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Sub.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Subscript.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_Try.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Tuple.py +9 -0
- osbot_utils/helpers/ast/nodes/Ast_Unary_Op.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_While.py +8 -0
- osbot_utils/helpers/ast/nodes/Ast_With.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_With_Item.py +7 -0
- osbot_utils/helpers/ast/nodes/Ast_Yield.py +7 -0
- osbot_utils/helpers/ast/nodes/__init__.py +0 -0
- osbot_utils/helpers/html/Dict_To_Css.py +20 -0
- osbot_utils/helpers/html/Dict_To_Html.py +59 -0
- osbot_utils/helpers/html/Dict_To_Tags.py +88 -0
- osbot_utils/helpers/html/Html_To_Dict.py +75 -0
- osbot_utils/helpers/html/Html_To_Tag.py +20 -0
- osbot_utils/helpers/html/Tag__Base.py +91 -0
- osbot_utils/helpers/html/Tag__Body.py +5 -0
- osbot_utils/helpers/html/Tag__Div.py +5 -0
- osbot_utils/helpers/html/Tag__H.py +9 -0
- osbot_utils/helpers/html/Tag__HR.py +5 -0
- osbot_utils/helpers/html/Tag__Head.py +32 -0
- osbot_utils/helpers/html/Tag__Html.py +42 -0
- osbot_utils/helpers/html/Tag__Link.py +17 -0
- osbot_utils/helpers/html/Tag__Style.py +25 -0
- osbot_utils/helpers/html/__init__.py +0 -0
- osbot_utils/helpers/pubsub/Event__Queue.py +95 -0
- osbot_utils/helpers/pubsub/PubSub__Client.py +53 -0
- osbot_utils/helpers/pubsub/PubSub__Room.py +13 -0
- osbot_utils/helpers/pubsub/PubSub__Server.py +94 -0
- osbot_utils/helpers/pubsub/PubSub__Sqlite.py +24 -0
- osbot_utils/helpers/pubsub/__init__.py +0 -0
- osbot_utils/helpers/pubsub/schemas/Schema__Event.py +15 -0
- osbot_utils/helpers/pubsub/schemas/Schema__Event__Connect.py +7 -0
- osbot_utils/helpers/pubsub/schemas/Schema__Event__Disconnect.py +7 -0
- osbot_utils/helpers/pubsub/schemas/Schema__Event__Join_Room.py +8 -0
- osbot_utils/helpers/pubsub/schemas/Schema__Event__Leave_Room.py +8 -0
- osbot_utils/helpers/pubsub/schemas/Schema__Event__Message.py +7 -0
- osbot_utils/helpers/pubsub/schemas/Schema__PubSub__Client.py +8 -0
- osbot_utils/helpers/pubsub/schemas/__init__.py +0 -0
- osbot_utils/helpers/sqlite/Capture_Sqlite_Error.py +51 -0
- osbot_utils/helpers/sqlite/Sqlite__Cursor.py +87 -0
- osbot_utils/helpers/sqlite/Sqlite__Database.py +137 -0
- osbot_utils/helpers/sqlite/Sqlite__Field.py +70 -0
- osbot_utils/helpers/sqlite/Sqlite__Globals.py +5 -0
- osbot_utils/helpers/sqlite/Sqlite__Table.py +293 -0
- osbot_utils/helpers/sqlite/Sqlite__Table__Create.py +96 -0
- osbot_utils/helpers/sqlite/Temp_Sqlite__Database__Disk.py +17 -0
- osbot_utils/helpers/sqlite/Temp_Sqlite__Table.py +23 -0
- osbot_utils/helpers/sqlite/__init__.py +0 -0
- osbot_utils/helpers/sqlite/domains/Sqlite__Cache__Requests.py +214 -0
- osbot_utils/helpers/sqlite/domains/Sqlite__Cache__Requests__Patch.py +63 -0
- osbot_utils/helpers/sqlite/domains/Sqlite__DB__Files.py +23 -0
- osbot_utils/helpers/sqlite/domains/Sqlite__DB__Graph.py +47 -0
- osbot_utils/helpers/sqlite/domains/Sqlite__DB__Json.py +83 -0
- osbot_utils/helpers/sqlite/domains/Sqlite__DB__Local.py +20 -0
- osbot_utils/helpers/sqlite/domains/Sqlite__DB__Requests.py +39 -0
- osbot_utils/helpers/sqlite/domains/__init__.py +0 -0
- osbot_utils/helpers/sqlite/domains/schemas/Schema__Table__Requests.py +12 -0
- osbot_utils/helpers/sqlite/domains/schemas/__init__.py +0 -0
- osbot_utils/helpers/sqlite/models/Sqlite__Field__Type.py +37 -0
- osbot_utils/helpers/sqlite/models/__init__.py +0 -0
- osbot_utils/helpers/sqlite/sample_data/Sqlite__Sample_Data__Chinook.py +116 -0
- osbot_utils/helpers/sqlite/sample_data/__init__.py +0 -0
- osbot_utils/helpers/sqlite/sql_builder/SQL_Builder.py +159 -0
- osbot_utils/helpers/sqlite/sql_builder/SQL_Builder__Select.py +12 -0
- osbot_utils/helpers/sqlite/sql_builder/__init__.py +0 -0
- osbot_utils/helpers/sqlite/tables/Sqlite__Table__Config.py +63 -0
- osbot_utils/helpers/sqlite/tables/Sqlite__Table__Edges.py +46 -0
- osbot_utils/helpers/sqlite/tables/Sqlite__Table__Files.py +45 -0
- osbot_utils/helpers/sqlite/tables/Sqlite__Table__Nodes.py +52 -0
- osbot_utils/helpers/sqlite/tables/__init__.py +0 -0
- osbot_utils/helpers/trace/Trace_Call.py +120 -0
- osbot_utils/helpers/trace/Trace_Call__Config.py +94 -0
- osbot_utils/helpers/trace/Trace_Call__Graph.py +26 -0
- osbot_utils/helpers/trace/Trace_Call__Handler.py +215 -0
- osbot_utils/helpers/trace/Trace_Call__Print_Lines.py +85 -0
- osbot_utils/helpers/trace/Trace_Call__Print_Traces.py +170 -0
- osbot_utils/helpers/trace/Trace_Call__Stack.py +166 -0
- osbot_utils/helpers/trace/Trace_Call__Stack_Node.py +59 -0
- osbot_utils/helpers/trace/Trace_Call__Stats.py +71 -0
- osbot_utils/helpers/trace/Trace_Call__View_Model.py +75 -0
- osbot_utils/helpers/trace/Trace_Files.py +33 -0
- osbot_utils/helpers/trace/__init__.py +0 -0
- osbot_utils/testing/Catch.py +54 -0
- osbot_utils/testing/Duration.py +69 -0
- osbot_utils/testing/Hook_Method.py +118 -0
- osbot_utils/testing/Log_To_Queue.py +46 -0
- osbot_utils/testing/Log_To_String.py +37 -0
- osbot_utils/testing/Logging.py +81 -0
- osbot_utils/testing/Patch_Print.py +52 -0
- osbot_utils/testing/Profiler.py +89 -0
- osbot_utils/testing/Stderr.py +19 -0
- osbot_utils/testing/Stdout.py +19 -0
- osbot_utils/testing/Temp_File.py +46 -0
- osbot_utils/testing/Temp_Folder.py +114 -0
- osbot_utils/testing/Temp_Sys_Path.py +13 -0
- osbot_utils/testing/Temp_Web_Server.py +83 -0
- osbot_utils/testing/Temp_Zip.py +45 -0
- osbot_utils/testing/Temp_Zip_In_Memory.py +90 -0
- osbot_utils/testing/Unit_Test.py +34 -0
- osbot_utils/testing/Unzip_File.py +30 -0
- osbot_utils/testing/__init__.py +0 -0
- osbot_utils/utils/Assert.py +52 -0
- osbot_utils/utils/Call_Stack.py +187 -0
- osbot_utils/utils/Csv.py +32 -0
- osbot_utils/utils/Dev.py +47 -0
- osbot_utils/utils/Exceptions.py +7 -0
- osbot_utils/utils/Files.py +528 -0
- osbot_utils/utils/Functions.py +113 -0
- osbot_utils/utils/Http.py +136 -0
- osbot_utils/utils/Int.py +6 -0
- osbot_utils/utils/Json.py +171 -0
- osbot_utils/utils/Json_Cache.py +59 -0
- osbot_utils/utils/Lists.py +198 -0
- osbot_utils/utils/Misc.py +496 -0
- osbot_utils/utils/Objects.py +341 -0
- osbot_utils/utils/Png.py +29 -0
- osbot_utils/utils/Process.py +73 -0
- osbot_utils/utils/Python_Logger.py +301 -0
- osbot_utils/utils/Status.py +79 -0
- osbot_utils/utils/Str.py +63 -0
- osbot_utils/utils/Version.py +16 -0
- osbot_utils/utils/Zip.py +97 -0
- osbot_utils/utils/__init__.py +16 -0
- osbot_utils/version +1 -0
- osbot_utils-1.7.7.dist-info/LICENSE +201 -0
- osbot_utils-1.7.7.dist-info/METADATA +46 -0
- osbot_utils-1.7.7.dist-info/RECORD +260 -0
- osbot_utils-1.7.7.dist-info/WHEEL +4 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
import ast
|
2
|
+
import inspect
|
3
|
+
from osbot_utils.utils.Files import file_contents
|
4
|
+
from osbot_utils.utils.Str import str_dedent
|
5
|
+
from osbot_utils.helpers.ast.nodes.Ast_Module import Ast_Module
|
6
|
+
|
7
|
+
|
8
|
+
class Ast:
|
9
|
+
|
10
|
+
def __init__(self):
|
11
|
+
pass
|
12
|
+
|
13
|
+
def source_code__from(self, target):
|
14
|
+
source_raw = inspect.getsource(target)
|
15
|
+
source = str_dedent(source_raw) # remove any training spaces or it won't compile
|
16
|
+
return source
|
17
|
+
|
18
|
+
def ast_module__from(self, target):
|
19
|
+
source_code = self.source_code__from(target)
|
20
|
+
ast_module = self.ast_module__from_source_code(source_code)
|
21
|
+
return ast_module
|
22
|
+
|
23
|
+
def ast_module__from_file(self, path_file):
|
24
|
+
source_code = file_contents(path_file)
|
25
|
+
return self.ast_module__from_source_code(source_code)
|
26
|
+
|
27
|
+
def ast_module__from_source_code(self, source_code):
|
28
|
+
result = ast.parse(source_code)
|
29
|
+
if type(result) is ast.Module:
|
30
|
+
return Ast_Module(result)
|
31
|
+
|
32
|
+
def parse(self, source_code):
|
33
|
+
return ast.parse(source_code)
|
34
|
+
|
35
|
+
|
@@ -0,0 +1,124 @@
|
|
1
|
+
import ast
|
2
|
+
import inspect
|
3
|
+
|
4
|
+
from osbot_utils.utils.Dev import pprint, jprint
|
5
|
+
from osbot_utils.utils.Exceptions import syntax_error
|
6
|
+
from osbot_utils.utils.Files import is_file, file_contents
|
7
|
+
from osbot_utils.utils.Objects import obj_data, obj_info
|
8
|
+
from osbot_utils.utils.Str import str_dedent
|
9
|
+
|
10
|
+
|
11
|
+
class Ast_Base:
|
12
|
+
def __init__(self, node):
|
13
|
+
if node.__module__ != 'ast':
|
14
|
+
raise Exception(f'Expected node.__module__ to be ast, got: {node.__module__}')
|
15
|
+
self.node = node
|
16
|
+
|
17
|
+
def __repr__(self):
|
18
|
+
return self.__class__.__name__
|
19
|
+
|
20
|
+
def is_ast(self, target):
|
21
|
+
if hasattr(target, "__module__"):
|
22
|
+
if target.__module__ == 'ast':
|
23
|
+
return True
|
24
|
+
return False
|
25
|
+
|
26
|
+
def is_not_ast(self, target):
|
27
|
+
return self.is_ast(target) is False
|
28
|
+
|
29
|
+
def dump(self):
|
30
|
+
return ast.dump(self.node, indent=4)
|
31
|
+
|
32
|
+
def execute_code(self, exec_locals=None, exec_namespace=None):
|
33
|
+
exec_locals = exec_locals or {}
|
34
|
+
#exec_namespace = exec_namespace or {'__builtins__': {}} # this has quite a lot of side effects
|
35
|
+
exec_namespace = exec_namespace or {}
|
36
|
+
exec_error = None
|
37
|
+
try:
|
38
|
+
exec(self.source_code(), exec_namespace, exec_locals)
|
39
|
+
status = 'ok'
|
40
|
+
except Exception as error:
|
41
|
+
status = 'error'
|
42
|
+
exec_error = str(error)
|
43
|
+
return { 'status' : status ,
|
44
|
+
'error' : exec_error ,
|
45
|
+
'locals' : exec_locals ,
|
46
|
+
'namespace' : exec_namespace }
|
47
|
+
|
48
|
+
def info(self):
|
49
|
+
return {} # to be overwritten by calles that uses this base class
|
50
|
+
|
51
|
+
def json_data(self, target):
|
52
|
+
if type(target) is dict:
|
53
|
+
data = {}
|
54
|
+
for key, value in target.items():
|
55
|
+
data[key] = self.json_data(value)
|
56
|
+
return data
|
57
|
+
if type(target) is list:
|
58
|
+
data = []
|
59
|
+
for item in target:
|
60
|
+
data.append(self.json_data(item))
|
61
|
+
return data
|
62
|
+
if isinstance(target, Ast_Base):
|
63
|
+
return self.json_data(target.info())
|
64
|
+
return target
|
65
|
+
|
66
|
+
def jprint(self):
|
67
|
+
return self.jprint_json()
|
68
|
+
|
69
|
+
def jprint_json(self):
|
70
|
+
jprint(self.json())
|
71
|
+
|
72
|
+
def json(self):
|
73
|
+
return self.json_data(self.info())
|
74
|
+
|
75
|
+
def key(self):
|
76
|
+
return str(self)
|
77
|
+
|
78
|
+
def obj_data(self, remove_source_info=True):
|
79
|
+
data = obj_data(self.node)
|
80
|
+
if remove_source_info:
|
81
|
+
vars_to_del = ['col_offset', 'end_col_offset', 'lineno', 'end_lineno', 'type_comment']
|
82
|
+
for var_to_del in vars_to_del:
|
83
|
+
if data.get(var_to_del):
|
84
|
+
del data[var_to_del]
|
85
|
+
return data
|
86
|
+
|
87
|
+
def parse(self, target):
|
88
|
+
try:
|
89
|
+
if type(target) is str:
|
90
|
+
if is_file(target):
|
91
|
+
source = file_contents(target)
|
92
|
+
else:
|
93
|
+
source = target
|
94
|
+
else:
|
95
|
+
source = inspect.getsource(target)
|
96
|
+
code = str_dedent(source) # remove any training spaces or it won't compile
|
97
|
+
return ast.parse(code)
|
98
|
+
except SyntaxError as error:
|
99
|
+
raise syntax_error(error) from None
|
100
|
+
|
101
|
+
def print(self):
|
102
|
+
return self.print_dump()
|
103
|
+
|
104
|
+
def print_dump(self):
|
105
|
+
print(self.dump())
|
106
|
+
return self
|
107
|
+
|
108
|
+
def print_json(self):
|
109
|
+
pprint(self.json())
|
110
|
+
return self
|
111
|
+
|
112
|
+
def print_obj_info(self):
|
113
|
+
obj_info(self.node)
|
114
|
+
return self
|
115
|
+
|
116
|
+
def print_source_code(self):
|
117
|
+
print(self.source_code())
|
118
|
+
return self
|
119
|
+
|
120
|
+
def source_code(self):
|
121
|
+
return ast.unparse(self.node)
|
122
|
+
|
123
|
+
|
124
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
from osbot_utils.helpers.ast import Ast_Module
|
2
|
+
|
3
|
+
class Ast_Data:
|
4
|
+
|
5
|
+
def __init__(self, target):
|
6
|
+
if type(target) is Ast_Module:
|
7
|
+
self.target = target
|
8
|
+
else:
|
9
|
+
self.target = Ast_Module(target)
|
10
|
+
self.ast_visit = None
|
11
|
+
|
12
|
+
# def add_file(self, target):
|
13
|
+
# self.ast_load.load_file(target)
|
14
|
+
# return self
|
15
|
+
#
|
16
|
+
# def add_files(self, target):
|
17
|
+
# self.ast_load.load_files(target)
|
18
|
+
# return self
|
19
|
+
#
|
20
|
+
# def add_target(self, target):
|
21
|
+
# self.ast_load.load_target(target)
|
22
|
+
# return self
|
23
|
+
#
|
24
|
+
# def module(self):
|
25
|
+
# return self.target
|
26
|
+
#
|
27
|
+
# def stats(self):
|
28
|
+
# return self.ast_load.stats()
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import ast
|
2
|
+
|
3
|
+
from osbot_utils.helpers.Type_Registry import type_registry
|
4
|
+
from osbot_utils.utils.Files import file_contents, file_exists
|
5
|
+
from osbot_utils.utils.Functions import python_file
|
6
|
+
from osbot_utils.helpers.ast.Ast_Node import Ast_Node
|
7
|
+
|
8
|
+
#todo: check if this is stll needed since it Ast_Visit does it similar
|
9
|
+
class Ast_Load(ast.NodeVisitor):
|
10
|
+
|
11
|
+
def __init__(self):
|
12
|
+
self.ast_nodes = {}
|
13
|
+
self.files_visited = []
|
14
|
+
|
15
|
+
def load_file(self, file_path):
|
16
|
+
if file_exists(file_path):
|
17
|
+
file_visited = "/".join(file_path.split('/')[-4:])
|
18
|
+
source_code = file_contents(file_path)
|
19
|
+
tree = ast.parse(source_code)
|
20
|
+
self.visit(tree)
|
21
|
+
self.files_visited.append(file_visited)
|
22
|
+
return True
|
23
|
+
return False
|
24
|
+
|
25
|
+
def load_files(self, files_paths):
|
26
|
+
for file_path in files_paths:
|
27
|
+
self.load_file(file_path)
|
28
|
+
|
29
|
+
def load_target(self, file_path):
|
30
|
+
file = python_file(file_path)
|
31
|
+
return self.load_file(file)
|
32
|
+
|
33
|
+
def add_visited_node(self, node):
|
34
|
+
ast_node = self.create_ast_node(node)
|
35
|
+
ast_node_key = ast_node.key() #ast_node.__class__.__name__
|
36
|
+
if self.ast_nodes.get(ast_node_key) is None:
|
37
|
+
self.ast_nodes[ast_node_key] = []
|
38
|
+
self.ast_nodes[ast_node_key].append(ast_node)
|
39
|
+
|
40
|
+
def create_ast_node(self, node):
|
41
|
+
type_key = type(node)
|
42
|
+
resolved_type = type_registry.resolve(type_key)
|
43
|
+
if resolved_type:
|
44
|
+
return resolved_type(node)
|
45
|
+
return Ast_Node(node)
|
46
|
+
|
47
|
+
def generic_visit(self, node):
|
48
|
+
#print(f'entering {node.__class__.__name__}')
|
49
|
+
self.add_visited_node(node)
|
50
|
+
super().generic_visit(node)
|
51
|
+
|
52
|
+
def stats(self):
|
53
|
+
nodes = {}
|
54
|
+
node_count = 0
|
55
|
+
for key,list in self.ast_nodes.items():
|
56
|
+
key_count = len(list)
|
57
|
+
nodes[key] = key_count
|
58
|
+
node_count += key_count
|
59
|
+
stats = { 'files_visited': self.files_visited,
|
60
|
+
'node_count' : node_count,
|
61
|
+
'nodes' : nodes }
|
62
|
+
return stats
|
@@ -0,0 +1,26 @@
|
|
1
|
+
from osbot_utils.utils.Files import is_file, file_contents
|
2
|
+
from osbot_utils.helpers.ast import Ast_Module
|
3
|
+
from osbot_utils.helpers.ast.Ast_Data import Ast_Data
|
4
|
+
|
5
|
+
|
6
|
+
class Ast_Merge:
|
7
|
+
|
8
|
+
def __init__(self):
|
9
|
+
self.module = Ast_Module("") # create an empty Ast_Module
|
10
|
+
self.ast_data = Ast_Data(self.module)
|
11
|
+
|
12
|
+
def merge_file(self, file_to_merge):
|
13
|
+
if is_file(file_to_merge):
|
14
|
+
ast_module = Ast_Module(file_to_merge)
|
15
|
+
return self.merge_module(ast_module)
|
16
|
+
return False
|
17
|
+
|
18
|
+
def merge_module(self, module_to_merge):
|
19
|
+
if type(module_to_merge) is Ast_Module:
|
20
|
+
nodes_to_add = module_to_merge.node.body
|
21
|
+
self.module.node.body.extend(nodes_to_add)
|
22
|
+
return True
|
23
|
+
return False
|
24
|
+
|
25
|
+
def source_code(self):
|
26
|
+
return self.module.source_code()
|
@@ -0,0 +1,117 @@
|
|
1
|
+
import ast
|
2
|
+
from osbot_utils.helpers.Type_Registry import type_registry
|
3
|
+
from osbot_utils.utils.Lists import list_stats
|
4
|
+
from osbot_utils.helpers.ast.Ast_Base import Ast_Base
|
5
|
+
|
6
|
+
|
7
|
+
class Ast_Node(Ast_Base):
|
8
|
+
|
9
|
+
def __repr__(self):
|
10
|
+
if self.__class__ is Ast_Node:
|
11
|
+
return f"[Ast_Node][????] {self.node.__class__}"
|
12
|
+
return super().__repr__()
|
13
|
+
|
14
|
+
def ast_node(self, node):
|
15
|
+
type_key = type(node)
|
16
|
+
resolved_type = type_registry.resolve(type_key)
|
17
|
+
if resolved_type:
|
18
|
+
return resolved_type(node)
|
19
|
+
return Ast_Node(node)
|
20
|
+
|
21
|
+
def ast_value(self, value):
|
22
|
+
if value is None:
|
23
|
+
return None
|
24
|
+
if hasattr(value, '__module__') and value.__module__ == 'ast':
|
25
|
+
return self.ast_node(value)
|
26
|
+
if type(value) is list:
|
27
|
+
return self.ast_nodes(value)
|
28
|
+
return value
|
29
|
+
|
30
|
+
def ast_nodes(self, nodes):
|
31
|
+
ast_nodes = []
|
32
|
+
for node in nodes:
|
33
|
+
ast_node = self.ast_node(node)
|
34
|
+
ast_nodes.append(ast_node) # todo: see the use of .info() here (should be better to return the ast_node)
|
35
|
+
return ast_nodes
|
36
|
+
|
37
|
+
def all_ast_nodes(self):
|
38
|
+
nodes = []
|
39
|
+
for node in ast.walk(self.node):
|
40
|
+
node = self.ast_node(node)
|
41
|
+
nodes.append(node)
|
42
|
+
return nodes
|
43
|
+
|
44
|
+
def stats(self):
|
45
|
+
ast_node_types = []
|
46
|
+
node_types = []
|
47
|
+
all_keys = []
|
48
|
+
all_values = []
|
49
|
+
for ast_node in self.all_ast_nodes():
|
50
|
+
ast_node_types.append(ast_node .__class__.__name__)
|
51
|
+
node_types .append(ast_node.node.__class__.__name__)
|
52
|
+
|
53
|
+
for _,info in ast_node.info().items():
|
54
|
+
if type(info) is dict:
|
55
|
+
for key,value in info.items():
|
56
|
+
if not isinstance(value, Ast_Node):
|
57
|
+
if type(value) not in [list, dict, tuple]:
|
58
|
+
if type(value) is str:
|
59
|
+
value = value[:20].strip()
|
60
|
+
if value and 'ast.Constant' in str(value):
|
61
|
+
print(key, str(value))
|
62
|
+
all_keys .append(key)
|
63
|
+
all_values.append(value)
|
64
|
+
|
65
|
+
assert _ == ast_node.__class__.__name__ # todo: revove after refactoring
|
66
|
+
|
67
|
+
stats = {'all_keys' : list_stats(all_keys) ,
|
68
|
+
'all_values' : list_stats(all_values) ,
|
69
|
+
'ast_node_types' : list_stats(ast_node_types ) ,
|
70
|
+
'node_types' : list_stats(node_types) }
|
71
|
+
|
72
|
+
#pprint(stats)
|
73
|
+
return stats
|
74
|
+
|
75
|
+
|
76
|
+
# node vars mappings
|
77
|
+
def args (self): return self.ast_value(self.node.args )
|
78
|
+
def bases (self): return self.ast_value(self.node.bases )
|
79
|
+
def body (self): return self.ast_value(self.node.body )
|
80
|
+
def cause (self): return self.ast_value(self.node.cause )
|
81
|
+
def comparators (self): return self.ast_value(self.node.comparators )
|
82
|
+
def context_expr(self): return self.ast_value(self.node.context_expr)
|
83
|
+
def ctx (self): return self.ast_value(self.node.ctx )
|
84
|
+
def dims (self): return self.ast_value(self.node.dims )
|
85
|
+
def elt (self): return self.ast_value(self.node.elt )
|
86
|
+
def elts (self): return self.ast_value(self.node.elts )
|
87
|
+
def exc (self): return self.ast_value (self.node.exc )
|
88
|
+
def func (self): return self.ast_value(self.node.func )
|
89
|
+
def id (self): return self.ast_value(self.node.id )
|
90
|
+
def ifs (self): return self.ast_value(self.node.ifs )
|
91
|
+
def items (self): return self.ast_value(self.node.items )
|
92
|
+
def iter (self): return self.ast_value(self.node.iter )
|
93
|
+
def generators (self): return self.ast_value(self.node.generators )
|
94
|
+
def finalbody (self): return self.ast_value(self.node.finalbody )
|
95
|
+
def handlers (self): return self.ast_value(self.node.handlers )
|
96
|
+
def keys (self): return self.ast_value(self.node.keys )
|
97
|
+
def keywords (self): return self.ast_value(self.node.keywords )
|
98
|
+
def left (self): return self.ast_value(self.node.left )
|
99
|
+
def level (self): return self.ast_value(self.node.level )
|
100
|
+
def lower (self): return self.ast_value(self.node.lower )
|
101
|
+
def module (self): return self.ast_value(self.node.module )
|
102
|
+
def name (self): return self.ast_value(self.node.name )
|
103
|
+
def names (self): return self.ast_value(self.node.names )
|
104
|
+
def op (self): return self.ast_value(self.node.op )
|
105
|
+
def operand (self): return self.ast_value(self.node.operand )
|
106
|
+
def ops (self): return self.ast_value(self.node.ops )
|
107
|
+
def orelse (self): return self.ast_value(self.node.orelse )
|
108
|
+
def right (self): return self.ast_value(self.node.right )
|
109
|
+
def msg (self): return self.ast_value(self.node.msg )
|
110
|
+
def slice (self): return self.ast_value(self.node.slice )
|
111
|
+
def target (self): return self.ast_value(self.node.target )
|
112
|
+
def targets (self): return self.ast_value(self.node.targets )
|
113
|
+
def test (self): return self.ast_value(self.node.test )
|
114
|
+
def type (self): return self.ast_value(self.node.type )
|
115
|
+
def upper (self): return self.ast_value (self.node.upper )
|
116
|
+
def value (self): return self.ast_value(self.node.value )
|
117
|
+
def values (self): return self.ast_value(self.node.values )
|
@@ -0,0 +1,85 @@
|
|
1
|
+
from osbot_utils.helpers.ast import Ast_Module
|
2
|
+
from osbot_utils.helpers.ast.Ast_Base import Ast_Base
|
3
|
+
|
4
|
+
class Ast_Visit:
|
5
|
+
|
6
|
+
def __init__(self, target):
|
7
|
+
if isinstance(target, Ast_Base): # support when we pass an Ast_Node
|
8
|
+
self.ast_node = target
|
9
|
+
else:
|
10
|
+
self.ast_node = Ast_Module(target) # or when we pass source code, or a python object
|
11
|
+
self.node_handlers = {}
|
12
|
+
self.capture_handlers = {}
|
13
|
+
|
14
|
+
def __enter__(self): return self
|
15
|
+
def __exit__(self, exc_type, exc_val, exc_tb): pass
|
16
|
+
|
17
|
+
def capture(self, node_type, callback):
|
18
|
+
self.capture_handlers[node_type] = { 'callback': callback,
|
19
|
+
'nodes' : [] }
|
20
|
+
return self
|
21
|
+
|
22
|
+
def capture_calls(self, callback=None):
|
23
|
+
return self.capture('Ast_Call', callback)
|
24
|
+
|
25
|
+
def capture_imports(self, callback=None):
|
26
|
+
self.capture('Ast_Import' , callback)
|
27
|
+
self.capture('Ast_Import_From', callback)
|
28
|
+
return self
|
29
|
+
|
30
|
+
def capture_modules(self, callback=None):
|
31
|
+
return self.capture('Ast_Module', callback)
|
32
|
+
|
33
|
+
def capture_functions(self, callback=None):
|
34
|
+
return self.capture('Ast_Function_Def', callback)
|
35
|
+
|
36
|
+
def captured_nodes(self):
|
37
|
+
captured = {}
|
38
|
+
for node_type, data in self.capture_handlers.items():
|
39
|
+
captured[node_type] = data['nodes']
|
40
|
+
return captured
|
41
|
+
|
42
|
+
def invoke_capture_callbacks(self):
|
43
|
+
for node_type, data in self.capture_handlers.items():
|
44
|
+
callback = data['callback']
|
45
|
+
nodes = data['nodes']
|
46
|
+
if callback:
|
47
|
+
callback(nodes)
|
48
|
+
|
49
|
+
def on_node(self, node):
|
50
|
+
node_type = type(node).__name__
|
51
|
+
if node_type in self.capture_handlers:
|
52
|
+
self.capture_handlers[node_type]['nodes'].append(node)
|
53
|
+
if node_type in self.node_handlers:
|
54
|
+
for handler in self.node_handlers[node_type]:
|
55
|
+
handler(node)
|
56
|
+
|
57
|
+
def stats(self):
|
58
|
+
stats = {}
|
59
|
+
for node_type, data in self.capture_handlers.items():
|
60
|
+
stats[node_type] = len(data['nodes'])
|
61
|
+
return stats
|
62
|
+
|
63
|
+
def register_node_handler(self, node_type, handler):
|
64
|
+
if node_type not in self.node_handlers:
|
65
|
+
self.node_handlers[node_type] = []
|
66
|
+
self.node_handlers[node_type].append(handler)
|
67
|
+
return self
|
68
|
+
|
69
|
+
def visit(self):
|
70
|
+
self.visit_node(self.ast_node)
|
71
|
+
self.invoke_capture_callbacks()
|
72
|
+
return self
|
73
|
+
|
74
|
+
def visit_node(self, node):
|
75
|
+
if isinstance(node, Ast_Base):
|
76
|
+
self.on_node(node)
|
77
|
+
self.visit_node(node.info())
|
78
|
+
elif type(node) is dict:
|
79
|
+
for _, value in node.items():
|
80
|
+
self.visit_node(value)
|
81
|
+
elif type(node) is list:
|
82
|
+
for item in node:
|
83
|
+
self.visit_node(item)
|
84
|
+
|
85
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import ast
|
2
|
+
import inspect
|
3
|
+
from osbot_utils.utils.Str import str_dedent
|
4
|
+
|
5
|
+
|
6
|
+
class Call_Tree:
|
7
|
+
|
8
|
+
def get_called_methods(self, func):
|
9
|
+
source = inspect.getsource(func)
|
10
|
+
source = str_dedent(source)
|
11
|
+
tree = ast.parse(source)
|
12
|
+
|
13
|
+
|
14
|
+
class CallVisitor(ast.NodeVisitor):
|
15
|
+
def __init__(self):
|
16
|
+
self.called_methods = []
|
17
|
+
|
18
|
+
def visit_FunctionDef(self, node):
|
19
|
+
node.name = 'aaaaa'
|
20
|
+
print(node)
|
21
|
+
|
22
|
+
|
23
|
+
def visit_Call(self, node):
|
24
|
+
|
25
|
+
|
26
|
+
if isinstance(node.func, ast.Attribute): # This handles method calls like obj.method()
|
27
|
+
self.called_methods.append(node.func.attr)
|
28
|
+
elif isinstance(node.func, ast.Name): # This handles direct function calls like func()
|
29
|
+
self.called_methods.append(node.func.id)
|
30
|
+
self.generic_visit(node)
|
31
|
+
|
32
|
+
visitor = CallVisitor()
|
33
|
+
visitor.visit(tree)
|
34
|
+
|
35
|
+
print()
|
36
|
+
#print(ast.dump(tree, indent=2))
|
37
|
+
return ast.unparse(tree) #todo: finish implementation
|
38
|
+
return visitor.called_methods
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# note 1: this __init__.py file needs to be here (vs inside the /utils/ast/nodes folder)
|
2
|
+
# so that the methods registration happens as soon as somebody uses a method from the /utils/ast folder/package
|
3
|
+
# note 2: this is needed due to the circular dependencyes between the Ast_Node and the
|
4
|
+
# clases that use it as a base class
|
5
|
+
|
6
|
+
import ast
|
7
|
+
from osbot_utils.helpers.Type_Registry import type_registry
|
8
|
+
from osbot_utils.helpers.ast.nodes.Ast_Add import Ast_Add
|
9
|
+
from osbot_utils.helpers.ast.nodes.Ast_Alias import Ast_Alias
|
10
|
+
from osbot_utils.helpers.ast.nodes.Ast_And import Ast_And
|
11
|
+
from osbot_utils.helpers.ast.nodes.Ast_Argument import Ast_Argument
|
12
|
+
from osbot_utils.helpers.ast.nodes.Ast_Arguments import Ast_Arguments
|
13
|
+
from osbot_utils.helpers.ast.nodes.Ast_Assert import Ast_Assert
|
14
|
+
from osbot_utils.helpers.ast.nodes.Ast_Assign import Ast_Assign
|
15
|
+
from osbot_utils.helpers.ast.nodes.Ast_Attribute import Ast_Attribute
|
16
|
+
from osbot_utils.helpers.ast.nodes.Ast_Aug_Assign import Ast_Aug_Assign
|
17
|
+
from osbot_utils.helpers.ast.nodes.Ast_Bin_Op import Ast_Bin_Op
|
18
|
+
from osbot_utils.helpers.ast.nodes.Ast_Bool_Op import Ast_Bool_Op
|
19
|
+
from osbot_utils.helpers.ast.nodes.Ast_Break import Ast_Break
|
20
|
+
from osbot_utils.helpers.ast.nodes.Ast_Call import Ast_Call
|
21
|
+
from osbot_utils.helpers.ast.nodes.Ast_Class_Def import Ast_Class_Def
|
22
|
+
from osbot_utils.helpers.ast.nodes.Ast_Compare import Ast_Compare
|
23
|
+
from osbot_utils.helpers.ast.nodes.Ast_Comprehension import Ast_Comprehension
|
24
|
+
from osbot_utils.helpers.ast.nodes.Ast_Constant import Ast_Constant
|
25
|
+
from osbot_utils.helpers.ast.nodes.Ast_Continue import Ast_Continue
|
26
|
+
from osbot_utils.helpers.ast.nodes.Ast_Dict import Ast_Dict
|
27
|
+
from osbot_utils.helpers.ast.nodes.Ast_Eq import Ast_Eq
|
28
|
+
from osbot_utils.helpers.ast.nodes.Ast_Except_Handler import Ast_Except_Handler
|
29
|
+
from osbot_utils.helpers.ast.nodes.Ast_Expr import Ast_Expr
|
30
|
+
from osbot_utils.helpers.ast.nodes.Ast_For import Ast_For
|
31
|
+
from osbot_utils.helpers.ast.nodes.Ast_Function_Def import Ast_Function_Def
|
32
|
+
from osbot_utils.helpers.ast.nodes.Ast_Generator_Exp import Ast_Generator_Exp
|
33
|
+
from osbot_utils.helpers.ast.nodes.Ast_Gt import Ast_Gt
|
34
|
+
from osbot_utils.helpers.ast.nodes.Ast_GtE import Ast_GtE
|
35
|
+
from osbot_utils.helpers.ast.nodes.Ast_If import Ast_If
|
36
|
+
from osbot_utils.helpers.ast.nodes.Ast_If_Exp import Ast_If_Exp
|
37
|
+
from osbot_utils.helpers.ast.nodes.Ast_Import import Ast_Import
|
38
|
+
from osbot_utils.helpers.ast.nodes.Ast_Import_From import Ast_Import_From
|
39
|
+
from osbot_utils.helpers.ast.nodes.Ast_In import Ast_In
|
40
|
+
from osbot_utils.helpers.ast.nodes.Ast_Is import Ast_Is
|
41
|
+
from osbot_utils.helpers.ast.nodes.Ast_Is_Not import Ast_Is_Not
|
42
|
+
from osbot_utils.helpers.ast.nodes.Ast_Keyword import Ast_Keyword
|
43
|
+
from osbot_utils.helpers.ast.nodes.Ast_Lambda import Ast_Lambda
|
44
|
+
from osbot_utils.helpers.ast.nodes.Ast_List import Ast_List
|
45
|
+
from osbot_utils.helpers.ast.nodes.Ast_List_Comp import Ast_List_Comp
|
46
|
+
from osbot_utils.helpers.ast.nodes.Ast_Load import Ast_Load
|
47
|
+
from osbot_utils.helpers.ast.nodes.Ast_Lt import Ast_Lt
|
48
|
+
from osbot_utils.helpers.ast.nodes.Ast_LtE import Ast_LtE
|
49
|
+
from osbot_utils.helpers.ast.nodes.Ast_Mod import Ast_Mod
|
50
|
+
from osbot_utils.helpers.ast.nodes.Ast_Module import Ast_Module
|
51
|
+
from osbot_utils.helpers.ast.nodes.Ast_Mult import Ast_Mult
|
52
|
+
from osbot_utils.helpers.ast.nodes.Ast_Name import Ast_Name
|
53
|
+
from osbot_utils.helpers.ast.nodes.Ast_Not import Ast_Not
|
54
|
+
from osbot_utils.helpers.ast.nodes.Ast_Not_Eq import Ast_Not_Eq
|
55
|
+
from osbot_utils.helpers.ast.nodes.Ast_Not_In import Ast_Not_In
|
56
|
+
from osbot_utils.helpers.ast.nodes.Ast_Or import Ast_Or
|
57
|
+
from osbot_utils.helpers.ast.nodes.Ast_Pass import Ast_Pass
|
58
|
+
from osbot_utils.helpers.ast.nodes.Ast_Pow import Ast_Pow
|
59
|
+
from osbot_utils.helpers.ast.nodes.Ast_Raise import Ast_Raise
|
60
|
+
from osbot_utils.helpers.ast.nodes.Ast_Return import Ast_Return
|
61
|
+
from osbot_utils.helpers.ast.nodes.Ast_Set import Ast_Set
|
62
|
+
from osbot_utils.helpers.ast.nodes.Ast_Slice import Ast_Slice
|
63
|
+
from osbot_utils.helpers.ast.nodes.Ast_Starred import Ast_Starred
|
64
|
+
from osbot_utils.helpers.ast.nodes.Ast_Store import Ast_Store
|
65
|
+
from osbot_utils.helpers.ast.nodes.Ast_Sub import Ast_Sub
|
66
|
+
from osbot_utils.helpers.ast.nodes.Ast_Subscript import Ast_Subscript
|
67
|
+
from osbot_utils.helpers.ast.nodes.Ast_Try import Ast_Try
|
68
|
+
from osbot_utils.helpers.ast.nodes.Ast_Tuple import Ast_Tuple
|
69
|
+
from osbot_utils.helpers.ast.nodes.Ast_Unary_Op import Ast_Unary_Op
|
70
|
+
from osbot_utils.helpers.ast.nodes.Ast_While import Ast_While
|
71
|
+
from osbot_utils.helpers.ast.nodes.Ast_With import Ast_With
|
72
|
+
from osbot_utils.helpers.ast.nodes.Ast_With_Item import Ast_With_Item
|
73
|
+
from osbot_utils.helpers.ast.nodes.Ast_Yield import Ast_Yield
|
74
|
+
|
75
|
+
ast_types = {
|
76
|
+
ast.Add : Ast_Add ,
|
77
|
+
ast.alias : Ast_Alias ,
|
78
|
+
ast.And : Ast_And ,
|
79
|
+
ast.Assert : Ast_Assert ,
|
80
|
+
ast.Assign : Ast_Assign ,
|
81
|
+
ast.Attribute : Ast_Attribute ,
|
82
|
+
ast.arg : Ast_Argument ,
|
83
|
+
ast.arguments : Ast_Arguments ,
|
84
|
+
ast.AugAssign : Ast_Aug_Assign ,
|
85
|
+
ast.BinOp : Ast_Bin_Op ,
|
86
|
+
ast.BoolOp : Ast_Bool_Op ,
|
87
|
+
ast.Break : Ast_Break ,
|
88
|
+
ast.Call : Ast_Call ,
|
89
|
+
ast.ClassDef : Ast_Class_Def ,
|
90
|
+
ast.Compare : Ast_Compare ,
|
91
|
+
ast.Constant : Ast_Constant ,
|
92
|
+
ast.Continue : Ast_Continue ,
|
93
|
+
ast.comprehension : Ast_Comprehension ,
|
94
|
+
ast.Dict : Ast_Dict ,
|
95
|
+
ast.ExceptHandler : Ast_Except_Handler,
|
96
|
+
ast.Expr : Ast_Expr ,
|
97
|
+
ast.Eq : Ast_Eq ,
|
98
|
+
ast.Gt : Ast_Gt ,
|
99
|
+
ast.GtE : Ast_GtE ,
|
100
|
+
ast.Import : Ast_Import ,
|
101
|
+
ast.ImportFrom : Ast_Import_From ,
|
102
|
+
ast.In : Ast_In ,
|
103
|
+
ast.For : Ast_For ,
|
104
|
+
ast.FunctionDef : Ast_Function_Def ,
|
105
|
+
ast.GeneratorExp : Ast_Generator_Exp ,
|
106
|
+
ast.If : Ast_If ,
|
107
|
+
ast.IfExp : Ast_If_Exp ,
|
108
|
+
ast.Is : Ast_Is ,
|
109
|
+
ast.IsNot : Ast_Is_Not ,
|
110
|
+
ast.keyword : Ast_Keyword ,
|
111
|
+
ast.Lambda : Ast_Lambda ,
|
112
|
+
ast.List : Ast_List ,
|
113
|
+
ast.ListComp : Ast_List_Comp ,
|
114
|
+
ast.Lt : Ast_Lt ,
|
115
|
+
ast.LtE : Ast_LtE ,
|
116
|
+
ast.Load : Ast_Load ,
|
117
|
+
ast.Mod : Ast_Mod ,
|
118
|
+
ast.Module : Ast_Module ,
|
119
|
+
ast.Mult : Ast_Mult ,
|
120
|
+
ast.Name : Ast_Name ,
|
121
|
+
ast.Not : Ast_Not ,
|
122
|
+
ast.NotEq : Ast_Not_Eq ,
|
123
|
+
ast.NotIn : Ast_Not_In ,
|
124
|
+
ast.Or : Ast_Or ,
|
125
|
+
ast.Pass : Ast_Pass ,
|
126
|
+
ast.Pow : Ast_Pow ,
|
127
|
+
ast.Raise : Ast_Raise ,
|
128
|
+
ast.Return : Ast_Return ,
|
129
|
+
ast.Slice : Ast_Slice ,
|
130
|
+
ast.Starred : Ast_Starred ,
|
131
|
+
ast.Store : Ast_Store ,
|
132
|
+
ast.Set : Ast_Set ,
|
133
|
+
ast.Sub : Ast_Sub ,
|
134
|
+
ast.Subscript : Ast_Subscript ,
|
135
|
+
ast.Try : Ast_Try ,
|
136
|
+
ast.Tuple : Ast_Tuple ,
|
137
|
+
ast.UnaryOp : Ast_Unary_Op ,
|
138
|
+
ast.While : Ast_While ,
|
139
|
+
ast.With : Ast_With ,
|
140
|
+
ast.withitem : Ast_With_Item ,
|
141
|
+
ast.Yield : Ast_Yield ,
|
142
|
+
}
|
143
|
+
|
144
|
+
for key, value in ast_types.items():
|
145
|
+
type_registry.register(key, value)
|