'Encodes this Key as an opaque string.
Returns a string representation of this key, suitable for use in HTML,
URLs, and other similar use cases. If the entity\'s key is incomplete,
raises a BadKeyError.
Unfortunately, this string encoding isn\'t particularly compact, and its
length varies with the length of the path. If you want a shorter identifier
and you know the kind and parent (if any) ahead of time, consider using just
the entity\'s id or name.
Returns:
string'

def __str__(self):

    try:
        if (self._str is not None):
            return self._str
    except AttributeError:
        pass
    if self.has_id_or_name():
        encoded = base64.urlsafe_b64encode(self.__reference.Encode())
        self._str = encoded.replace('=', '')
    else:
        raise datastore_errors.BadKeyError(('Cannot    string    encode    an    incomplete    key!\n%s' % self.__reference))
    return self._str
