Commit b4fd22bd authored by Robin Obůrka's avatar Robin Obůrka

messages: Add restriction to the message type

parent cf8742d0
......@@ -6,5 +6,9 @@ class InvalidMsgError(SentinelError):
pass
class InvalidMsgTypeError(InvalidMsgError):
pass
class SockConfigError(SentinelError):
pass
import re
import msgpack
from .exceptions import *
SN_MSG_REGEXP = "^([a-z0-9_]|[a-z0-9_]+/)([a-z0-9_]+/)+[a-z0-9_]+$"
SN_MSG = re.compile(SN_MSG_REGEXP)
def parse_msg(data):
""" Gets a Sentinel-type ZMQ message and parses message type and its
payload.
"""
try:
msg_type = str(data[0], encoding="UTF-8")
if not SN_MSG.match(msg_type):
raise InvalidMsgTypeError("Bad message type definition")
payload = msgpack.unpackb(data[1], encoding="UTF-8")
except IndexError:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment