'Returns negative, zero, or positive when comparing two keys.
TODO: for API v2, we should change this to make incomplete keys, ie
keys without an id or name, not equal to any other keys.
Args:
other: Key to compare to.
Returns:
Negative if self is less than "other"
Zero if "other" is equal to self
Positive if self is greater than "other"'

def __cmp__(self, other):

    if (not isinstance(other, Key)):
        return (-2)
    self_args = [self.__reference.app(), self.__reference.name_space()]
    self_args += self.to_path(_default_id=0, _decode=False)
    other_args = [other.__reference.app(), other.__reference.name_space()]
    other_args += other.to_path(_default_id=0, _decode=False)
    for (self_component, other_component) in zip(self_args, other_args):
        comparison = cmp(self_component, other_component)
        if (comparison != 0):
            return comparison
    return cmp(len(self_args), len(other_args))
