From 9dca3ed02e869faba5e849be68650d36617c14ce Mon Sep 17 00:00:00 2001 From: Nick Daly Date: Sun, 13 May 2012 09:47:56 -0500 Subject: [PATCH] Santiago now knows required and optional keys at class level This abstraction makes message processing more intuitive. --- ugly_hacks/santiago/simplesantiago.py | 12 +++++++++--- ugly_hacks/santiago/test_santiago.py | 8 ++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ugly_hacks/santiago/simplesantiago.py b/ugly_hacks/santiago/simplesantiago.py index 17e9a0e04..cb6e583b4 100644 --- a/ugly_hacks/santiago/simplesantiago.py +++ b/ugly_hacks/santiago/simplesantiago.py @@ -65,7 +65,13 @@ class Santiago(object): protocols. """ - supported_protocols = set([1]) + SUPPORTED_PROTOCOLS = set([1]) + ALL_KEYS = ("host", "client", "service", "locations", "reply_to", + "request_version", "reply_versions") + REQUIRED_KEYS = ("client", "host", "service", + "request_version", "reply_versions") + OPTIONAL_KEYS = ("locations", "reply_to") + LIST_KEYS = ("reply_to", "locations", "reply_versions") def __init__(self, listeners = None, senders = None, hosting = None, consuming = None, me = 0): @@ -282,10 +288,10 @@ class Santiago(object): ("request", "request_version", "reply_versions")): return False - if not (Santiago.supported_protocols & set(request["reply_versions"])): + if not (Santiago.SUPPORTED_PROTOCOLS & set(request["reply_versions"])): return False - if not (Santiago.supported_protocols & + if not (Santiago.SUPPORTED_PROTOCOLS & set([request["request_version"]])): return False diff --git a/ugly_hacks/santiago/test_santiago.py b/ugly_hacks/santiago/test_santiago.py index 3c391638d..a871c77bb 100644 --- a/ugly_hacks/santiago/test_santiago.py +++ b/ugly_hacks/santiago/test_santiago.py @@ -496,13 +496,13 @@ class VerifyRequest(unittest.TestCase): def test_require_protocol_version_overlap(self): """Clients that can't accept protocols I can send are ignored.""" - santiago.Santiago.supported_protocols, unsupported = \ - set(["e"]), santiago.Santiago.supported_protocols + santiago.Santiago.SUPPORTED_PROTOCOLS, unsupported = \ + set(["e"]), santiago.Santiago.SUPPORTED_PROTOCOLS self.assertFalse(self.santiago.verify_request(self.request)) - santiago.Santiago.supported_protocols, unsupported = \ - unsupported, santiago.Santiago.supported_protocols + santiago.Santiago.SUPPORTED_PROTOCOLS, unsupported = \ + unsupported, santiago.Santiago.SUPPORTED_PROTOCOLS def test_require_protocol_version_understanding(self): """I must ignore any protocol versions I can't understand."""