retracesoftware-proxy 0.1.0__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.
@@ -0,0 +1,141 @@
1
+ import sys
2
+ import os
3
+
4
+ import retracesoftware.functional as functional
5
+ import retracesoftware.utils as utils
6
+
7
+ class Stub:
8
+ __slots__ = []
9
+
10
+ class ExtendedRef:
11
+ def __init__(self, module, name):
12
+ self.type = type
13
+ self.module = module
14
+
15
+ class StubRef:
16
+ def __init__(self, module, name, methods, members):
17
+ self.name = name
18
+ self.module = module
19
+ self.methods = methods
20
+ self.members = members
21
+
22
+ def __str__(self):
23
+ return f'StubRef(module = {self.module}, name = {self.name}, methods = {self.methods}, members = {self.members})'
24
+
25
+ def resolve(module, name):
26
+ try:
27
+ return getattr(sys.modules[module], name)
28
+ except:
29
+ return None
30
+
31
+ class StubMethodDescriptor(functional.repeatedly):
32
+ def __init__(self, name, next_result):
33
+ super().__init__(next_result)
34
+ self.__name__ = name
35
+
36
+ def __str__(self):
37
+ return f"stub - {__name__}"
38
+
39
+ class StubMemberDescriptor:
40
+ def __init__(self, name, next_result):
41
+ self.next_result = next_result
42
+ self.__name__ = name
43
+
44
+ def __get__(self, instance, owner):
45
+ if instance is None:
46
+ return self
47
+
48
+ return self.next_result()
49
+
50
+ def __set__(self, instance, value):
51
+ return self.next_result()
52
+
53
+ def __delete__(self, instance):
54
+ return self.next_result()
55
+
56
+ def __str__(self):
57
+ return f"stub member - {__name__}"
58
+
59
+ class StubFunction(functional.repeatedly):
60
+ def __init__(self, name, next_result):
61
+ super().__init__(next_result)
62
+ self.__name__ = name
63
+
64
+ def __str__(self):
65
+ return f"stub function - {__name__}"
66
+
67
+ class StubFactory:
68
+
69
+ __slots__ = ['next_result', 'thread_state', 'cache']
70
+
71
+ def __init__(self, thread_state, next_result):
72
+ self.next_result = next_result
73
+ self.thread_state = thread_state
74
+ self.cache = {}
75
+
76
+ def create_member(self, name):
77
+ def disabled(*args, **kwargs):
78
+ if self.thread_state.value == 'disabled' and name == '__repr__':
79
+ return f"stub member - {name}"
80
+ else:
81
+ print(f'Error trying to call member descriptor: {name} {args} {kwargs}, retrace mode: {self.thread_state.value}')
82
+ utils.sigtrap(None)
83
+ os._exit(1)
84
+
85
+ next_result = self.thread_state.dispatch(disabled, external = self.next_result)
86
+
87
+ return StubMemberDescriptor(name = name, next_result = next_result)
88
+
89
+ def create_method(self, name):
90
+
91
+ def disabled(*args, **kwargs):
92
+ if self.thread_state.value == 'disabled' and name == '__repr__':
93
+ return f"stub - {name}"
94
+ else:
95
+ print(f'Error trying to call descriptor: {name} {args} {kwargs}, retrace mode: {self.thread_state.value}')
96
+ utils.sigtrap(None)
97
+ os._exit(1)
98
+
99
+ next_result = self.thread_state.dispatch(disabled, external = self.next_result)
100
+
101
+ func = functional.repeatedly(next_result)
102
+ func.__name__ = name
103
+
104
+ return func
105
+
106
+ def create_stubtype(self, spec):
107
+
108
+ print(f'FOOO: {spec.module}')
109
+ slots = {
110
+ '__module__': spec.module,
111
+ '__qualname__': spec.name,
112
+ }
113
+
114
+ for method in spec.methods:
115
+ slots[method] = self.create_method(method)
116
+ assert utils.is_method_descriptor(slots[method])
117
+
118
+ for member in spec.members:
119
+ slots[member] = self.create_member(member)
120
+
121
+ resolved = resolve(spec.module, spec.name)
122
+
123
+ if isinstance(resolved, type):
124
+ slots['__class__'] = property(functional.repeatedly(resolved))
125
+
126
+ stubtype = type(spec.name, (Stub, ), slots)
127
+
128
+ for method in spec.methods:
129
+ slots[method].__objclass__ = stubtype
130
+
131
+ return stubtype
132
+
133
+ def __call__(self, spec):
134
+ print(f'In stubFactory.__call__ {spec}')
135
+ if spec not in self.cache:
136
+ self.cache[spec] = self.create_stubtype(spec)
137
+
138
+ stubtype = self.cache[spec]
139
+ stub = stubtype.__new__(stubtype)
140
+ print(f'In stubFactory created new')
141
+ return stub
@@ -1,11 +1,46 @@
1
1
  import retracesoftware.functional as functional
