commit cc95059da5a8e34d10c16f5a226df21ffb5b43c9 Author: Damian Johnson atagar@torproject.org Date: Tue Apr 17 10:09:14 2018 -0700
Context methods for the Circuit class
Like our Relay class circuits are intended to be used for a time then closed. Decorating it with the methods necessary so it can be used through 'with' clauses. --- stem/client/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/stem/client/__init__.py b/stem/client/__init__.py index 2c6b7ea6..be7e16ad 100644 --- a/stem/client/__init__.py +++ b/stem/client/__init__.py @@ -256,3 +256,9 @@ class Circuit(object): with self.relay._orport_lock: self.relay._orport.send(stem.client.cell.DestroyCell(self.id).pack(self.relay.link_protocol)) del self.relay._circuits[self.id] + + def __enter__(self): + return self + + def __exit__(self, exit_type, value, traceback): + self.close()
tor-commits@lists.torproject.org