[tor-commits] [stem/master] Flagging the ExitPolicy's set_default_allowed() as private

atagar at torproject.org atagar at torproject.org
Sun Dec 30 10:54:31 UTC 2012


commit d1d00b635c53c885ff930fe28771cef51f1edebb
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Dec 30 01:18:59 2012 -0800

    Flagging the ExitPolicy's set_default_allowed() as private
    
    The ExitPolicy's set_default_allowed() method is there to support
    microdescriptor policies, not for our users. Acually, exit policies were
    entirely immutable with the exception of this attribute. Changing the method to
    be private.
---
 stem/exit_policy.py             |   35 +++++++++++++++++------------------
 test/unit/exit_policy/policy.py |    4 ++--
 2 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/stem/exit_policy.py b/stem/exit_policy.py
index 6aaa4cc..3e2cbd7 100644
--- a/stem/exit_policy.py
+++ b/stem/exit_policy.py
@@ -23,7 +23,6 @@ exiting to a destination is permissible or not. For instance...
 
   ExitPolicy - Exit policy for a Tor relay
     |  + MicrodescriptorExitPolicy - Microdescriptor exit policy
-    |- set_default_allowed - sets the can_exit_to response when no rules match
     |- can_exit_to - check if exiting to this destination is allowed or not
     |- is_exiting_allowed - check if any exiting is allowed
     |- summary - provides a short label, similar to a microdescriptor
@@ -99,22 +98,6 @@ class ExitPolicy(object):
     self._is_allowed_default = True
     self._summary_representation = None
   
-  def set_default_allowed(self, is_allowed_default):
-    """
-    Generally policies end with either an 'reject \*:\*' or 'accept \*:\*'
-    policy, but if it doesn't then is_allowed_default will determine the
-    default response for our :meth:`~stem.exit_policy.ExitPolicy.can_exit_to`
-    method.
-    
-    Our default, and tor's, is **True**.
-    
-    :param bool is_allowed_default:
-      :meth:`~stem.exit_policy.ExitPolicy.can_exit_to` default when no rules
-      apply
-    """
-    
-    self._is_allowed_default = is_allowed_default
-  
   def can_exit_to(self, address = None, port = None):
     """
     Checks if this policy allows exiting to a given destination or not. If the
@@ -231,6 +214,22 @@ class ExitPolicy(object):
     
     return self._summary_representation
   
+  def _set_default_allowed(self, is_allowed_default):
+    """
+    Generally policies end with either an 'reject \*:\*' or 'accept \*:\*'
+    policy, but if it doesn't then is_allowed_default will determine the
+    default response for our :meth:`~stem.exit_policy.ExitPolicy.can_exit_to`
+    method.
+    
+    Our default, and tor's, is **True**.
+    
+    :param bool is_allowed_default:
+      :meth:`~stem.exit_policy.ExitPolicy.can_exit_to` default when no rules
+      apply
+    """
+    
+    self._is_allowed_default = is_allowed_default
+  
   def __iter__(self):
     for rule in self._rules:
       yield rule
@@ -311,7 +310,7 @@ class MicrodescriptorExitPolicy(ExitPolicy):
         raise ValueError(exc_msg)
     
     super(MicrodescriptorExitPolicy, self).__init__(*rules)
-    self.set_default_allowed(not self.is_accept)
+    self._set_default_allowed(not self.is_accept)
   
   def __str__(self):
     return self._policy
diff --git a/test/unit/exit_policy/policy.py b/test/unit/exit_policy/policy.py
index bfafa98..831009e 100644
--- a/test/unit/exit_policy/policy.py
+++ b/test/unit/exit_policy/policy.py
@@ -43,7 +43,7 @@ class TestExitPolicy(unittest.TestCase):
     self.assertTrue(policy.can_exit_to("75.119.206.243", 443))
     self.assertTrue(policy.can_exit_to("75.119.206.243", 999))
     
-    policy.set_default_allowed(False)
+    policy._set_default_allowed(False)
     self.assertFalse(policy.can_exit_to("75.119.206.243", 80))
     self.assertTrue(policy.can_exit_to("75.119.206.243", 443))
     self.assertFalse(policy.can_exit_to("75.119.206.243", 999))
@@ -54,7 +54,7 @@ class TestExitPolicy(unittest.TestCase):
     policy = ExitPolicy()
     self.assertTrue(policy.is_exiting_allowed())
     
-    policy.set_default_allowed(False)
+    policy._set_default_allowed(False)
     self.assertFalse(policy.is_exiting_allowed())
   
   def test_can_exit_to(self):





More information about the tor-commits mailing list