[tor-commits] [stem/master] Renaming MicrodescriptorExitPolicy to MicroExitPolicy
atagar at torproject.org
atagar at torproject.org
Sun Jan 6 00:24:53 UTC 2013
commit ec306804fc325b8670758df36ec76a1e10fe3604
Author: Damian Johnson <atagar at torproject.org>
Date: Sat Jan 5 16:14:12 2013 -0800
Renaming MicrodescriptorExitPolicy to MicroExitPolicy
Suggestion by Sean on "Stem code review 2013-01-03". The new name both fits
better (since the rule class is called MicroExitPolicyRule) and a friendlier
length to type.
---
stem/descriptor/router_status_entry.py | 4 ++--
stem/descriptor/server_descriptor.py | 4 ++--
stem/exit_policy.py | 12 ++++++------
test/unit/descriptor/router_status_entry.py | 6 +++---
test/unit/descriptor/server_descriptor.py | 2 +-
test/unit/exit_policy/policy.py | 18 +++++++++---------
6 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index ed01132..57b018a 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -279,7 +279,7 @@ class RouterStatusEntryV3(RouterStatusEntry):
:var list unrecognized_bandwidth_entries: **\*** bandwidth weighting
information that isn't yet recognized
- :var stem.exit_policy.MicrodescriptorExitPolicy exit_policy: router's exit policy
+ :var stem.exit_policy.MicroExitPolicy exit_policy: router's exit policy
:var list microdescriptor_hashes: **\*** tuples of two values, the list of
consensus methods for generating a set of digests and the 'algorithm =>
@@ -557,7 +557,7 @@ def _parse_p_line(desc, value, validate):
# example: p accept 80,110,143,443,993,995,6660-6669,6697,7000-7001
try:
- desc.exit_policy = stem.exit_policy.MicrodescriptorExitPolicy(value)
+ desc.exit_policy = stem.exit_policy.MicroExitPolicy(value)
except ValueError, exc:
if not validate: return
raise ValueError("%s exit policy is malformed (%s): p %s" % (desc._name(), exc, value))
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index 634a705..17664bc 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -146,7 +146,7 @@ class ServerDescriptor(stem.descriptor.Descriptor):
:var int uptime: uptime when published in seconds
:var str contact: contact information
:var stem.exit_policy.ExitPolicy exit_policy: **\*** stated exit policy
- :var stem.exit_policy.MicrodescriptorExitPolicy exit_policy_v6: **\*** exit policy for IPv6
+ :var stem.exit_policy.MicroExitPolicy exit_policy_v6: **\*** exit policy for IPv6
:var list family: **\*** nicknames or fingerprints of declared family
:var int average_bandwidth: **\*** average rate it's willing to relay in bytes/s
@@ -475,7 +475,7 @@ class ServerDescriptor(stem.descriptor.Descriptor):
elif keyword == "eventdns":
self.eventdns = value == "1"
elif keyword == "ipv6-policy":
- self.exit_policy_v6 = stem.exit_policy.MicrodescriptorExitPolicy(value)
+ self.exit_policy_v6 = stem.exit_policy.MicroExitPolicy(value)
elif keyword == "or-address":
or_address_entries = [value for (value, _) in values]
diff --git a/stem/exit_policy.py b/stem/exit_policy.py
index d7e091f..677a3c9 100644
--- a/stem/exit_policy.py
+++ b/stem/exit_policy.py
@@ -4,7 +4,7 @@ exiting to a destination is permissible or not. For instance...
::
- >>> from stem.exit_policy import ExitPolicy, MicrodescriptorExitPolicy
+ >>> from stem.exit_policy import ExitPolicy, MicroExitPolicy
>>> policy = ExitPolicy("accept *:80", "accept *:443", "reject *:*")
>>> print policy
accept *:80, accept *:443, reject *:*
@@ -13,7 +13,7 @@ exiting to a destination is permissible or not. For instance...
>>> policy.can_exit_to("75.119.206.243", 80)
True
- >>> policy = MicrodescriptorExitPolicy("accept 80,443")
+ >>> policy = MicroExitPolicy("accept 80,443")
>>> print policy
accept 80,443
>>> policy.can_exit_to("75.119.206.243", 80)
@@ -22,7 +22,7 @@ exiting to a destination is permissible or not. For instance...
::
ExitPolicy - Exit policy for a Tor relay
- | + MicrodescriptorExitPolicy - Microdescriptor exit policy
+ | + MicroExitPolicy - Microdescriptor exit policy
|- 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
@@ -256,7 +256,7 @@ class ExitPolicy(object):
else:
return False
-class MicrodescriptorExitPolicy(ExitPolicy):
+class MicroExitPolicy(ExitPolicy):
"""
Exit policy provided by the microdescriptors. This is a distilled version of
a normal :class:`~stem.exit_policy.ExitPolicy` contains, just consisting of a
@@ -323,14 +323,14 @@ class MicrodescriptorExitPolicy(ExitPolicy):
rules.append(MicroExitPolicyRule(self.is_accept, int(min_port), int(max_port)))
- super(MicrodescriptorExitPolicy, self).__init__(*rules)
+ super(MicroExitPolicy, self).__init__(*rules)
self._set_default_allowed(not self.is_accept)
def __str__(self):
return self._policy
def __eq__(self, other):
- if isinstance(other, MicrodescriptorExitPolicy):
+ if isinstance(other, MicroExitPolicy):
return str(self) == str(other)
else:
return False
diff --git a/test/unit/descriptor/router_status_entry.py b/test/unit/descriptor/router_status_entry.py
index ef03baa..fd668d2 100644
--- a/test/unit/descriptor/router_status_entry.py
+++ b/test/unit/descriptor/router_status_entry.py
@@ -7,7 +7,7 @@ import unittest
from stem.descriptor import Flag
from stem.descriptor.router_status_entry import RouterStatusEntryV3, _decode_fingerprint
-from stem.exit_policy import MicrodescriptorExitPolicy
+from stem.exit_policy import MicroExitPolicy
from stem.version import Version
from test.mocking import get_router_status_entry_v2, \
@@ -439,8 +439,8 @@ class TestRouterStatusEntry(unittest.TestCase):
"""
test_values = {
- "reject 1-65535": MicrodescriptorExitPolicy("reject 1-65535"),
- "accept 80,110,143,443": MicrodescriptorExitPolicy("accept 80,110,143,443"),
+ "reject 1-65535": MicroExitPolicy("reject 1-65535"),
+ "accept 80,110,143,443": MicroExitPolicy("accept 80,110,143,443"),
}
for p_line, expected in test_values.items():
diff --git a/test/unit/descriptor/server_descriptor.py b/test/unit/descriptor/server_descriptor.py
index e0a86fb..62eb033 100644
--- a/test/unit/descriptor/server_descriptor.py
+++ b/test/unit/descriptor/server_descriptor.py
@@ -264,7 +264,7 @@ class TestServerDescriptor(unittest.TestCase):
Checks a 'ipv6-policy' line.
"""
- expected = stem.exit_policy.MicrodescriptorExitPolicy("accept 22-23,53,80,110")
+ expected = stem.exit_policy.MicroExitPolicy("accept 22-23,53,80,110")
desc = get_relay_server_descriptor({"ipv6-policy": "accept 22-23,53,80,110"})
self.assertEquals(expected, desc.exit_policy_v6)
diff --git a/test/unit/exit_policy/policy.py b/test/unit/exit_policy/policy.py
index 831009e..c4e675e 100644
--- a/test/unit/exit_policy/policy.py
+++ b/test/unit/exit_policy/policy.py
@@ -5,18 +5,18 @@ Unit tests for the stem.exit_policy.ExitPolicy class.
import unittest
from stem.exit_policy import ExitPolicy, \
- MicrodescriptorExitPolicy, \
+ MicroExitPolicy, \
ExitPolicyRule
class TestExitPolicy(unittest.TestCase):
def test_example(self):
- # tests the ExitPolicy and MicrodescriptorExitPolicy pydoc examples
+ # tests the ExitPolicy and MicroExitPolicy pydoc examples
policy = ExitPolicy("accept *:80", "accept *:443", "reject *:*")
self.assertEquals("accept *:80, accept *:443, reject *:*", str(policy))
self.assertEquals("accept 80, 443", policy.summary())
self.assertTrue(policy.can_exit_to("75.119.206.243", 80))
- policy = MicrodescriptorExitPolicy("accept 80,443")
+ policy = MicroExitPolicy("accept 80,443")
self.assertTrue(policy.can_exit_to("75.119.206.243", 80))
def test_constructor(self):
@@ -145,7 +145,7 @@ class TestExitPolicy(unittest.TestCase):
for policy_arg, expect_success in test_inputs.items():
try:
- policy = MicrodescriptorExitPolicy(policy_arg)
+ policy = MicroExitPolicy(policy_arg)
if expect_success:
self.assertEqual(policy_arg, str(policy))
@@ -158,15 +158,15 @@ class TestExitPolicy(unittest.TestCase):
# checks that its is_accept attribute is properly set
# single port
- policy = MicrodescriptorExitPolicy('accept 443')
+ policy = MicroExitPolicy('accept 443')
self.assertTrue(policy.is_accept)
# multiple ports
- policy = MicrodescriptorExitPolicy('accept 80,443')
+ policy = MicroExitPolicy('accept 80,443')
self.assertTrue(policy.is_accept)
# port range
- policy = MicrodescriptorExitPolicy('reject 1-1024')
+ policy = MicroExitPolicy('reject 1-1024')
self.assertFalse(policy.is_accept)
def test_microdescriptor_can_exit_to(self):
@@ -178,13 +178,13 @@ class TestExitPolicy(unittest.TestCase):
}
for policy_arg, attr in test_inputs.items():
- policy = MicrodescriptorExitPolicy(policy_arg)
+ policy = MicroExitPolicy(policy_arg)
for port, expected_value in attr.items():
self.assertEqual(expected_value, policy.can_exit_to(port = port))
# address argument should be ignored
- policy = MicrodescriptorExitPolicy('accept 80,443')
+ policy = MicroExitPolicy('accept 80,443')
self.assertFalse(policy.can_exit_to('127.0.0.1', 79))
self.assertTrue(policy.can_exit_to('127.0.0.1', 80))
More information about the tor-commits
mailing list