zephyr_mirror: Support whitespace-only zephyr instances.

Previously messages sent to zephyr instance " " wouldn't be forwarded
zephyr=>humbug because the target instance is the null instance; I
learned this when we got a few tracebacks in the zephyr_mirror log, so
clearly this does happen.

(imported from commit 08bd7470e75ac6af24ac83696b6cf68d70654664)
This commit is contained in:
Tim Abbott 2012-11-09 16:36:57 -05:00
parent cb0f48b59d
commit 7cafd7c6d0
1 changed files with 9 additions and 7 deletions

View File

@ -263,10 +263,10 @@ def process_notice(notice, log):
else: else:
zeph['type'] = 'stream' zeph['type'] = 'stream'
zeph['stream'] = zephyr_class zeph['stream'] = zephyr_class
if notice.instance != "": if notice.instance.strip() != "":
zeph['subject'] = notice.instance zeph['subject'] = notice.instance
else: else:
zeph["subject"] = "(no instance)" zeph["subject"] = '(instance "%s")' % (notice.instance,)
# Add instances in for instanced personals # Add instances in for instanced personals
if zeph['type'] == "personal" and notice.instance.lower() != "personal": if zeph['type'] == "personal" and notice.instance.lower() != "personal":
@ -367,11 +367,13 @@ def forward_to_zephyr(message):
if message['type'] == "stream": if message['type'] == "stream":
zephyr_class = message["display_recipient"] zephyr_class = message["display_recipient"]
instance = message["subject"] instance = message["subject"]
if instance == "(no instance)":
# Forward messages sent to "(no instance)" back to the match_whitespace_instance = re.match(r'^\(instance "(\s*)"\)$', instance)
# empty instance for bidirectional mirroring if match_whitespace_instance:
instance = "" # Forward messages sent to '(instance "WHITESPACE")' back to the
if (instance == "instance %s" % (zephyr_class,) or # appropriate WHITESPACE instance for bidirectional mirroring
instance = match_whitespace_instance.group(1)
elif (instance == "instance %s" % (zephyr_class,) or
instance == "test instance %s" % (zephyr_class,)): instance == "test instance %s" % (zephyr_class,)):
# Forward messages to e.g. -c -i white-magic back from the # Forward messages to e.g. -c -i white-magic back from the
# place we forward them to # place we forward them to