mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
Santiago now knows required and optional keys at class level
This abstraction makes message processing more intuitive.
This commit is contained in:
parent
edf035c222
commit
9dca3ed02e
@ -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
|
||||||
|
|
||||||
|
|||||||
@ -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."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user