MCPcopy Index your code
hub / github.com/secdev/scapy / ObjectPipe

Class ObjectPipe

scapy/automaton.py:159–273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157
158
159class ObjectPipe(Generic[_T]):
160 def __init__(self, name=None):
161 # type: (Optional[str]) -> None
162 self.name = name or "ObjectPipe"
163 self.closed = False
164 self.__rd, self.__wr = os.pipe()
165 self.__queue = deque() # type: Deque[_T]
166 if WINDOWS:
167 self._wincreate()
168
169 if WINDOWS:
170 def _wincreate(self):
171 # type: () -> None
172 self._fd = cast(int, ctypes.windll.kernel32.CreateEventA(
173 None, True, False,
174 ctypes.create_string_buffer(b"ObjectPipe %f" % random.random())
175 ))
176
177 def _winset(self):
178 # type: () -> None
179 if ctypes.windll.kernel32.SetEvent(ctypes.c_void_p(self._fd)) == 0:
180 warning(ctypes.FormatError(ctypes.GetLastError()))
181
182 def _winreset(self):
183 # type: () -> None
184 if ctypes.windll.kernel32.ResetEvent(ctypes.c_void_p(self._fd)) == 0:
185 warning(ctypes.FormatError(ctypes.GetLastError()))
186
187 def _winclose(self):
188 # type: () -> None
189 if ctypes.windll.kernel32.CloseHandle(ctypes.c_void_p(self._fd)) == 0:
190 warning(ctypes.FormatError(ctypes.GetLastError()))
191
192 def fileno(self):
193 # type: () -> int
194 if WINDOWS:
195 return self._fd
196 return self.__rd
197
198 def send(self, obj):
199 # type: (_T) -> int
200 self.__queue.append(obj)
201 if WINDOWS:
202 self._winset()
203 os.write(self.__wr, b"X")
204 return 1
205
206 def write(self, obj):
207 # type: (_T) -> None
208 self.send(obj)
209
210 def empty(self):
211 # type: () -> bool
212 return not bool(self.__queue)
213
214 def flush(self):
215 # type: () -> None
216 pass

Callers 2

__init__Method · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by 1

__init__Method · 0.72