retracesoftware-proxy 0.1.1__py3-none-any.whl → 0.1.3__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.
@@ -100,12 +100,6 @@ def replaying_proxy_factory(thread_state, is_immutable_type, tracer, next, bind,
100
100
  on_result = tracer('proxy.int.result'),
101
101
  on_error = tracer('proxy.int.error'),
102
102
  function = handler)
103
-
104
- def foo(cls):
105
- print(f"IN FOO {cls}")
106
- inst = utils.create_stub_object(cls)
107
- print(f'FOO {cls} {type(inst)}')
108
- return inst
109
103
 
110
104
  # def is_stub_type(obj):
111
105
  # return type(obj) == type and issubclass(obj, (WrappingProxy, ExtendingProxy))
@@ -113,7 +107,7 @@ def replaying_proxy_factory(thread_state, is_immutable_type, tracer, next, bind,
113
107
  def is_stub_type(obj):
114
108
  return type(obj) == type
115
109
 
116
- create_stubs = functional.walker(functional.when(is_stub_type, foo))
110
+ create_stubs = functional.walker(functional.when(is_stub_type, utils.create_stub_object))
117
111
  # create_stubs = functional.walker(functional.when(is_stub_type, utils.create_stub_object))
118
112
 
119
113
  def wrap_ext_call(handler):
@@ -96,7 +96,7 @@ def container_replace(container, old, new):
96
96
  container_replace(container, old, new)
97
97
  else:
98
98
  for key,value in container.items():
99
- if value is old:
99
+ if key != '__retrace_unproxied__' and value is old:
100
100
  container[key] = new
101
101
  return True
102
102
  elif isinstance(container, list):
@@ -340,7 +340,9 @@ class Patcher:
340
340
  def patch_extension_exec(self, exec):
341
341
 
342
342
  def wrapper(module):
343
- res = exec(module)
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 = set()
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'])
@@ -31,7 +31,8 @@ def replace(container, old, new):
31
31
  replace(container, old, new)
32
32
  else:
33
33
  for key,value in container.items():
34
- if value is old:
34
+ if key != '__retrace_unproxied__' and value is old:
35
+ print(f'FOO replacing: {key} {old} {new}')
35
36
  container[key] = new
36
37
 
37
38
  elif isinstance(container, list):
@@ -35,7 +35,7 @@ def replay_system(thread_state, immutable_types, config):
35
35
 
36
36
  recording_path = Path(latest_from_pattern(config['recording_path']))
37
37
 
38
- print(f"replay running against path: {recording_path}")
38
+ # print(f"replay running against path: {recording_path}")
39
39
 
40
40
  globals.recording_path = globals.RecordingPath(recording_path)
41
41
 
@@ -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
- else:
31
- return 'FOO!!!!'
33
+ return str(cls)
32
34
 
33
- if issubclass(cls, Proxy):
34
- return f'<Proxy>'
35
+ # if issubclass(cls, Proxy):
36
+ # return f'<Proxy>'
35
37
 
36
- if issubclass(cls, types.TracebackType):
37
- return '<traceback>'
38
+ # if issubclass(cls, types.TracebackType):
39
+ # return '<traceback>'
38
40
 
39
- elif issubclass(cls, utils.wrapped_function):
40
- return utils.unwrap(obj).__name__
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
- else:
47
- return '<other>'
48
- # return f'instance type: {str(self.serialize(type(obj)))}'
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)
@@ -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(proxy_input,
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
- # def callbacks():
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
-