'Construct the "path" of this key as a list.
Returns:
A list [kind_1, id_or_name_1, ..., kind_n, id_or_name_n] of the key path.
Raises:
datastore_errors.BadKeyError if this key does not have a valid path.'

def to_path(self, _default_id=None, _decode=True, _fail=True):

    def Decode(s):
        if _decode:
            try:
                return s.decode('utf-8')
            except UnicodeDecodeError:
                if _fail:
                    raise
        return s
    path = []
    for path_element in self.__reference.path().element_list():
        path.append(Decode(path_element.type()))
        if path_element.has_name():
            path.append(Decode(path_element.name()))
        elif path_element.has_id():
            path.append(path_element.id())
        elif (_default_id is not None):
            path.append(_default_id)
        else:
            raise datastore_errors.BadKeyError('Incomplete    key    found    in    to_path')
    return path
