[tor-commits] [bridgedb/develop] Change Bridge.nickname into a @property.

isis at torproject.org isis at torproject.org
Thu Feb 19 02:21:13 UTC 2015


commit 293d390ae320d77d09125cfbb70f63f46127f0bf
Author: Isis Lovecruft <isis at torproject.org>
Date:   Thu Dec 11 04:31:59 2014 +0000

    Change Bridge.nickname into a @property.
---
 lib/bridgedb/bridges.py |   26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/lib/bridgedb/bridges.py b/lib/bridgedb/bridges.py
index 2e64fdf..5c92898 100644
--- a/lib/bridgedb/bridges.py
+++ b/lib/bridgedb/bridges.py
@@ -35,6 +35,7 @@ from bridgedb.parse.addr import PortList
 from bridgedb.parse.fingerprint import isValidFingerprint
 from bridgedb.parse.fingerprint import toHex
 from bridgedb.parse.fingerprint import fromHex
+from bridgedb.parse.nickname import isValidRouterNickname
 
 
 class PluggableTransportUnavailable(Exception):
@@ -386,7 +387,7 @@ class BridgeBase(object):
 
     def __init__(self):
         self._fingerprint = None
-        self.nickname = None
+        self._nickname = None
         self.address = None
         self.orPort = None
         self.socksPort = 0  # Bridges should always have ``SOCKSPort`` and
@@ -424,6 +425,29 @@ class BridgeBase(object):
         """Reset this Bridge's fingerprint."""
         self._fingerprint = None
         
+    @property
+    def nickname(self):
+        """Get this Bridge's nickname.
+
+        :rtype: str
+        :returns: The Bridge's nickname.
+        """
+        return self._nickname
+
+    @nickname.setter
+    def nickname(self, value):
+        """Set this Bridge's nickname to **value**.
+
+        :param str value: The nickname of this Bridge.
+        """
+        if isValidRouterNickname(value):
+            self._nickname = value
+
+    @nickname.deleter
+    def nickname(self, value):
+        """Reset this Bridge's nickname."""
+        self._nickname = None
+
 
 class BridgeBackwardsCompatibility(BridgeBase):
     """Backwards compatibility methods for the old Bridge class."""





More information about the tor-commits mailing list