我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用google.appengine.ext.db.BadValueError()。
def property_clean(prop, value): """Apply Property level validation to value. Calls .make_value_from_form() and .validate() on the property and catches exceptions generated by either. The exceptions are converted to forms.ValidationError exceptions. Args: prop: The property to validate against. value: The value to validate. Raises: forms.ValidationError if the value cannot be validated. """ if value is not None: try: prop.validate(prop.make_value_from_form(value)) except (db.BadValueError, ValueError), e: raise forms.ValidationError(unicode(e))
def _validate_filters_ndb(cls, filters, model_class): """Validate ndb.Model filters.""" if not filters: return properties = model_class._properties for f in filters: prop, _, val = f if prop not in properties: raise errors.BadReaderParamsError( "Property %s is not defined for entity type %s", prop, model_class._get_kind()) try: properties[prop]._do_validate(val) except db.BadValueError, e: raise errors.BadReaderParamsError(e)
def validate(self, value): if value is not None and not isinstance(value, Flow): raise db.BadValueError('Property %s must be convertible ' 'to a FlowThreeLegged instance (%s)' % (self.name, value)) return super(FlowProperty, self).validate(value)
def validate(self, value): value = super(CredentialsProperty, self).validate(value) logger.info("validate: Got type " + str(type(value))) if value is not None and not isinstance(value, Credentials): raise db.BadValueError('Property %s must be convertible ' 'to a Credentials instance (%s)' % (self.name, value)) return value
def validate(self, value): value = super(CredentialsProperty, self).validate(value) logger.info("validate: Got type " + str(type(value))) if value is not None and not isinstance(value, Credentials): raise db.BadValueError('Property %s must be convertible ' 'to a Credentials instance (%s)' % (self.name, value)) #if value is not None and not isinstance(value, Credentials): # return None return value
def test_behaviour(self): """ Test the behaviour of the Google SDK not handling ints gracefully """ with self.assertRaises(db.BadValueError): setattr(self.f, 'f', 3) self.f.f = 3.0 self.assertEqual(self.f.f, 3.0)
def validate(self, value): if value is not None and not isinstance(value, client.Flow): raise db.BadValueError( 'Property {0} must be convertible ' 'to a FlowThreeLegged instance ({1})'.format(self.name, value)) return super(FlowProperty, self).validate(value)
def validate(self, value): value = super(CredentialsProperty, self).validate(value) logger.info("validate: Got type " + str(type(value))) if value is not None and not isinstance(value, client.Credentials): raise db.BadValueError( 'Property {0} must be convertible ' 'to a Credentials instance ({1})'.format(self.name, value)) return value
def test_validate(self): appengine.FlowProperty().validate(None) with self.assertRaises(db.BadValueError): appengine.FlowProperty().validate(42)
def test_validate(self): appengine.CredentialsProperty().validate(self.credentials) appengine.CredentialsProperty().validate(None) with self.assertRaises(db.BadValueError): appengine.CredentialsProperty().validate(42)
def validate(self, value): value = super(GAEDecimalProperty, self).validate(value) if value is None or isinstance(value, decimal.Decimal): return value elif isinstance(value, basestring): return decimal.Decimal(value) raise gae.BadValueError("Property %s must be a Decimal or string."\ % self.name) ################################################################################### # class that handles connection pooling (all adapters are derived from this one) ###################################################################################
def validate(self, value): if isinstance(value, basestring): value = self.make_value_from_datastore(value) if not isinstance(value, self.model): raise db.BadValueError('Value must be of type %s' % self.model.__name__) if self.validator is not None: self.validator(value) return value
def validate(self, value): new_value = [] for item in value: if isinstance(item, basestring): item = self.make_value_from_datastore([item])[0] if not isinstance(item, self.model): raise db.BadValueError('Value must be of type %s' % self.model.__name__) new_value.append(item) if self.validator is not None: self.validator(new_value) return new_value
def validate(self, value): new_value = [] for item in value: if isinstance(item, basestring): item = db.Key(item) if isinstance(item, self.reference_class): item = item.key() if not isinstance(item, db.Key): raise db.BadValueError('Value must be a key or of type %s' % self.reference_class.__name__) new_value.append(item) return super(KeyListProperty, self).validate(new_value)
def validate(self, value): if value is not None and not isinstance(value, Flow): raise db.BadValueError( 'Property {0} must be convertible ' 'to a FlowThreeLegged instance ({1})'.format(self.name, value)) return super(FlowProperty, self).validate(value)
def validate(self, value): value = super(CredentialsProperty, self).validate(value) logger.info("validate: Got type " + str(type(value))) if value is not None and not isinstance(value, Credentials): raise db.BadValueError( 'Property {0} must be convertible ' 'to a Credentials instance ({1})'.format(self.name, value)) return value
def clean(self, value): """Override Field.clean() to do reference-specific value cleaning. This turns a non-empty value into a model instance. """ value = super(ModelChoiceField, self).clean(value) if not value: return None instance = db.get(value) if instance is None: raise db.BadValueError(self.error_messages['invalid_choice']) return instance
def _validate_filters(cls, filters, model_class): """Validate user supplied filters. Validate filters are on existing properties and filter values have valid semantics. Args: filters: user supplied filters. Each filter should be a list or tuple of format (<property_name_as_str>, <query_operator_as_str>, <value_of_certain_type>). Value type is up to the property's type. model_class: the db.Model class for the entity type to apply filters on. Raises: BadReaderParamsError: if any filter is invalid in any way. """ if not filters: return properties = model_class.properties() for f in filters: prop, _, val = f if prop not in properties: raise errors.BadReaderParamsError( "Property %s is not defined for entity type %s", prop, model_class.kind()) try: properties[prop].validate(val) except db.BadValueError, e: raise errors.BadReaderParamsError(e)