[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Fix monkey patches of the `_handle_event` method



commit 2a65ee4bb3cd4a25baf14918cd7bb1c614be361e
Author: Illia Volochii <illia.volochii@xxxxxxxxx>
Date:   Thu Apr 30 19:32:25 2020 +0300

    Fix monkey patches of the `_handle_event` method
---
 stem/interpreter/__init__.py | 5 ++++-
 stem/interpreter/commands.py | 9 +++++----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/stem/interpreter/__init__.py b/stem/interpreter/__init__.py
index 1d08abb6..07353d44 100644
--- a/stem/interpreter/__init__.py
+++ b/stem/interpreter/__init__.py
@@ -124,7 +124,10 @@ def main() -> None:
 
     if args.run_cmd:
       if args.run_cmd.upper().startswith('SETEVENTS '):
-        controller._handle_event = lambda event_message: print(format(str(event_message), *STANDARD_OUTPUT))  # type: ignore
+        async def handle_event(event_message):
+          print(format(str(event_message), *STANDARD_OUTPUT))
+
+        controller._async_controller._handle_event = handle_event
 
         if sys.stdout.isatty():
           events = args.run_cmd.upper().split(' ', 1)[1]
diff --git a/stem/interpreter/commands.py b/stem/interpreter/commands.py
index 4c506b5e..0d262ab5 100644
--- a/stem/interpreter/commands.py
+++ b/stem/interpreter/commands.py
@@ -128,17 +128,18 @@ class ControlInterpreter(code.InteractiveConsole):
     # Intercept events our controller hears about at a pretty low level since
     # the user will likely be requesting them by direct 'SETEVENTS' calls.
 
-    handle_event_real = self._controller._handle_event
+    handle_event_real = self._controller._async_controller._handle_event
 
-    def handle_event_wrapper(event_message: stem.response.ControlMessage) -> None:
-      handle_event_real(event_message)
-      self._received_events.insert(0, event_message)  # type: ignore
+    async def handle_event_wrapper(event_message: stem.response.ControlMessage) -> None:
+      await handle_event_real(event_message)
+      self._received_events.insert(0, event_message)
 
       if len(self._received_events) > MAX_EVENTS:
         self._received_events.pop()
 
     # type check disabled due to https://github.com/python/mypy/issues/708
 
+    self._controller._async_controller._handle_event = handle_event_wrapper
     self._controller._handle_event = handle_event_wrapper  # type: ignore
 
   def get_events(self, *event_types: stem.control.EventType) -> List[stem.response.events.Event]:



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits