commit 59ed7fdd4f90fe6ac804b7b24dfdc0c3f2bc68dd Author: Damian Johnson atagar@torproject.org Date: Thu Jul 19 08:47:43 2012 -0700
Using the ExitPolicy class for ServerDescriptors
The ServerDescriptor class had a todo item to replace the lists of strings that it was using for an exit policy with the ExitPolicy class when we had one. Making it so... --- stem/descriptor/server_descriptor.py | 7 +++++-- test/integ/descriptor/server_descriptor.py | 7 ++++--- 2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py index fc15a3d..730709f 100644 --- a/stem/descriptor/server_descriptor.py +++ b/stem/descriptor/server_descriptor.py @@ -35,6 +35,7 @@ import datetime import stem.prereq import stem.descriptor import stem.descriptor.extrainfo_descriptor +import stem.exit_policy import stem.version import stem.util.log as log import stem.util.connection @@ -204,7 +205,7 @@ class ServerDescriptor(stem.descriptor.Descriptor): self.operating_system = None self.uptime = None self.contact = None - self.exit_policy = [] # should be an ExitPolicy instance when we have the class... + self.exit_policy = None self.family = []
self.average_bandwidth = None @@ -241,8 +242,10 @@ class ServerDescriptor(stem.descriptor.Descriptor): # influences the resulting exit policy, but for everything else the order # does not matter so breaking it into key / value pairs.
- entries, first_keyword, last_keyword, self.exit_policy = \ + entries, first_keyword, last_keyword, policy = \ stem.descriptor._get_descriptor_components(raw_contents, validate, ("accept", "reject")) + + self.exit_policy = stem.exit_policy.ExitPolicy(*policy) self._parse(entries, validate) if validate: self._check_constraints(entries, first_keyword, last_keyword)
diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py index 7a3e2e6..38d633c 100644 --- a/test/integ/descriptor/server_descriptor.py +++ b/test/integ/descriptor/server_descriptor.py @@ -9,6 +9,7 @@ import datetime import unittest
import stem.control +import stem.exit_policy import stem.version import stem.descriptor.server_descriptor import test.runner @@ -80,7 +81,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= self.assertEquals(153600, desc.average_bandwidth) self.assertEquals(256000, desc.burst_bandwidth) self.assertEquals(104590, desc.observed_bandwidth) - self.assertEquals(["reject *:*"], desc.exit_policy) + self.assertEquals(stem.exit_policy.ExitPolicy("reject *:*"), desc.exit_policy) self.assertEquals(expected_onion_key, desc.onion_key) self.assertEquals(expected_signing_key, desc.signing_key) self.assertEquals(expected_signature, desc.signature) @@ -211,7 +212,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= self.assertEquals(81920, desc.average_bandwidth) self.assertEquals(102400, desc.burst_bandwidth) self.assertEquals(84275, desc.observed_bandwidth) - self.assertEquals(["reject *:*"], desc.exit_policy) + self.assertEquals(stem.exit_policy.ExitPolicy("reject *:*"), desc.exit_policy) self.assertEquals([], desc.get_unrecognized_lines())
def test_cr_in_contact_line(self): @@ -309,7 +310,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= self.assertEquals(409600, desc.average_bandwidth) self.assertEquals(819200, desc.burst_bandwidth) self.assertEquals(5120, desc.observed_bandwidth) - self.assertEquals(["reject *:*"], desc.exit_policy) + self.assertEquals(stem.exit_policy.ExitPolicy("reject *:*"), desc.exit_policy) self.assertEquals("006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4", desc.digest()) self.assertEquals([], desc.get_unrecognized_lines())