[Code-review] review: Gadget alias branch

Dafydd Harries dafydd.harries at collabora.co.uk
Wed Aug 13 14:03:37 EDT 2008


>-    __slots__ = ('jid', 'properties', 'current_activity')
>+    __slots__ = ('jid', 'properties', 'current_activity', 'alias')

Having special cases for this worries me somewhat. I think ideally, activities
and buddies would both just be a{sv}s. Special cases add a lot of complexity.
Do you think it would be possible for Gadget to communicate aliases by
including them in the properties dict?

>+    def buddy_view(self, size, properties, handler, alias=None):
>+        def test(buddy):
>+            if alias is not None and buddy.alias != alias:
>+                return False

I don't think exact string match is the right approach here. I should be able
to find you if I search for "Guillaume", even if your alias is actually
"Guillaume Desmottes". Doing a substring match seems like a reasonable
approach, though perhaps stripping combining characters would be even better.

   def strip_nonspacing_marks(s):
    return ''.join([c
        for c in unicodedata.normalize('NFD', s)
        if unicodedata.category(c) != 'Mn'])

   def match(x, y):
       return (strip_nonspacing_marks(x).lower() in
               strip_nonspacing_marks(y).lower())

   def _test_match():
       r"""
       >>> match(u'oo', u'foo')
       True
       >>> match(u'aa', u'foo')
       False

       U+00D3 is LATIN CAPITAL LETTER O WITH ACUTE

       >>> match(u'oo', u'fo\xd3')
       True
       >>> match(u'o\xd3', u'fo\xd3')
       True
       >>> match(u'o\xd3', u'foo')
       True
       """

-- 
Dafydd


More information about the Code-review mailing list