retracesoftware-proxy 0.1.1__py3-none-any.whl → 0.1.2__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.
- retracesoftware/install/patcher.py +21 -2
- retracesoftware/install/record.py +7 -0
- retracesoftware/install/tracer.py +16 -14
- retracesoftware/proxy/gateway.py +3 -112
- retracesoftware/proxy/proxyfactory.py +194 -194
- retracesoftware/proxy/proxysystem.py +88 -67
- retracesoftware/proxy/proxytype.py +213 -85
- retracesoftware/proxy/record.py +80 -83
- retracesoftware/proxy/replay.py +57 -33
- retracesoftware/proxy/stubfactory.py +141 -0
- retracesoftware/proxy/thread.py +1 -1
- {retracesoftware_proxy-0.1.1.dist-info → retracesoftware_proxy-0.1.2.dist-info}/METADATA +1 -1
- retracesoftware_proxy-0.1.2.dist-info/RECORD +27 -0
- retracesoftware_proxy-0.1.1.dist-info/RECORD +0 -26
- {retracesoftware_proxy-0.1.1.dist-info → retracesoftware_proxy-0.1.2.dist-info}/WHEEL +0 -0
- {retracesoftware_proxy-0.1.1.dist-info → retracesoftware_proxy-0.1.2.dist-info}/top_level.txt +0 -0
|
@@ -340,7 +340,9 @@ class Patcher:
|
|
|
340
340
|
def patch_extension_exec(self, exec):
|
|
341
341
|
|
|
342
342
|
def wrapper(module):
|
|
343
|
-
|
|
343
|
+
with self.thread_state.select('internal'):
|
|
344
|
+
res = exec(module)
|
|
345
|
+
|
|
344
346
|
self(module)
|
|
345
347
|
return res
|
|
346
348
|
|
|
@@ -454,6 +456,23 @@ def env_truthy(key, default=False):
|
|
|
454
456
|
return default
|
|
455
457
|
return value.strip().lower() in ("1", "true", "yes", "on")
|
|
456
458
|
|
|
459
|
+
class ImmutableTypes(set):
|
|
460
|
+
def __init__(self, *args, **kwargs):
|
|
461
|
+
super().__init__(*args, **kwargs)
|
|
462
|
+
|
|
463
|
+
def __contains__(self, item):
|
|
464
|
+
assert isinstance(item, type)
|
|
465
|
+
|
|
466
|
+
if super().__contains__(item):
|
|
467
|
+
return True
|
|
468
|
+
|
|
469
|
+
for elem in self:
|
|
470
|
+
if issubclass(item, elem):
|
|
471
|
+
self.add(item)
|
|
472
|
+
return True
|
|
473
|
+
|
|
474
|
+
return False
|
|
475
|
+
|
|
457
476
|
def install(mode):
|
|
458
477
|
|
|
459
478
|
create_system = None
|
|
@@ -471,7 +490,7 @@ def install(mode):
|
|
|
471
490
|
|
|
472
491
|
thread_state = utils.ThreadState(*states)
|
|
473
492
|
|
|
474
|
-
immutable_types =
|
|
493
|
+
immutable_types = ImmutableTypes()
|
|
475
494
|
|
|
476
495
|
if 'RETRACE_RECORDING_PATH' in os.environ:
|
|
477
496
|
config['recording_path'] = os.environ['RETRACE_RECORDING_PATH']
|
|
@@ -42,6 +42,13 @@ def tracing_level(config):
|
|
|
42
42
|
# level = os.environ.get('RETRACE_DEBUG', config['default_tracing_level'])
|
|
43
43
|
# return config['tracing_levels'].get(level, {})
|
|
44
44
|
|
|
45
|
+
def merge_config(base, override):
|
|
46
|
+
if isinstance(base, dict) and isinstance(override, dict):
|
|
47
|
+
...
|
|
48
|
+
else:
|
|
49
|
+
return override
|
|
50
|
+
|
|
51
|
+
|
|
45
52
|
def record_system(thread_state, immutable_types, config):
|
|
46
53
|
|
|
47
54
|
recording_path = create_recording_path(config['recording_path'])
|
|
@@ -24,28 +24,30 @@ class Tracer:
|
|
|
24
24
|
|
|
25
25
|
cls = functional.typeof(obj)
|
|
26
26
|
|
|
27
|
+
if issubclass(cls, Proxy):
|
|
28
|
+
return str(cls)
|
|
29
|
+
|
|
27
30
|
if issubclass(cls, (int, str)):
|
|
28
31
|
return obj
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
return 'FOO!!!!'
|
|
33
|
+
return str(cls)
|
|
32
34
|
|
|
33
|
-
if issubclass(cls, Proxy):
|
|
34
|
-
|
|
35
|
+
# if issubclass(cls, Proxy):
|
|
36
|
+
# return f'<Proxy>'
|
|
35
37
|
|
|
36
|
-
if issubclass(cls, types.TracebackType):
|
|
37
|
-
|
|
38
|
+
# if issubclass(cls, types.TracebackType):
|
|
39
|
+
# return '<traceback>'
|
|
38
40
|
|
|
39
|
-
elif issubclass(cls, utils.wrapped_function):
|
|
40
|
-
|
|
41
|
+
# elif issubclass(cls, utils.wrapped_function):
|
|
42
|
+
# return utils.unwrap(obj).__name__
|
|
41
43
|
|
|
42
|
-
elif hasattr(obj, '__module__') and hasattr(obj, '__name__'):
|
|
43
|
-
return f'{obj.__module__}.{obj.__name__}'
|
|
44
|
-
# elif isinstance(obj, type):
|
|
44
|
+
# elif hasattr(obj, '__module__') and hasattr(obj, '__name__'):
|
|
45
45
|
# return f'{obj.__module__}.{obj.__name__}'
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
# # elif isinstance(obj, type):
|
|
47
|
+
# # return f'{obj.__module__}.{obj.__name__}'
|
|
48
|
+
# else:
|
|
49
|
+
# return '<other>'
|
|
50
|
+
# # return f'instance type: {str(self.serialize(type(obj)))}'
|
|
49
51
|
except:
|
|
50
52
|
print("ERROR in tracer serialize!!!!")
|
|
51
53
|
os._exit(1)
|
retracesoftware/proxy/gateway.py
CHANGED
|
@@ -9,9 +9,9 @@ from retracesoftware.proxy.proxytype import ExtendingProxy
|
|
|
9
9
|
# transform = functional.walker(utils.try_unwrap),
|
|
10
10
|
# function = functional.apply)
|
|
11
11
|
|
|
12
|
-
def adapter(
|
|
12
|
+
def adapter(function,
|
|
13
|
+
proxy_input,
|
|
13
14
|
proxy_output,
|
|
14
|
-
function,
|
|
15
15
|
on_call = None,
|
|
16
16
|
on_result = None,
|
|
17
17
|
on_error = None):
|
|
@@ -31,17 +31,7 @@ def adapter(proxy_input,
|
|
|
31
31
|
|
|
32
32
|
return function
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
# return {
|
|
36
|
-
# 'proxy': None
|
|
37
|
-
# 'proxytype': None,
|
|
38
|
-
# 'on_call': None,
|
|
39
|
-
# 'on_result': None,
|
|
40
|
-
# 'on_error': None,
|
|
41
|
-
# 'apply': functional.apply,
|
|
42
|
-
# }
|
|
43
|
-
|
|
44
|
-
def adapter_pair1(int, ext):
|
|
34
|
+
def adapter_pair(int, ext):
|
|
45
35
|
return (
|
|
46
36
|
adapter(
|
|
47
37
|
function = ext.apply,
|
|
@@ -57,102 +47,3 @@ def adapter_pair1(int, ext):
|
|
|
57
47
|
on_call = int.on_call,
|
|
58
48
|
on_result = int.on_result,
|
|
59
49
|
on_error = int.on_error))
|
|
60
|
-
|
|
61
|
-
# def adapter_pair(proxy_int,
|
|
62
|
-
# proxy_ext,
|
|
63
|
-
# int_apply,
|
|
64
|
-
# ext_apply,
|
|
65
|
-
# tracer,
|
|
66
|
-
# on_int_call,
|
|
67
|
-
# on_ext_result,
|
|
68
|
-
# on_ext_error):
|
|
69
|
-
# return (
|
|
70
|
-
# adapter(
|
|
71
|
-
# function = ext_apply,
|
|
72
|
-
# proxy_input = proxy_int,
|
|
73
|
-
# proxy_output = proxy_ext,
|
|
74
|
-
# on_call = tracer('proxy.ext.call'),
|
|
75
|
-
# on_result = on_ext_result,
|
|
76
|
-
# on_error = on_ext_error),
|
|
77
|
-
# # on_result = tracer('proxy.ext.result', on_ext_result),
|
|
78
|
-
# # on_error = tracer('proxy.ext.error', on_ext_error)),
|
|
79
|
-
# adapter(
|
|
80
|
-
# function = int_apply,
|
|
81
|
-
# proxy_input = proxy_ext,
|
|
82
|
-
# proxy_output = proxy_int,
|
|
83
|
-
# on_call = tracer('proxy.int.call', on_int_call),
|
|
84
|
-
# on_result = tracer('proxy.int.result'),
|
|
85
|
-
# on_error = tracer('proxy.int.error')))
|
|
86
|
-
|
|
87
|
-
# def proxy(proxytype):
|
|
88
|
-
# def set_type(cls, obj):
|
|
89
|
-
# obj.__class__ = cls
|
|
90
|
-
# return obj
|
|
91
|
-
|
|
92
|
-
# def can_set_type(cls, obj): return issubclass(cls, ExtendingProxy)
|
|
93
|
-
|
|
94
|
-
# create = functional.if_then_else(can_set_type, set_type, utils.create_wrapped)
|
|
95
|
-
|
|
96
|
-
# return functional.spread(
|
|
97
|
-
# create,
|
|
98
|
-
# functional.sequence(functional.typeof, proxytype),
|
|
99
|
-
# None)
|
|
100
|
-
|
|
101
|
-
# functional.sequence(functional.typeof, proxytype)
|
|
102
|
-
# lambda obj: functional.partial(utils.create_wrapped(proxytype(type(obj)))
|
|
103
|
-
# return lambda obj: utils.create_wrapped(proxytype(type(obj)), obj)
|
|
104
|
-
# return functional.selfapply(functional.sequence(functional.typeof, proxytype))
|
|
105
|
-
|
|
106
|
-
# def maybe_proxy(proxytype):
|
|
107
|
-
# return functional.if_then_else(
|
|
108
|
-
# functional.isinstanceof(utils.Wrapped),
|
|
109
|
-
# utils.unwrap,
|
|
110
|
-
# proxy(functional.memoize_one_arg(proxytype)))
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
# def gateway_pair(thread_state,
|
|
114
|
-
# tracer,
|
|
115
|
-
# immutable_types,
|
|
116
|
-
# int_proxytype,
|
|
117
|
-
# ext_proxytype,
|
|
118
|
-
# wrap_int_to_ext = functional.identity,
|
|
119
|
-
# int_apply = functional.apply,
|
|
120
|
-
# ext_apply = functional.apply,
|
|
121
|
-
# on_int_call = None,
|
|
122
|
-
# on_ext_result = None,
|
|
123
|
-
# on_ext_error = None):
|
|
124
|
-
|
|
125
|
-
# def is_immutable_type(cls):
|
|
126
|
-
# return issubclass(cls, tuple(immutable_types))
|
|
127
|
-
|
|
128
|
-
# is_immutable = functional.sequence(functional.typeof, functional.memoize_one_arg(is_immutable_type))
|
|
129
|
-
|
|
130
|
-
# def proxyfactory(proxytype):
|
|
131
|
-
# return functional.walker(functional.when_not(is_immutable, maybe_proxy(proxytype)))
|
|
132
|
-
|
|
133
|
-
# # int_to_ext_dispatch = thread_state.dispatch(tracer('proxy.int.disabled.event', unproxy_execute))
|
|
134
|
-
# # ext_to_int_dispatch = thread_state.dispatch(tracer('proxy.ext.disabled.event', unproxy_execute))
|
|
135
|
-
|
|
136
|
-
# int_to_ext, ext_to_int = adapter_pair(
|
|
137
|
-
# proxy_int = proxyfactory(int_proxytype),
|
|
138
|
-
# proxy_ext = proxyfactory(ext_proxytype),
|
|
139
|
-
# int_apply = thread_state.wrap(desired_state = 'internal', function = int_apply),
|
|
140
|
-
# ext_apply = thread_state.wrap(desired_state = 'external', function = ext_apply),
|
|
141
|
-
# tracer = tracer,
|
|
142
|
-
# on_int_call = on_int_call,
|
|
143
|
-
# on_ext_result = on_ext_result,
|
|
144
|
-
# on_ext_error = on_ext_error)
|
|
145
|
-
|
|
146
|
-
# # thread_state.set_dispatch(int_to_ext_dispatch, external = functional.apply, internal = wrap_int_to_ext(tracer('proxy.int_to_ext.stack', int_to_ext)))
|
|
147
|
-
# # thread_state.set_dispatch(int_to_ext_dispatch, external = functional.apply, internal = wrap_int_to_ext(int_to_ext))
|
|
148
|
-
# # thread_state.set_dispatch(ext_to_int_dispatch, internal = functional.apply, external = tracer('proxy.ext_to_int.wrap', ext_to_int))
|
|
149
|
-
|
|
150
|
-
# def gateway(name, internal = functional.apply, external = functional.apply):
|
|
151
|
-
# default = tracer(name, unproxy_execute)
|
|
152
|
-
# return thread_state.dispatch(default, internal = internal, external = external)
|
|
153
|
-
|
|
154
|
-
# return (gateway('proxy.int.disabled.event',
|
|
155
|
-
# internal = wrap_int_to_ext(int_to_ext)),
|
|
156
|
-
# gateway('proxy.ext.disabled.event',
|
|
157
|
-
# external = tracer('proxy.ext_to_int.wrap', ext_to_int)))
|
|
158
|
-
|