'Constructor. Creates a Key from a string.
Args:
# a base64-encoded primary key, generated by Key.__str__
encoded: str'

def __init__(self, encoded=None):

    self._str = None
    if (encoded is not None):
        if (not isinstance(encoded, basestring)):
            try:
                repr_encoded = repr(encoded)
            except:
                repr_encoded = "<couldn't    encode>"
            raise datastore_errors.BadArgumentError(('Key()    expects    a    string;    received    %s    (a    %s).' % (repr_encoded, typename(encoded))))
        try:
            modulo = (len(encoded) % 4)
            if (modulo != 0):
                encoded += ('=' * (4 - modulo))
            self._str = str(encoded)
            encoded_pb = base64.urlsafe_b64decode(self._str)
            self.__reference = entity_pb.Reference(encoded_pb)
            assert self.__reference.IsInitialized()
            self._str = self._str.rstrip('=')
        except (AssertionError, TypeError) as e:
            raise datastore_errors.BadKeyError(('Invalid    string    key    %s.    Details:    %s' % (encoded, e)))
        except Exception as e:
            if (e.__class__.__name__ == 'ProtocolBufferDecodeError'):
                raise datastore_errors.BadKeyError(('Invalid    string    key    %s.' % encoded))
            else:
                raise
    else:
        self.__reference = entity_pb.Reference()
