From c38587191e43391979f9ea41561e9c98339f1782 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 9 Nov 2012 16:36:57 -0500 Subject: [PATCH] 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) --- bots/zephyr_mirror.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/bots/zephyr_mirror.py b/bots/zephyr_mirror.py index 4f90c21..de42067 100755 --- a/bots/zephyr_mirror.py +++ b/bots/zephyr_mirror.py @@ -263,10 +263,10 @@ def process_notice(notice, log): else: zeph['type'] = 'stream' zeph['stream'] = zephyr_class - if notice.instance != "": + if notice.instance.strip() != "": zeph['subject'] = notice.instance else: - zeph["subject"] = "(no instance)" + zeph["subject"] = '(instance "%s")' % (notice.instance,) # Add instances in for instanced personals if zeph['type'] == "personal" and notice.instance.lower() != "personal": @@ -367,11 +367,13 @@ def forward_to_zephyr(message): if message['type'] == "stream": zephyr_class = message["display_recipient"] instance = message["subject"] - if instance == "(no instance)": - # Forward messages sent to "(no instance)" back to the - # empty instance for bidirectional mirroring - instance = "" - if (instance == "instance %s" % (zephyr_class,) or + + match_whitespace_instance = re.match(r'^\(instance "(\s*)"\)$', instance) + if match_whitespace_instance: + # Forward messages sent to '(instance "WHITESPACE")' back to the + # 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,)): # Forward messages to e.g. -c -i white-magic back from the # place we forward them to