Beispiel #1
0
  def __normalize_and_convert_keys(cls, keys):
    """Normalize and convert all keys to BlobKey type.

    This method is based on datastore.NormalizeAndTypeCheck().

    Args:
      keys: A single key or a list/tuple of keys.  Keys may be a string
        or BlobKey

    Returns:
      Single key or list with all strings replaced by BlobKey instances.
    """
    if isinstance(keys, (list, tuple)):
      multiple = True
      keys = list(keys)
    else:
      multiple = False
      keys = [keys]

    for index, key in enumerate(keys):
      if not isinstance(key, (basestring, BlobKey)):
        raise datastore_errors.BadArgumentError(
            'Expected str or BlobKey; received %s (a %s)' % (
                key,
                datastore.typename(key)))
      keys[index] = datastore.Key.from_path(cls.kind(), str(key))

    if multiple:
      return keys
    else:
      return keys[0]
Beispiel #2
0
    def __normalize_and_convert_keys(cls, keys):
        """Normalize and convert all keys to BlobKey type.

    This method is based on datastore.NormalizeAndTypeCheck().

    Args:
      keys: A single key or a list/tuple of keys.  Keys may be a string
        or BlobKey

    Returns:
      Single key or list with all strings replaced by BlobKey instances.
    """
        if isinstance(keys, (list, tuple)):
            multiple = True

            keys = list(keys)
        else:
            multiple = False
            keys = [keys]

        for index, key in enumerate(keys):
            if not isinstance(key, (basestring, BlobKey)):
                raise datastore_errors.BadArgumentError(
                    'Expected str or BlobKey; received %s (a %s)' %
                    (key, datastore.typename(key)))
            keys[index] = datastore.Key.from_path(cls.kind(),
                                                  str(key),
                                                  namespace='')

        if multiple:
            return keys
        else:
            return keys[0]
def _to_mutexes(mutexes_or_keys):
  """Normalizes and type checks the given sequence.

  Args:
    mutexes_or_keys: sequence of Mutex objects or keys

  Returns:
    list of Mutexes
  """
  mutexes = []

  for arg in mutexes_or_keys:
    if isinstance(arg, Mutex):
      mutexes.append(arg)
    elif isinstance(arg, db.Key):
      mutexes.append(Mutex.get(arg))
    else:
      raise db.BadArgumentError(
          'Expected a Mutex instance or key; received %s (a %s).' %
          (arg, datastore.typename(arg)))

  return mutexes