def _get_attribute(element, attrname):
    """
    Get attribute from an element.

    Wrapper over Element.attrib, as this doesn't fallback to the element
    namespace if the attribute is qnamed and the requested attribute name
    is not.

    Ex:
        <ns:elem attr1="value1" ns:attr2="value2"/>

        _get_attribute(elem, "attr1") -> value1
        _get_attribute(elem, "attr2") -> value2
        _get_attribute(elem, "{uri}:attr1") -> Error
        _get_attribute(elem, "{uri}:attr2") -> value2
    """
    isns = (attrname[0] == '{')

    #
    # Handle qnamed request: 
    #   attrname = {uri}name
    #
    if isns:
        return element.attrib.get(attrname, "")

    #
    # Handle non-qnamed request and non-qnamed actual_attr
    #   attrname = name
    #   actual_attr = name
    #
    if attrname in element.attrib:
        return element.attrib.get(attrname, "")

    #
    # Handle non-qnamed request but qnamed actualAttr
    #   attrname = name
    #   actual_attr = {uri}name
    #
    tag_uri = element.tag[0: element.tag.find('}') + 1]
    return element.attrib.get(tag_uri + attrname, "")