uv

Finished
4848 regex_matches = self.regex.search(str(value))
4949 invalid_input = regex_matches if self.inverse_match else not regex_matches
5050 if invalid_input:
51 raise ValidationError(self.message, code=self.code)
51 raise ValidationError(self.message, code=self.code, params={'value': value})
5252
5353 def __eq__(self, other):
5454 return (
100100
101101 def __call__(self, value):
102102 if not isinstance(value, str):
103 raise ValidationError(self.message, code=self.code)
103 raise ValidationError(self.message, code=self.code, params={'value': value})
104 if value.rstrip() != value:
105 raise ValidationError(self.message, code=self.code, params={'value': value})
104106 # Check if the scheme is valid.
105107 scheme = value.split('://')[0].lower()
106108 if scheme not in self.schemes:
107 raise ValidationError(self.message, code=self.code)
109 raise ValidationError(self.message, code=self.code, params={'value': value})
108110
109111 # Then check full URL
110112 try:
115117 try:
116118 scheme, netloc, path, query, fragment = urlsplit(value)
117119 except ValueError: # for example, "Invalid IPv6 URL"
118 raise ValidationError(self.message, code=self.code)
120 raise e
119121 try:
120122 netloc = punycode(netloc) # IDN -> ACE
121123 except UnicodeError: # invalid domain part
126128 raise
127129 else:
128130 # Now verify IPv6 in the netloc part
129 host_match = re.search(r'^\[(.+)\](?::\d{2,5})?$', urlsplit(value).netloc)
131 try:
132 netloc = urlsplit(value).netloc
133 except ValueError: # for example, "Invalid IPv6 URL"
134 raise ValidationError(self.message, code=self.code, params={'value': value})
135 host_match = re.search(r'^\[(.+)\](?::\d{2,5})?$', netloc)
130136 if host_match:
131137 potential_ip = host_match[1]
132138 try:
133139 validate_ipv6_address(potential_ip)
134140 except ValidationError:
135 raise ValidationError(self.message, code=self.code)
141 raise ValidationError(self.message, code=self.code, params={'value': value})
136142
137143 # The maximum length of a full host name is 253 characters per RFC 1034
138144 # section 3.1. It's defined to be 255 bytes or less, but this includes
139145 # one byte for the length of the name and one byte for the trailing dot
140146 # that's used to indicate absolute names in DNS.
141147 if len(urlsplit(value).netloc) > 253:
142 raise ValidationError(self.message, code=self.code)
148 raise ValidationError(self.message, code=self.code, params={'value': value})
143149
144150
145151integer_validator = RegexValidator(
208214
209215 def __call__(self, value):
210216 if not value or '@' not in value:
211 raise ValidationError(self.message, code=self.code)
217 raise ValidationError(self.message, code=self.code, params={'value': value})
212218
213219 user_part, domain_part = value.rsplit('@', 1)
214220
215221 if not self.user_regex.match(user_part):
216 raise ValidationError(self.message, code=self.code)
222 raise ValidationError(self.message, code=self.code, params={'value': value})
217223
218224 if (domain_part not in self.domain_allowlist and
219225 not self.validate_domain_part(domain_part)):
225231 else:
226232 if self.validate_domain_part(domain_part):
227233 return
228 raise ValidationError(self.message, code=self.code)
234 raise ValidationError(self.message, code=self.code, params={'value': value})
229235
230236 def validate_domain_part(self, domain_part):
231237 if self.domain_regex.match(domain_part):
272278 try:
273279 ipaddress.IPv4Address(value)
274280 except ValueError:
275 raise ValidationError(_('Enter a valid IPv4 address.'), code='invalid')
281 raise ValidationError(_('Enter a valid IPv4 address.'), code='invalid', params={'value': value})
276282
277283
278284def validate_ipv6_address(value):
279285 if not is_valid_ipv6_address(value):
280 raise ValidationError(_('Enter a valid IPv6 address.'), code='invalid')
286 raise ValidationError(_('Enter a valid IPv6 address.'), code='invalid', params={'value': value})
281287
282288
283289def validate_ipv46_address(value):
287293 try:
288294 validate_ipv6_address(value)
289295 except ValidationError:
290 raise ValidationError(_('Enter a valid IPv4 or IPv6 address.'), code='invalid')
296 raise ValidationError(_('Enter a valid IPv4 or IPv6 address.'), code='invalid', params={'value': value})
291297
292298
293299ip_address_validator_map = {
438444 def __call__(self, value):
439445 digit_tuple, exponent = value.as_tuple()[1:]
440446 if exponent in {'F', 'n', 'N'}:
441 raise ValidationError(self.messages['invalid'])
447 raise ValidationError(self.messages['invalid'], params={'value': value})
442448 if exponent >= 0:
443449 # A positive exponent adds that many trailing zeros.
444450 digits = len(digit_tuple) + exponent
460466 raise ValidationError(
461467 self.messages['max_digits'],
462468 code='max_digits',
463 params={'max': self.max_digits},
469 params={'max': self.max_digits, 'value': value},
464470 )
465471 if self.decimal_places is not None and decimals > self.decimal_places:
466472 raise ValidationError(
467473 self.messages['max_decimal_places'],
468474 code='max_decimal_places',
469 params={'max': self.decimal_places},
475 params={'max': self.decimal_places, 'value': value},
470476 )
471477 if (self.max_digits is not None and self.decimal_places is not None and
472478 whole_digits > (self.max_digits - self.decimal_places)):
473479 raise ValidationError(
474480 self.messages['max_whole_digits'],
475481 code='max_whole_digits',
476 params={'max': (self.max_digits - self.decimal_places)},
482 params={'max': (self.max_digits - self.decimal_places), 'value': value},
477483 )
478484
479485 def __eq__(self, other):
550556
551557 def __call__(self, value):
552558 if '\x00' in str(value):
553 raise ValidationError(self.message, code=self.code)
559 raise ValidationError(self.message, code=self.code, params={'value': value})
554560
555561 def __eq__(self, other):
556562 return (
Test NameStatus
test_value_placeholder_with_decimal_field (forms_tests.tests.test_validators.ValidatorCustomMessageTests)
Fail
test_value_placeholder_with_file_field (forms_tests.tests.test_validators.ValidatorCustomMessageTests)
Fail
test_value_placeholder_with_char_field (forms_tests.tests.test_validators.ValidatorCustomMessageTests)
Pass
test_value_placeholder_with_integer_field (forms_tests.tests.test_validators.ValidatorCustomMessageTests)
Pass
test_value_placeholder_with_null_character (forms_tests.tests.test_validators.ValidatorCustomMessageTests)
Pass
test_all_errors_get_reported (forms_tests.tests.test_validators.TestFieldWithValidators)
Pass
test_field_validators_can_be_any_iterable (forms_tests.tests.test_validators.TestFieldWithValidators)
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.