2
2
  import retracesoftware_utils as utils
3
3
 
4
+ # def thread_aware_writer(writer):
5
+ # on_thread_switch = functional.sequence(utils.thread_id(), writer.handle('THREAD_SWITCH'))
6
+ # return utils.threadawareproxy(on_thread_switch = on_thread_switch, target = writer)
7
+
4
8
  class ThreadSwitch:
5
- def __init__(self, thread_id):
6
- self.thread_id = thread_id
9
+ __slots__ = ['id']
10
+
11
+ def __init__(self, id):
12
+ self.id = id
13
+
14
+ def set_thread_id(writer, id):
15
+ utils.set_thread_id(writer.handle(ThreadSwitch(id)))
16
+
17
+ def write_thread_switch(writer):
18
+ on_thread_switch = functional.repeatedly(functional.sequence(utils.thread_id, writer))
19
+
20
+ return lambda f: utils.thread_aware_proxy(target = f, on_thread_switch = on_thread_switch, sticky = False)
21
+
22
+ def prefix_with_thread_id(f, current):
23
+ def next():
24
+ nonlocal current, f
25
+ obj = f()
26
+
27
+ while issubclass(type(obj), ThreadSwitch):
28
+ current = obj.id
29
+ obj = f()
30
+
31
+ return (current, obj)
32
+
33
+ return next
34
+
35
+ def per_thread_messages(messages):
36
+ thread_id = utils.thread_id
37
+ # thread_id = lambda: 'FOOOOO!!!'
7
38
 
39
+ demux = utils.demux(source = prefix_with_thread_id(messages, thread_id()), key_function = lambda obj: obj[0])
8
40
 
9
- def thread_aware_writer(writer):
10
- on_thread_switch = functional.sequence(utils.thread_id(), writer.handle('THREAD_SWITCH'))
11
- return utils.threadawareproxy(on_thread_switch = on_thread_switch, target = writer)
41
+ # def next():
42
+ # thread,message = demux(thread_id())
43
+ # return message
44
+
45
+ # return next
46
+ return functional.repeatedly(lambda: demux(thread_id())[1])
@@ -1,12 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: retracesoftware_proxy
3
- Version: 0.1.0
4
- Summary: Proxy layer for retracesoftware runtime
3
+ Version: 0.1.2
5
4
  License: Apache-2.0
6
- Requires-Python: >=3.11
7
- Description-Content-Type: text/markdown
8
5
  Requires-Dist: retracesoftware_utils
9
6
  Requires-Dist: retracesoftware_functional
10
7
  Requires-Dist: retracesoftware_stream
