Santiago now knows required and optional keys at class level

This abstraction makes message processing more intuitive.
This commit is contained in:
Nick Daly 2012-05-13 09:47:56 -05:00
parent edf035c222
commit 9dca3ed02e
2 changed files with 13 additions and 7 deletions

View File

@ -65,7 +65,13 @@ class Santiago(object):
protocols. 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, def __init__(self, listeners = None, senders = None,
hosting = None, consuming = None, me = 0): hosting = None, consuming = None, me = 0):
@ -282,10 +288,10 @@ class Santiago(object):
("request", "request_version", "reply_versions")): ("request", "request_version", "reply_versions")):
return False return False
if not (Santiago.supported_protocols & set(request["reply_versions"])): if not (Santiago.SUPPORTED_PROTOCOLS & set(request["reply_versions"])):
return False return False
if not (Santiago.supported_protocols & if not (Santiago.SUPPORTED_PROTOCOLS &
set([request["request_version"]])): set([request["request_version"]])):
return False return False

View File

@ -496,13 +496,13 @@ class VerifyRequest(unittest.TestCase):
def test_require_protocol_version_overlap(self): def test_require_protocol_version_overlap(self):
"""Clients that can't accept protocols I can send are ignored.""" """Clients that can't accept protocols I can send are ignored."""
santiago.Santiago.supported_protocols, unsupported = \ santiago.Santiago.SUPPORTED_PROTOCOLS, unsupported = \
set(["e"]), santiago.Santiago.supported_protocols set(["e"]), santiago.Santiago.SUPPORTED_PROTOCOLS
self.assertFalse(self.santiago.verify_request(self.request)) self.assertFalse(self.santiago.verify_request(self.request))
santiago.Santiago.supported_protocols, unsupported = \ santiago.Santiago.SUPPORTED_PROTOCOLS, unsupported = \
unsupported, santiago.Santiago.supported_protocols unsupported, santiago.Santiago.SUPPORTED_PROTOCOLS
def test_require_protocol_version_understanding(self): def test_require_protocol_version_understanding(self):
"""I must ignore any protocol versions I can't understand.""" """I must ignore any protocol versions I can't understand."""