retracesoftware-proxy 0.1.2__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):
@@ -462,7 +462,7 @@ class ImmutableTypes(set):
462
462
 
463
463
  def __contains__(self, item):
464
464
  assert isinstance(item, type)
465
-
465
+
466
466
  if super().__contains__(item):
467
467
  return True
468
468
 
@@ -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
 
@@ -123,7 +123,6 @@ class ProxySystem:
123
123
  bind = self.bind)
124
124
 
125
125
  def dynamic_ext_proxytype(self, cls):
126
- print(f'dynamic_ext_proxytype: {cls} {self.thread_state.value}')
127
126
 
128
127
  proxytype = dynamic_proxytype(
129
128
  handler = self.ext_dispatch,
@@ -176,27 +175,23 @@ class ProxySystem:
176
175
  assert not isinstance(obj, Proxy)
177
176
  assert not isinstance(obj, utils.wrapped_function)
178
177
 
179
- try:
180
- print(f'STARTING PROXYING: {obj}')
181
- if type(obj) == type:
182
- if obj in self.immutable_types or issubclass(obj, tuple):
183
- return obj
184
-
185
- return self.ext_proxytype(obj)
186
-
187
- elif type(obj) in self.immutable_types:
178
+ if type(obj) == type:
179
+ if obj in self.immutable_types or issubclass(obj, tuple):
188
180
  return obj
189
181
 
190
- elif is_function_type(type(obj)):
191
-
192
- return self.thread_state.dispatch(
193
- obj,
194
- internal = self.proxy_function(obj))
182
+ return self.ext_proxytype(obj)
195
183
 
196
- else:
197
- proxytype = dynamic_proxytype(handler = self.ext_dispatch, cls = type(obj))
184
+ elif type(obj) in self.immutable_types:
185
+ return obj
186
+
187
+ elif is_function_type(type(obj)):
188
+
189
+ return self.thread_state.dispatch(
190
+ obj,
191
+ internal = self.proxy_function(obj))
192
+
193
+ else:
194
+ proxytype = dynamic_proxytype(handler = self.ext_dispatch, cls = type(obj))
198
195
 
199
- return utils.create_wrapped(proxytype, obj)
200
- # raise Exception(f'object {obj} was not proxied as its not a extensible type and is not callable')
201
- finally:
202
- print(f'FINISHED PROXYING: {obj}')
196
+ return utils.create_wrapped(proxytype, obj)
197
+ # raise Exception(f'object {obj} was not proxied as its not a extensible type and is not callable')
@@ -196,8 +196,6 @@ class ExtendingDescriptorProxy:
196
196
 
197
197
  def dynamic_proxytype(handler, cls):
198
198
 
199
- print(f'Creating dynamic_proxytype from {cls} {cls.__dict__}')
200
-
201
199
  assert not issubclass(cls, Proxy)
202
200
  assert not issubclass(cls, BaseException)
203
201
 
@@ -209,10 +207,7 @@ def dynamic_proxytype(handler, cls):
209
207
  if name not in blacklist:
210
208
  value = getattr(cls, name)
211
209
  if is_descriptor(value):
212
- print(f'Adding: {name} {value} {type(value).__mro__}')
213
-
214
210
  if utils.is_method_descriptor(value):
215
- print(f'Adding method descriptor: {name} {value}')
216
211
  spec[name] = utils.wrapped_function(handler = handler, target = value)
217
212
  else:
218
213
  spec[name] = DescriptorProxy(handler = handler, target = value)
@@ -254,8 +249,6 @@ def dynamic_from_extended(cls):
254
249
  target_type = functional.sequence(utils.unwrap, functional.typeof)
255
250
  spec['__class__'] = property(target_type)
256
251
 
257
- print(f'dynamic_from_extended {spec}')
258
-
259
252
  return type(name, (utils.Wrapped, DynamicProxy), spec)
260
253
 
261
254
 
@@ -269,8 +262,6 @@ def instantiable_dynamic_proxytype(handler, cls, thread_state, create_stub = Fal
269
262
  return instance
270
263
 
271
264
  def __new__(proxytype, *args, **kwargs):
272
- print(f'instantiable_dynamic_proxytype: {cls}')
273
-
274
265
  instance = utils.create_stub_object(cls) if create_stub else cls(*args, **kwargs)
275
266
  return utils.create_wrapped(proxytype, instance)
276
267
 
@@ -317,19 +308,24 @@ blacklist = ['__getattribute__', '__hash__', '__del__', '__dict__']
317
308
  # cls.__new__ = thread_state.dispatch(unproxied__new__, internal = proxied__new__)
318
309
 
319
310
  def create_unproxied_type(cls):
320
-
321
311
  def unproxy_type(cls):
322
312
  return cls.__dict__.get('__retrace_unproxied__', cls)
323
313
 
324
- return type(cls.__name__, tuple(map(unproxy_type, cls.__bases__)), dict(cls.__dict__))
314
+ bases = tuple(map(unproxy_type, cls.__bases__))
315
+ slots = dict(cls.__dict__)
316
+ del slots['__init_subclass__']
317
+ return type(cls.__name__, tuple(bases), slots)
325
318
 
326
319
  def extending_proxytype(cls, base, thread_state, ext_handler, int_handler, on_subclass_new):
327
320
 
321
+ # assert cls is base
328
322
  assert not issubclass(cls, BaseException)
323
+ assert not issubclass(cls, ExtendingProxy)
329
324
 
330
325
  def init_subclass(subclass, **kwargs):
331
- # print(f'In init_subclass: {subclass} {kwargs}')
332
- subclass.__retrace_unproxied__ = create_unproxied_type(subclass)
326
+ print(f'In init_subclass: {subclass} {kwargs}')
327
+ unproxied = create_unproxied_type(subclass)
328
+ subclass.__retrace_unproxied__ = unproxied
333
329
 
334
330
  proxy_method_descriptors(cls = subclass, handler = int_handler)
335
331
 
@@ -337,6 +333,8 @@ def extending_proxytype(cls, base, thread_state, ext_handler, int_handler, on_su
337
333
  subclass.__new__ = functional.sequence(subclass.__new__, functional.side_effect(on_subclass_new))
338
334
  subclass.__bases__ = subclass.__bases__ + (InternalProxy,)
339
335
 
336
+ assert not issubclass(subclass.__retrace_unproxied__, ExtendingProxy)
337
+
340
338
  slots = { "__slots__": (),
341
339
  "__retrace_unproxied__": cls,
342
340
  "__module__": cls.__module__,
@@ -353,6 +351,8 @@ def extending_proxytype(cls, base, thread_state, ext_handler, int_handler, on_su
353
351
  elif is_descriptor(value):
354
352
  descriptors.append(name)
355
353
 
354
+ slots['__retrace_unproxied__'] = cls
355
+
356
356
  extended = type(cls.__name__, (base, ExtendingProxy), slots)
357
357
 
358
358
  for name in descriptors:
@@ -364,56 +364,9 @@ def extending_proxytype(cls, base, thread_state, ext_handler, int_handler, on_su
364
364
 
365
365
  extended.__new__ = thread_state.dispatch(unproxied__new__, internal = base.__new__)
366
366
 
367
- return extended
368
-
369
-
370
- # def stubtype(cls, result, thread_state, handler):
371
-
372
- # name = f'retrace.stub.{cls.__module__}.{cls.__name__}'
373
-
374
- # slots = {}
375
-
376
- # def wrap(name):
377
- # return utils.wrapped_function(
378
- # handler = handler,
379
- # target = StubMethodDescriptor(name = name, result = result))
380
-
381
- # for name,value in superdict(cls).items():
382
- # if name not in blacklist:
383
- # if is_method_descriptor(value):
384
- # slots[name] = wrap(name)
385
- # elif is_descriptor(value):
386
- # slots[name] = DescriptorStub(handler = handler, name = name)
387
-
388
- # def disabled__new__(subcls, *args, **kwargs):
389
- # instance = cls.__new__(subcls.__retrace_unproxied__, *args, **kwargs)
390
- # instance.__init__(*args, **kwargs)
391
- # return instance
367
+ assert not issubclass(extended.__retrace_unproxied__, ExtendingProxy)
368
+ assert extended.__dict__['__retrace_unproxied__'] is extended.__retrace_unproxied__
369
+ print(f'FOO: {extended} {id(extended)} {id(extended.__retrace_unproxied__)}')
370
+ # breakpoint()
392
371
 
393
- # stub = type(name, (Stub,), slots)
394
-
395
- # stub.__new__ = thread_state.dispatch(disabled__new__, internal = stub.__new__, external = stub.__new__)
396
-
397
- # stub.__retrace_unproxied__ = cls
398
-
399
- # return stub
400
-
401
-
402
-
403
-
404
-
405
- # def make_extensible(cls, handler, on_new):
406
-
407
- # cls.__retrace_unproxied__ = cls.__base__
408
-
409
- # def init_subclass(*args, **kwargs):
410
- # print(f'In init_subclass: {args} {kwargs}')
411
- # # subclass.__retrace_unproxied__ = create_unproxied_type(subclass)
412
-
413
- # # proxy_method_descriptors(cls = subclass, handler = handler)
414
-
415
- # # if not issubclass(subclass, InternalProxy):
416
- # # cls.__new__ = functional.compose(cls.__new__, functional.side_effect(on_new))
417
- # # cls.__bases__ = cls.__bases__ + (InternalProxy,)
418
-
419
- # cls.__init_subclass__ = init_subclass
372
+ return extended
@@ -84,10 +84,10 @@ class RecordProxySystem(ProxySystem):
84
84
 
85
85
  self.writer = stream.writer(path)
86
86
 
87
- w = self.writer.handle('TRACE')
88
- def trace_writer(*args):
89
- print(f'Trace: {args}')
90
- w(*args)
87
+ # w = self.writer.handle('TRACE')
88
+ # def trace_writer(*args):
89
+ # print(f'Trace: {args}')
90
+ # w(*args)
91
91
 
92
92
  self.extended_types = {}
93
93
  self.bindings = utils.id_dict()
@@ -110,7 +110,7 @@ class RecordProxySystem(ProxySystem):
110
110
 
111
111
  def watch(f): return functional.either(thread_switch_monitor, f)
112
112
 
113
- tracer = Tracer(tracing_config, writer = trace_writer)
113
+ tracer = Tracer(tracing_config, writer = self.writer.handle('TRACE'))
114
114
 
115
115
  self.wrap_int_to_ext = watch
116
116
 
@@ -25,7 +25,6 @@ class ReplayError(RetraceError):
25
25
  class ReplayProxySystem(ProxySystem):
26
26
 
27
27
  def stubtype(self, cls):
28
- print(f'In stubtype, class: {cls}')
29
28
  assert not issubclass(cls, Proxy)
30
29
 
31
30
  return dynamic_proxytype(handler = self.ext_handler, cls = cls)
@@ -63,7 +62,6 @@ class ReplayProxySystem(ProxySystem):
63
62
  err_value = self.messages()
64
63
  utils.raise_exception(err_type, err_value)
65
64
  else:
66
- if type(next) is str: print('FOOBAR!!!!')
67
65
  assert type(next) is not str
68
66
  return next
69
67
 
@@ -105,7 +105,6 @@ class StubFactory:
105
105
 
106
106
  def create_stubtype(self, spec):
107
107
 
108
- print(f'FOOO: {spec.module}')
109
108
  slots = {
110
109
  '__module__': spec.module,
111
110
  '__qualname__': spec.name,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: retracesoftware_proxy
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  License: Apache-2.0
5
5
  Requires-Dist: retracesoftware_utils
6
6
  Requires-Dist: retracesoftware_functional
@@ -4,24 +4,24 @@ retracesoftware/install/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
4
4
  retracesoftware/install/config.py,sha256=EzE5ifQF2lo--hu2njI4T0FJ-zlnWDJV6i7x0DMkVTw,1364
5
5
  retracesoftware/install/edgecases.py,sha256=NR3lyvad9sRsyeDv_Ya8V4xMgPsMPOi9rMcnFOJGOEA,6330
6
6
  retracesoftware/install/globals.py,sha256=F8XvIoZQQ10gSRalk30dvdKllxlwxkaggYY6FogLDxY,510
7
- retracesoftware/install/install.py,sha256=nHnXjLnZDcY2untKR7BsPJEAcwoHfvXqgCmdHLiwRPE,5104
8
- retracesoftware/install/patcher.py,sha256=Bqr1uwo7Kh4a1VASUfiAd0N7CI40GGyxuH6Zv9c5ir8,17259
7
+ retracesoftware/install/install.py,sha256=HCD_ji8XCr96b5fNzNdL_8qcEp0Jf05Em7T6GA6u8HU,4969
8
+ retracesoftware/install/patcher.py,sha256=zSDmaVmgwTteF-ysMjHFbum793mt93J0gVHDOnYg2uM,17286
9
9
  retracesoftware/install/predicate.py,sha256=tX7NQc0rGkyyHYO3mduYHcJHbw1wczT53m_Dpkzo6do,2679
10
10
  retracesoftware/install/record.py,sha256=tseF_jV4k4HLPTgBPJdjcahl4EQqagoiisMAdGNC52Q,3257
11
- retracesoftware/install/references.py,sha256=0nUY_9BkeFz2imcw97rcJNq2jqISCB8dysBbCrh1eCo,1623
12
- retracesoftware/install/replay.py,sha256=SV7-k05xZFiNfBaxrlLrqbB8-i01IPvnJQjRj9zuinI,1828
11
+ retracesoftware/install/references.py,sha256=A-G651IDOfuo00MkbAdpbIQh_15ChvJ7uAVTSmE6zd4,1721
12
+ retracesoftware/install/replay.py,sha256=VUiHvQK3mgAJEGmtE2TFs9kXzxdWtsjibEcGkhZVCVE,1830
13
13
  retracesoftware/install/tracer.py,sha256=NFilwwtopDrEXjh4ZLkwyIgvPvzApQYC6BA78B11WTQ,4675
14
14
  retracesoftware/install/typeutils.py,sha256=_a1PuwdCsYjG1Nkd77V-flqYtwbD4RkJVKn6Z-xABL4,1813
15
15
  retracesoftware/proxy/__init__.py,sha256=ZlDZIuUmKFsE9Tvfd2EKGabTepqv8nrbr5pQhCM3IKc,193
16
16
  retracesoftware/proxy/gateway.py,sha256=xESohWXkiNm4ZutU0RgWUwxjxcBWRQ4rQyxIGQXv_F4,1590
17
17
  retracesoftware/proxy/proxyfactory.py,sha256=qhOqDfMJnLDNkQs26JqDB431MwjjRhGQi8xupJ45asg,12272
18
- retracesoftware/proxy/proxysystem.py,sha256=JZmi5EWI3B_l5zbq2KsFUTcD9bEsF3EjBhck_IiBmmE,6966
19
- retracesoftware/proxy/proxytype.py,sha256=XiCFDn6DeMoZ9tOq-VDZnsskkCfhJPSxrguIBxLWmws,13622
20
- retracesoftware/proxy/record.py,sha256=BGcYEzTXikHPIJXxhfITKA1uz0FcWIv92xfBheK-KCo,7480
21
- retracesoftware/proxy/replay.py,sha256=GHoXfCr-k23aKCOSjv0TH-nV-bJJ9l279dyTn5-982w,7949
22
- retracesoftware/proxy/stubfactory.py,sha256=RH4Xw9BTh_mPz81j6lmoRXfXm7RukxCxzk_H3se_shk,4152
18
+ retracesoftware/proxy/proxysystem.py,sha256=eUYinugkA2EZgTkxcXcdDntQmK5HCQp5oOwRzfhosx4,6698
19
+ retracesoftware/proxy/proxytype.py,sha256=iKN57FPRrACgYIFEDsCMvROA_tuhuGtZVguOxGlzVEE,12246
20
+ retracesoftware/proxy/record.py,sha256=YEwfqldpb1MQGi6EngPxdbmjbCIjbz9EQCZuXubLSy4,7503
21
+ retracesoftware/proxy/replay.py,sha256=4DxEuBlQSA6e-vB401JVfJV9Dgfesf5qbuBQBD-ApkA,7847
22
+ retracesoftware/proxy/stubfactory.py,sha256=6dvDnbClDY1tDLIDvPYOPxuCIGsg3TYa1qf2SqrmAvg,4114
23
23
  retracesoftware/proxy/thread.py,sha256=-SvnyVbANkmX2lLRpOvFtkpdpAoF6DhnnYdOOs7Q8vo,1379
24
- retracesoftware_proxy-0.1.2.dist-info/METADATA,sha256=C2ZwqWsiW4Hs0HPbadhuecKiDB8etu9dfBGYrt7Q4q0,202
25
- retracesoftware_proxy-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
- retracesoftware_proxy-0.1.2.dist-info/top_level.txt,sha256=hYHsR6txLidmqvjBMITpIHvmJJbmoCAgr76-IpZPRz8,16
27
- retracesoftware_proxy-0.1.2.dist-info/RECORD,,
24
+ retracesoftware_proxy-0.1.3.dist-info/METADATA,sha256=J7wYAHin2b8ikm4VVMN9YfzRDZ9VEg43dpEbvqm0BXw,202
25
+ retracesoftware_proxy-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
+ retracesoftware_proxy-0.1.3.dist-info/top_level.txt,sha256=hYHsR6txLidmqvjBMITpIHvmJJbmoCAgr76-IpZPRz8,16
27
+ retracesoftware_proxy-0.1.3.dist-info/RECORD,,