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

[tor-commits] [stem/master] Move Endpoint class up in the base module



commit 3330d89cef046426816d53dc4572571615eecf63
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Thu May 17 10:14:46 2018 -0700

    Move Endpoint class up in the base module
    
    The base module provides quite a few exceptions so think I'd prefer for the
    concrete classes to come a little earlier as not to get buried. Also a minor
    fix for the ORPort's hash function (nothing consiquential, just doing more work
    than it had to).
---
 stem/__init__.py | 106 +++++++++++++++++++++++++++++--------------------------
 1 file changed, 55 insertions(+), 51 deletions(-)

diff --git a/stem/__init__.py b/stem/__init__.py
index e9ad8430..c4d8c1a5 100644
--- a/stem/__init__.py
+++ b/stem/__init__.py
@@ -8,6 +8,10 @@ Library for working with the tor process.
 
 ::
 
+  Endpoint - Networking endpoint.
+    |- ORPort - Tor relay endpoint.
+    +- DirPort - Descriptor mirror.
+
   ControllerError - Base exception raised when using the controller.
     |- ProtocolError - Malformed socket data.
     |
@@ -547,6 +551,57 @@ __all__ = [
 UNDEFINED = '<Undefined_ >'
 
 
+class Endpoint(object):
+  """
+  Tor endpint that can be connected to.
+
+  .. versionadded:: 1.7.0
+
+  :var str address: ip address of the endpoint
+  :var int port: port of the endpoint
+  """
+
+  def __init__(self, address, port):
+    if not stem.util.connection.is_valid_ipv4_address(address) and not stem.util.connection.is_valid_ipv6_address(address):
+      raise ValueError("'%s' isn't a valid IPv4 or IPv6 address" % address)
+    elif not stem.util.connection.is_valid_port(port):
+      raise ValueError("'%s' isn't a valid port" % port)
+
+    self.address = address
+    self.port = int(port)
+
+  def __hash__(self):
+    return stem.util._hash_attr(self, 'address', 'port')
+
+  def __eq__(self, other):
+    return hash(self) == hash(other) if isinstance(other, Endpoint) else False
+
+  def __ne__(self, other):
+    return not self == other
+
+
+class ORPort(Endpoint):
+  """
+  Tor relay's ORPort. The endpoint on which Tor accepts relay traffic.
+
+  :var list link_protocols: link protocol version we're willing to establish
+  """
+
+  def __init__(self, address, port, link_protocols = None):
+    super(ORPort, self).__init__(address, port)
+    self.link_protocols = link_protocols
+
+  def __hash__(self):
+    return stem.util._hash_attr(self, 'link_protocols', parent = Endpoint)
+
+
+class DirPort(Endpoint):
+  """
+  Tor relay's DirPort. The endpoint on which Tor provides http access for
+  downloading descriptors.
+  """
+
+
 class ControllerError(Exception):
   'Base error for controller communication issues.'
 
@@ -640,57 +695,6 @@ class SocketClosed(SocketError):
   'Control socket was closed before completing the message.'
 
 
-class Endpoint(object):
-  """
-  Tor endpint that can be connected to.
-
-  .. versionadded:: 1.7.0
-
-  :var str address: ip address of the endpoint
-  :var int port: port of the endpoint
-  """
-
-  def __init__(self, address, port):
-    if not stem.util.connection.is_valid_ipv4_address(address) and not stem.util.connection.is_valid_ipv6_address(address):
-      raise ValueError("'%s' isn't a valid IPv4 or IPv6 address" % address)
-    elif not stem.util.connection.is_valid_port(port):
-      raise ValueError("'%s' isn't a valid port" % port)
-
-    self.address = address
-    self.port = int(port)
-
-  def __hash__(self):
-    return stem.util._hash_attr(self, 'address', 'port')
-
-  def __eq__(self, other):
-    return hash(self) == hash(other) if isinstance(other, Endpoint) else False
-
-  def __ne__(self, other):
-    return not self == other
-
-
-class ORPort(Endpoint):
-  """
-  Tor relay's ORPort. The endpoint on which Tor accepts relay traffic.
-
-  :var list link_protocols: link protocol version we're willing to establish
-  """
-
-  def __init__(self, address, port, link_protocols = None):
-    super(ORPort, self).__init__(address, port)
-    self.link_protocols = link_protocols
-
-  def __hash__(self):
-    return super(ORPort, self).__hash__() + stem.util._hash_attr(self, 'link_protocols', 'port') * 10
-
-
-class DirPort(Endpoint):
-  """
-  Tor relay's DirPort. The endpoint on which Tor provides http access for
-  downloading descriptors.
-  """
-
-
 Runlevel = stem.util.enum.UppercaseEnum(
   'DEBUG',
   'INFO',



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