11
-
12
- # proxy
@@ -0,0 +1,27 @@
1
+ retracesoftware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ retracesoftware/config.json,sha256=zhi3DZKG0pIT3Mh2EUXlzQai-U6YrknueOjMJLwNKxY,8281
3
+ retracesoftware/install/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ retracesoftware/install/config.py,sha256=EzE5ifQF2lo--hu2njI4T0FJ-zlnWDJV6i7x0DMkVTw,1364
5
+ retracesoftware/install/edgecases.py,sha256=NR3lyvad9sRsyeDv_Ya8V4xMgPsMPOi9rMcnFOJGOEA,6330
6
+ retracesoftware/install/globals.py,sha256=F8XvIoZQQ10gSRalk30dvdKllxlwxkaggYY6FogLDxY,510
7
+ retracesoftware/install/install.py,sha256=nHnXjLnZDcY2untKR7BsPJEAcwoHfvXqgCmdHLiwRPE,5104
8
+ retracesoftware/install/patcher.py,sha256=Bqr1uwo7Kh4a1VASUfiAd0N7CI40GGyxuH6Zv9c5ir8,17259
9
+ retracesoftware/install/predicate.py,sha256=tX7NQc0rGkyyHYO3mduYHcJHbw1wczT53m_Dpkzo6do,2679
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
13
+ retracesoftware/install/tracer.py,sha256=NFilwwtopDrEXjh4ZLkwyIgvPvzApQYC6BA78B11WTQ,4675
14
+ retracesoftware/install/typeutils.py,sha256=_a1PuwdCsYjG1Nkd77V-flqYtwbD4RkJVKn6Z-xABL4,1813
15
+ retracesoftware/proxy/__init__.py,sha256=ZlDZIuUmKFsE9Tvfd2EKGabTepqv8nrbr5pQhCM3IKc,193
16
+ retracesoftware/proxy/gateway.py,sha256=xESohWXkiNm4ZutU0RgWUwxjxcBWRQ4rQyxIGQXv_F4,1590
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
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,,
@@ -1,26 +0,0 @@
1
- retracesoftware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- retracesoftware/config.json,sha256=aedf9CXxOBkcQk3BJVrh0GuBkIAjBGBRlrTXdoRJ-MY,8108
3
- retracesoftware/install/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- retracesoftware/install/config.py,sha256=EzE5ifQF2lo--hu2njI4T0FJ-zlnWDJV6i7x0DMkVTw,1364
5
- retracesoftware/install/edgecases.py,sha256=NR3lyvad9sRsyeDv_Ya8V4xMgPsMPOi9rMcnFOJGOEA,6330
6
- retracesoftware/install/globals.py,sha256=F8XvIoZQQ10gSRalk30dvdKllxlwxkaggYY6FogLDxY,510
7
- retracesoftware/install/install.py,sha256=VNtivSf6A9wtLzIkZKJQ7thPkYTdjtTmxaIkPUOwLhg,5942
8
- retracesoftware/install/patcher.py,sha256=5DGzVaNM53Z_KWz-wWQxlr1WqeWuuxKoVZyN5tNGuTw,15866
9
- retracesoftware/install/predicate.py,sha256=tX7NQc0rGkyyHYO3mduYHcJHbw1wczT53m_Dpkzo6do,2679
10
- retracesoftware/install/record.py,sha256=mJyz8ZFnrveDCvrUHksTXaFZbBX10yqH6UBV1QH5EwA,4370
11
- retracesoftware/install/references.py,sha256=0nUY_9BkeFz2imcw97rcJNq2jqISCB8dysBbCrh1eCo,1623
12
- retracesoftware/install/replay.py,sha256=ox43e8k_uvn9w6vf6rt8f3KwaXcBVx2GbvWaLZpwqR4,4952
13
- retracesoftware/install/tracer.py,sha256=dFhXKkmvGLF-_WzQvZXxNO1Ftj6crH1SM6pGBU4cqMY,4586
14
- retracesoftware/install/typeutils.py,sha256=_a1PuwdCsYjG1Nkd77V-flqYtwbD4RkJVKn6Z-xABL4,1813
15
- retracesoftware/proxy/__init__.py,sha256=NaGsqoj4X3NpHfTAmRIfsXM16R6AGE99ciQeknj3sXc,119
16
- retracesoftware/proxy/gateway.py,sha256=JtSwwllXiUykpNdojbK7okyYadRnILGgpRCHxAQijZs,3911
17
- retracesoftware/proxy/proxyfactory.py,sha256=2PgC0NtDbRmhmU--caTiQDsaF8s1h9tavQxvPIow_bM,11912
18
- retracesoftware/proxy/proxysystem.py,sha256=kDdtea-vCcsqdwSwmgGBBvVrIRl6Gwb89Wgx6VSIwgQ,759
19
- retracesoftware/proxy/proxytype.py,sha256=P78aL3_aemG8p3NKmP4YfAcwC8IDr7LIq5-dkV4n0Ec,9038
20
- retracesoftware/proxy/record.py,sha256=yI8CH0oOyrAyvjy9JsawgkQh9jYTlg9sQ_CcejrFKO4,4772
21
- retracesoftware/proxy/replay.py,sha256=usbb2OTX6uJG_zialqHk9en0mxD2xEhjPajMZDjZnkQ,3940
22
- retracesoftware/proxy/thread.py,sha256=9_6gWiRbir77f9kelpvXaTWviRfZo0ACkKPdGNbrq2Q,394
23
- retracesoftware_proxy-0.1.0.dist-info/METADATA,sha256=c24hdDKP-miIrX6mM1yVyXCQeu0ozLP4N0ebtqiGccw,324
24
- retracesoftware_proxy-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
25
- retracesoftware_proxy-0.1.0.dist-info/top_level.txt,sha256=hYHsR6txLidmqvjBMITpIHvmJJbmoCAgr76-IpZPRz8,16
26
- retracesoftware_proxy-0.1.0.dist-info/RECORD,,