commit 910941c712f20816c70e06e64add5e8530218c1c Author: Isis Lovecruft isis@torproject.org Date: Tue Jun 9 00:16:37 2015 +0000
Define IBridge interface for sufficiently "bridge-like" things.
* ADD bridgedb.bridges.IBridge interface specification. * CHANGE the following classes to declare that they implement the IBridge interface: - bridgedb.bridges.BridgeAddressBase - bridgedb.bridges.PluggableTransport - bridgedb.bridges.BridgeBase - bridgedb.bridges.BridgeBackwardsCompatibility - bridgedb.bridges.Bridge
Conflicts: lib/bridgedb/bridges.py --- lib/bridgedb/bridges.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
diff --git a/lib/bridgedb/bridges.py b/lib/bridgedb/bridges.py index 5093bef..747863a 100644 --- a/lib/bridgedb/bridges.py +++ b/lib/bridgedb/bridges.py @@ -23,6 +23,10 @@ from Crypto.Util import asn1 from Crypto.Util.number import bytes_to_long from Crypto.Util.number import long_to_bytes
+from zope.interface import implementer +from zope.interface import Attribute +from zope.interface import Interface + import bridgedb.Storage
from bridgedb import geo @@ -78,6 +82,18 @@ class InvalidExtraInfoSignature(MalformedBridgeInfo): """Raised if the signature on an ``@type bridge-extrainfo`` is invalid."""
+class IBridge(Interface): + """I am a (mostly) stub interface whose primary purpose is merely to allow + other classes to signify whether or not they can be treated like a + :class:`Bridge`. + """ + fingerprint = Attribute( + ("The lowercased, hexadecimal-encoded, hash digest of this Bridge's " + "public identity key.")) + address = Attribute("This Bridge's primary public IP address.") + port = Attribute("The port which this Bridge is listening on.") + + class Flags(object): """All the flags which a :class:`Bridge` may have."""
@@ -122,6 +138,7 @@ class Flags(object): self.valid = 'Valid' in flags
+@implementer(IBridge) class BridgeAddressBase(object): """A base class for describing one of a :class:`Bridge`'s or a :class:`PluggableTransport`'s location, including its identity key @@ -274,6 +291,8 @@ class BridgeAddressBase(object): self._port = None
+ +@implementer(IBridge) class PluggableTransport(BridgeAddressBase): """A single instance of a Pluggable Transport (PT) offered by a :class:`Bridge`. @@ -589,6 +608,7 @@ class PluggableTransport(BridgeAddressBase): self._runChecks()
+@implementer(IBridge) class BridgeBase(BridgeAddressBase): """The base class for all bridge implementations."""
@@ -652,6 +672,7 @@ class BridgeBase(BridgeAddressBase): del self.port
+@implementer(IBridge) class BridgeBackwardsCompatibility(BridgeBase): """Backwards compatibility methods for the old Bridge class."""
@@ -841,6 +862,7 @@ class BridgeBackwardsCompatibility(BridgeBase): return db.getBridgeHistory(self.fingerprint).weightedUptime
+@implementer(IBridge) class Bridge(BridgeBackwardsCompatibility): """A single bridge, and all the information we have for it.
tor-commits@lists.torproject.org