'Add an alias from this namespace URI to the desired alias'

def addAlias(self, namespace_uri, desired_alias, implicit=False):

    assert (desired_alias not in OPENID_PROTOCOL_FIELDS), ('%r    is    not    an    allowed    namespace    alias' % (desired_alias,))
    if (type(desired_alias) in [str, unicode]):
        assert ('.' not in desired_alias), ('%r    must    not    contain    a    dot' % (desired_alias,))
    current_namespace_uri = self.alias_to_namespace.get(desired_alias)
    if ((current_namespace_uri is not None) and (current_namespace_uri != namespace_uri)):
        fmt = 'Cannot    map    %r    to    alias    %r.    %r    is    already    mapped    to    alias    %r'
        msg = (fmt % (namespace_uri, desired_alias, current_namespace_uri, desired_alias))
        raise KeyError(msg)
    alias = self.namespace_to_alias.get(namespace_uri)
    if ((alias is not None) and (alias != desired_alias)):
        fmt = 'Cannot    map    %r    to    alias    %r.    It    is    already    mapped    to    alias    %r'
        raise KeyError((fmt % (namespace_uri, desired_alias, alias)))
    assert ((desired_alias == NULL_NAMESPACE) or (type(desired_alias) in [str, unicode])), repr(desired_alias)
    assert (namespace_uri not in self.implicit_namespaces)
    self.alias_to_namespace[desired_alias] = namespace_uri
    self.namespace_to_alias[namespace_uri] = desired_alias
    if implicit:
        self.implicit_namespaces.append(namespace_uri)
    return desired_alias
