[tor-commits] [stem/master] Providing ExitPolicy via get_config_policy()

atagar at torproject.org atagar at torproject.org
Mon Jan 14 01:39:16 UTC 2013


commit f264a626d682f6b8a4cdea8b58a260b1c1069524
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Jan 13 16:33:03 2013 -0800

    Providing ExitPolicy via get_config_policy()
    
    On reflection it desn't make sense to provide a list of ExitPolicyRules.
    Usually we want a policy itself, and if we do want a rule list then that's
    easily done via 'list(get_config_policy())'.
---
 stem/exit_policy.py             |    4 +-
 test/unit/exit_policy/policy.py |   42 +++++++++++++++++---------------------
 2 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/stem/exit_policy.py b/stem/exit_policy.py
index 3bccc27..b5d0573 100644
--- a/stem/exit_policy.py
+++ b/stem/exit_policy.py
@@ -97,7 +97,7 @@ def get_config_policy(rules):
 
   :param str,list rules: comma separated rules or list to be converted
 
-  :returns: **list** of :class:`~stem.exit_policy.ExitPolicyRule`
+  :returns: :class:`~stem.exit_policy.ExitPolicy` reflected by the rules
 
   :raises: **ValueError** if input isn't a valid tor exit policy
   """
@@ -125,7 +125,7 @@ def get_config_policy(rules):
     else:
       result.append(ExitPolicyRule(rule))
 
-  return result
+  return ExitPolicy(*result)
 
 
 class ExitPolicy(object):
diff --git a/test/unit/exit_policy/policy.py b/test/unit/exit_policy/policy.py
index b8ac286..af4ceba 100644
--- a/test/unit/exit_policy/policy.py
+++ b/test/unit/exit_policy/policy.py
@@ -199,29 +199,25 @@ class TestExitPolicy(unittest.TestCase):
 
   def test_get_config_policy(self):
     test_inputs = {
-      "": [],
-      "reject *": [
-        ExitPolicyRule('reject *:*'),
-      ],
-      "reject *:*": [
-        ExitPolicyRule('reject *:*'),
-      ],
-      "reject private": [
-        ExitPolicyRule('reject 0.0.0.0/8:*'),
-        ExitPolicyRule('reject 169.254.0.0/16:*'),
-        ExitPolicyRule('reject 127.0.0.0/8:*'),
-        ExitPolicyRule('reject 192.168.0.0/16:*'),
-        ExitPolicyRule('reject 10.0.0.0/8:*'),
-        ExitPolicyRule('reject 172.16.0.0/12:*'),
-      ],
-      "accept *:80, reject *": [
-        ExitPolicyRule('accept *:80'),
-        ExitPolicyRule('reject *:*'),
-      ],
-      "  accept *:80,     reject *   ": [
-        ExitPolicyRule('accept *:80'),
-        ExitPolicyRule('reject *:*'),
-      ],
+      "": ExitPolicy(),
+      "reject *": ExitPolicy('reject *:*'),
+      "reject *:*": ExitPolicy('reject *:*'),
+      "reject private": ExitPolicy(
+        'reject 0.0.0.0/8:*',
+        'reject 169.254.0.0/16:*',
+        'reject 127.0.0.0/8:*',
+        'reject 192.168.0.0/16:*',
+        'reject 10.0.0.0/8:*',
+        'reject 172.16.0.0/12:*',
+      ),
+      "accept *:80, reject *": ExitPolicy(
+        'accept *:80',
+        'reject *:*',
+      ),
+      "  accept *:80,     reject *   ": ExitPolicy(
+        'accept *:80',
+        'reject *:*',
+      ),
     }
 
     for test_input, expected in test_inputs.items():





More information about the tor-commits mailing list