tobe

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 # Check for trailing whitespace
105 if value != value.rstrip():
106 raise ValidationError(self.message, code=self.code, params={'value': value})
104107 # Check if the scheme is valid.
105108 scheme = value.split('://')[0].lower()
106109 if scheme not in self.schemes:
107 raise ValidationError(self.message, code=self.code)
110 raise ValidationError(self.message, code=self.code, params={'value': value})
108111
109112 # Then check full URL
110113 try:
115118 try:
116119 scheme, netloc, path, query, fragment = urlsplit(value)
117120 except ValueError: # for example, "Invalid IPv6 URL"
118 raise ValidationError(self.message, code=self.code)
121 raise ValidationError(self.message, code=self.code, params={'value': value})
119122 try:
120123 netloc = punycode(netloc) # IDN -> ACE
121124 except UnicodeError: # invalid domain part
126129 raise
127130 else:
128131 # Now verify IPv6 in the netloc part
129 host_match = re.search(r'^\[(.+)\](?::\d{2,5})?$', urlsplit(value).netloc)
130 if host_match:
131 potential_ip = host_match[1]
132 try:
133 validate_ipv6_address(potential_ip)
134 except ValidationError:
135 raise ValidationError(self.message, code=self.code)
132 try:
133 host_match = re.search(r'^\[(.+)\](?::\d{2,5})?$', urlsplit(value).netloc)
134 if host_match:
135 potential_ip = host_match[1]
136 try:
137 validate_ipv6_address(potential_ip)
138 except ValidationError:
139 raise ValidationError(self.message, code=self.code, params={'value': value})
140 except ValueError: # urlsplit failed
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.
141 if len(urlsplit(value).netloc) > 253:
142 raise ValidationError(self.message, code=self.code)
147 try:
148 if len(urlsplit(value).netloc) > 253:
149 raise ValidationError(self.message, code=self.code, params={'value': value})
150 except ValueError: # urlsplit failed
151 raise ValidationError(self.message, code=self.code, params={'value': value})
143152
144153
145154integer_validator = RegexValidator(
208217
209218 def __call__(self, value):
210219 if not value or '@' not in value:
211 raise ValidationError(self.message, code=self.code)
220 raise ValidationError(self.message, code=self.code, params={'value': value})
212221
213222 user_part, domain_part = value.rsplit('@', 1)
214223
215224 if not self.user_regex.match(user_part):
216 raise ValidationError(self.message, code=self.code)
225 raise ValidationError(self.message, code=self.code, params={'value': value})
217226
218227 if (domain_part not in self.domain_allowlist and
219228 not self.validate_domain_part(domain_part)):
225234 else:
226235 if self.validate_domain_part(domain_part):
227236 return
228 raise ValidationError(self.message, code=self.code)
237 raise ValidationError(self.message, code=self.code, params={'value': value})
229238
230239 def validate_domain_part(self, domain_part):
231240 if self.domain_regex.match(domain_part):
272281 try:
273282 ipaddress.IPv4Address(value)
274283 except ValueError:
275 raise ValidationError(_('Enter a valid IPv4 address.'), code='invalid')
284 raise ValidationError(_('Enter a valid IPv4 address.'), code='invalid', params={'value': value})
276285
277286
278287def validate_ipv6_address(value):
279288 if not is_valid_ipv6_address(value):
280 raise ValidationError(_('Enter a valid IPv6 address.'), code='invalid')
289 raise ValidationError(_('Enter a valid IPv6 address.'), code='invalid', params={'value': value})
281290
282291
283292def validate_ipv46_address(value):
287296 try:
288297 validate_ipv6_address(value)
289298 except ValidationError:
290 raise ValidationError(_('Enter a valid IPv4 or IPv6 address.'), code='invalid')
299 raise ValidationError(_('Enter a valid IPv4 or IPv6 address.'), code='invalid', params={'value': value})
291300
292301
293302ip_address_validator_map = {
438447 def __call__(self, value):
439448 digit_tuple, exponent = value.as_tuple()[1:]
440449 if exponent in {'F', 'n', 'N'}:
441 raise ValidationError(self.messages['invalid'])
450 raise ValidationError(self.messages['invalid'], params={'value': value})
442451 if exponent >= 0:
443452 # A positive exponent adds that many trailing zeros.
444453 digits = len(digit_tuple) + exponent
460469 raise ValidationError(
461470 self.messages['max_digits'],
462471 code='max_digits',
463 params={'max': self.max_digits},
472 params={'max': self.max_digits, 'value': value},
464473 )
465474 if self.decimal_places is not None and decimals > self.decimal_places:
466475 raise ValidationError(
467476 self.messages['max_decimal_places'],
468477 code='max_decimal_places',
469 params={'max': self.decimal_places},
478 params={'max': self.decimal_places, 'value': value},
470479 )
471480 if (self.max_digits is not None and self.decimal_places is not None and
472481 whole_digits > (self.max_digits - self.decimal_places)):
473482 raise ValidationError(
474483 self.messages['max_whole_digits'],
475484 code='max_whole_digits',
476 params={'max': (self.max_digits - self.decimal_places)},
485 params={'max': (self.max_digits - self.decimal_places), 'value': value},
477486 )
478487
479488 def __eq__(self, other):
509518 code=self.code,
510519 params={
511520 'extension': extension,
512 'allowed_extensions': ', '.join(self.allowed_extensions)
521 'allowed_extensions': ', '.join(self.allowed_extensions),
522 'value': value
513523 }
514524 )
515525
550560
551561 def __call__(self, value):
552562 if '\x00' in str(value):
553 raise ValidationError(self.message, code=self.code)
563 raise ValidationError(self.message, code=self.code, params={'value': value})
554564
555565 def __eq__(self, other):
556566 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.