import operator


def freeze_dict(dict_):
    """Freezes ``dict`` into ``tuple``.

    A typical usage is packing ``dict`` into hashable.

    e.g.::

        >>> freeze_dict({'a': 1, 'b': 2})
        (('a', 1), ('b', 2))
    """
    pairs = dict_.items()
    key_getter = operator.itemgetter(0)
    return tuple(sorted(pairs, key=key_getter))


class BoundTypeProperty(object):
    """This kind of property creates subclasses of given class for each
    instance.

    Those subclasses means "bound type" which be used for identifying
    themselves with blinker/Flask signals.

    e.g.::

        >>> class Foo(object):
        ...     pass
        >>> class Bar(object):
        ...     Foo = BoundTypeProperty('Foo', Foo)
        >>>
        >>> Bar.Foo
        BoundTypeProperty('Foo', Foo)
        >>> bar = Bar()
        >>> bar.Foo is Foo
        False
        >>> issubclass(bar.Foo, Foo)
        True
        >>> egg = Bar()
        >>> egg.Foo is bar.Foo
        False
        >>> egg.Foo.__bases__ == bar.Foo.__bases__ == (Foo,)
        True

    :param name: the name of this property.
    :param cls: the base class of all bound classes.
    """

    def __init__(self, name, cls):
        self.name = name
        self.cls = cls

    def __repr__(self):
        return 'BoundTypeProperty(%r, %s)' % (self.name, self.cls.__name__)

    def __get__(self, instance, owner):
        if instance is None:
            return self
        ns = vars(instance)  # the instance namespace
        if self.name not in ns:
            ns[self.name] = type(self.name, (self.cls,), {})
        return ns[self.name]

@@ -9,16 +9,35 @@
 perator%0A
+import collections%0A
 %0A%0Adef fr
@@ -358,16 +358,569 @@
 ter))%0A%0A%0A
+def join_html_attrs(attrs):%0A    %22%22%22Joins the map structure into HTML attributes.%0A%0A    The return value is a 2-tuple %60%60(template, ordered_values)%60%60. It should be%0A    passed into :class:%60markupsafe.Markup%60 to prevent XSS attacked.%0A%0A    e.g.::%0A%0A        %3E%3E%3E join_html_attrs(%7B'href': '/', 'data-active': 'true'%7D)%0A        ('data-active=%22%7B0%7D%22 href=%22%7B1%7D%22', %5B'true', '/'%5D)%0A    %22%22%22%0A    attrs = collections.OrderedDict(freeze_dict(attrs or %7B%7D))%0A    template = ' '.join('%25s=%22%7B%25d%7D%22' %25 (k, i) for i, k in enumerate(attrs))%0A    return template, list(attrs.values())%0A%0A%0A
 class Bo

add utility to make dict into html attrs.