thirdparty/google_appengine/google/appengine/api/datastore.py
changeset 686 df109be0567c
parent 297 35211afcd563
child 828 f5fd65cc3bf3
equal deleted inserted replaced
685:a440ced9a75f 686:df109be0567c
   241   Args:
   241   Args:
   242     # the primary key(s) of the entity(ies) to delete
   242     # the primary key(s) of the entity(ies) to delete
   243     keys: Key or string or list of Keys or strings
   243     keys: Key or string or list of Keys or strings
   244 
   244 
   245   Raises:
   245   Raises:
   246     TransactionFailedError, if the Put could not be committed.
   246     TransactionFailedError, if the Delete could not be committed.
   247   """
   247   """
   248   keys, multiple = NormalizeAndTypeCheckKeys(keys)
   248   keys, multiple = NormalizeAndTypeCheckKeys(keys)
   249 
   249 
   250   if multiple and not keys:
   250   if multiple and not keys:
   251     return
   251     return
   880     except apiproxy_errors.ApplicationError, err:
   880     except apiproxy_errors.ApplicationError, err:
   881       try:
   881       try:
   882         _ToDatastoreError(err)
   882         _ToDatastoreError(err)
   883       except datastore_errors.NeedIndexError, exc:
   883       except datastore_errors.NeedIndexError, exc:
   884         yaml = datastore_index.IndexYamlForQuery(
   884         yaml = datastore_index.IndexYamlForQuery(
   885           *datastore_index.CompositeIndexForQuery(pb)[:-1])
   885           *datastore_index.CompositeIndexForQuery(pb)[1:-1])
   886         raise datastore_errors.NeedIndexError(
   886         raise datastore_errors.NeedIndexError(
   887           str(exc) + '\nThis query needs this index:\n' + yaml)
   887           str(exc) + '\nThis query needs this index:\n' + yaml)
   888 
   888 
   889     return Iterator._FromPb(result.cursor())
   889     return Iterator._FromPb(result.cursor())
   890 
   890 
   974     the value is not a supported type, raises BadValueError.
   974     the value is not a supported type, raises BadValueError.
   975     """
   975     """
   976     if isinstance(value, tuple):
   976     if isinstance(value, tuple):
   977       value = list(value)
   977       value = list(value)
   978 
   978 
   979     datastore_types.ValidateProperty(' ', value)
   979     datastore_types.ValidateProperty(' ', value, read_only=True)
   980     match = self._CheckFilter(filter, value)
   980     match = self._CheckFilter(filter, value)
   981     property = match.group(1)
   981     property = match.group(1)
   982     operator = match.group(3)
   982     operator = match.group(3)
   983 
   983 
   984     dict.__setitem__(self, filter, value)
   984     dict.__setitem__(self, filter, value)
  1063       raise datastore_errors.BadFilterError(
  1063       raise datastore_errors.BadFilterError(
  1064         'Could not parse filter string: %s' % str(filter))
  1064         'Could not parse filter string: %s' % str(filter))
  1065 
  1065 
  1066     property = match.group(1)
  1066     property = match.group(1)
  1067     operator = match.group(3)
  1067     operator = match.group(3)
       
  1068     if operator is None:
       
  1069       operator = '='
  1068 
  1070 
  1069     if isinstance(values, tuple):
  1071     if isinstance(values, tuple):
  1070       values = list(values)
  1072       values = list(values)
  1071     elif not isinstance(values, list):
  1073     elif not isinstance(values, list):
  1072       values = [values]
  1074       values = [values]
  1085       elif len(self.__orderings) >= 1 and self.__orderings[0][0] != property:
  1087       elif len(self.__orderings) >= 1 and self.__orderings[0][0] != property:
  1086         raise datastore_errors.BadFilterError(
  1088         raise datastore_errors.BadFilterError(
  1087           'Inequality operators (%s) must be on the same property as the '
  1089           'Inequality operators (%s) must be on the same property as the '
  1088           'first sort order, if any sort orders are supplied' %
  1090           'first sort order, if any sort orders are supplied' %
  1089           ', '.join(self.INEQUALITY_OPERATORS))
  1091           ', '.join(self.INEQUALITY_OPERATORS))
       
  1092     elif property in datastore_types._SPECIAL_PROPERTIES:
       
  1093       if property == datastore_types._KEY_SPECIAL_PROPERTY:
       
  1094         for value in values:
       
  1095           if not isinstance(value, Key):
       
  1096             raise datastore_errors.BadFilterError(
       
  1097               '%s filter value must be a Key; received %s (a %s)' %
       
  1098               (datastore_types._KEY_SPECIAL_PROPERTY, value, typename(value)))
  1090 
  1099 
  1091     return match
  1100     return match
  1092 
  1101 
  1093   def _ToPb(self, limit=None, offset=None):
  1102   def _ToPb(self, limit=None, offset=None):
  1094     """Converts this Query to its protocol buffer representation. Not
  1103     """Converts this Query to its protocol buffer representation. Not