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

[tor-commits] [stem/master] Make `Controller.get_listeners` and `Controller.get_ports` asynchronous



commit 2c4250d7225fac97a19a3b270901420f5f009005
Author: Illia Volochii <illia.volochii@xxxxxxxxx>
Date:   Wed Apr 15 21:59:31 2020 +0300

    Make `Controller.get_listeners` and `Controller.get_ports` asynchronous
---
 stem/control.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 5dc53a1a..c5cbbf81 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1299,7 +1299,7 @@ class Controller(BaseController):
     return policy
 
   @with_default()
-  def get_ports(self, listener_type: 'stem.control.Listener', default: Any = UNDEFINED) -> Sequence[int]:
+  async def get_ports(self, listener_type: 'stem.control.Listener', default: Any = UNDEFINED) -> Sequence[int]:
     """
     get_ports(listener_type, default = UNDEFINED)
 
@@ -1332,10 +1332,10 @@ class Controller(BaseController):
         log.info("Request for %s ports got an address that's neither IPv4 or IPv6: %s" % (listener_type, address))
         return False
 
-    return [port for (addr, port) in self.get_listeners(listener_type) if is_localhost(addr)]
+    return [port for (addr, port) in (await self.get_listeners(listener_type)) if is_localhost(addr)]
 
   @with_default()
-  def get_listeners(self, listener_type: 'stem.control.Listener', default: Any = UNDEFINED) -> Sequence[Tuple[str, int]]:
+  async def get_listeners(self, listener_type: 'stem.control.Listener', default: Any = UNDEFINED) -> Sequence[Tuple[str, int]]:
     """
     get_listeners(listener_type, default = UNDEFINED)
 
@@ -1366,7 +1366,7 @@ class Controller(BaseController):
       query = 'net/listeners/%s' % str(listener_type).lower()
 
       try:
-        for listener in self.get_info(query).split():
+        for listener in (await self.get_info(query)).split():
           if not (listener.startswith('"') and listener.endswith('"')):
             raise stem.ProtocolError("'GETINFO %s' responses are expected to be quoted: %s" % (query, listener))
           elif ':' not in listener:
@@ -1415,7 +1415,7 @@ class Controller(BaseController):
 
         port_value = self._get_conf_single(port_option).split()[0]
 
-        for listener in self.get_conf(listener_option, multiple = True):
+        for listener in (await self.get_conf(listener_option, multiple = True)):
           if ':' in listener:
             addr, port = listener.rsplit(':', 1)
 



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