From ab68503fcf84e81b99e4bbf97f6d0e2631f0ec2e Mon Sep 17 00:00:00 2001
From: Tim Abbott <tabbott@humbughq.com>
Date: Wed, 28 Nov 2012 21:17:07 -0500
Subject: [PATCH] zephyr_mirror: Compare zephyr subs from server after
 normalization.

(imported from commit eea290698e83c7d26f23ab3bb0201914417f0e09)
---
 bots/zephyr_mirror_backend.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/bots/zephyr_mirror_backend.py b/bots/zephyr_mirror_backend.py
index f844e032..1b699d22 100755
--- a/bots/zephyr_mirror_backend.py
+++ b/bots/zephyr_mirror_backend.py
@@ -34,6 +34,7 @@ import textwrap
 import signal
 import logging
 import hashlib
+import unicodedata
 
 DEFAULT_SITE = "https://humbughq.com"
 
@@ -158,7 +159,12 @@ def zephyr_bulk_subscribe(subs):
         # (within 15 seconds).
         return
     for (cls, instance, recipient) in subs:
-        if cls not in actual_zephyr_subs:
+        # Zephyr class names are canonicalized by first applying NFKC
+        # normalization and then lower-casing server-side -- so we
+        # need to compare against those to see if we've successfully
+        # subscribed.
+        canonical_cls = unicodedata.normalize("NFKC", cls.decode("utf-8").lower()).encode("utf-8")
+        if canonical_cls not in actual_zephyr_subs:
             logging.error("Zephyr failed to subscribe us to %s; will retry" % (cls,))
             try:
                 # We'll retry automatically when we next check for