MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / validate

Method validate

mongoengine/fields.py:297–325  ·  view source on GitHub ↗
(self, value)

Source from the content-addressed store, hash-verified

295 return False
296
297 def validate(self, value):
298 super().validate(value)
299
300 if "@" not in value:
301 self.error(self.error_msg % value)
302
303 user_part, domain_part = value.rsplit("@", 1)
304
305 # Validate the user part.
306 if not self.validate_user_part(user_part):
307 self.error(self.error_msg % value)
308
309 # Validate the domain and, if invalid, see if it's IDN-encoded.
310 if not self.validate_domain_part(domain_part):
311 try:
312 domain_part = domain_part.encode("idna").decode("ascii")
313 except UnicodeError:
314 self.error(
315 "{} {}".format(
316 self.error_msg % value, "(domain failed IDN encoding)"
317 )
318 )
319 else:
320 if not self.validate_domain_part(domain_part):
321 self.error(
322 "{} {}".format(
323 self.error_msg % value, "(domain validation failed)"
324 )
325 )
326
327
328class IntField(BaseField):

Callers

nothing calls this directly

Calls 5

validate_user_partMethod · 0.95
validate_domain_partMethod · 0.95
errorMethod · 0.80
formatMethod · 0.80
validateMethod · 0.45

Tested by

no test coverage detected