Boom

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})
104104 # Check if the scheme is valid.
105105 scheme = value.split('://')[0].lower()
106106 if scheme not in self.schemes:
107 raise ValidationError(self.message, code=self.code)
107 raise ValidationError(self.message, code=self.code, params={'value': value})
108108
109109 # Then check full URL
110110 try:
115115 try:
116116 scheme, netloc, path, query, fragment = urlsplit(value)
117117 except ValueError: # for example, "Invalid IPv6 URL"
118 raise ValidationError(self.message, code=self.code)
118 raise ValidationError(self.message, code=self.code, params={'value': value})
119119 try:
120120 netloc = punycode(netloc) # IDN -> ACE
121121 except UnicodeError: # invalid domain part
132132 try:
133133 validate_ipv6_address(potential_ip)
134134 except ValidationError:
135 raise ValidationError(self.message, code=self.code)
135 raise ValidationError(self.message, code=self.code, params={'value': value})
136136
137137 # The maximum length of a full host name is 253 characters per RFC 1034
138138 # section 3.1. It's defined to be 255 bytes or less, but this includes
139139 # one byte for the length of the name and one byte for the trailing dot
140140 # that's used to indicate absolute names in DNS.
141141 if len(urlsplit(value).netloc) > 253:
142 raise ValidationError(self.message, code=self.code)
142 raise ValidationError(self.message, code=self.code, params={'value': value})
143143
144144
145145integer_validator = RegexValidator(
208208
209209 def __call__(self, value):
210210 if not value or '@' not in value:
211 raise ValidationError(self.message, code=self.code)
211 raise ValidationError(self.message, code=self.code, params={'value': value})
212212
213213 user_part, domain_part = value.rsplit('@', 1)
214214
215215 if not self.user_regex.match(user_part):
216 raise ValidationError(self.message, code=self.code)
216 raise ValidationError(self.message, code=self.code, params={'value': value})
217217
218218 if (domain_part not in self.domain_allowlist and
219219 not self.validate_domain_part(domain_part)):
225225 else:
226226 if self.validate_domain_part(domain_part):
227227 return
228 raise ValidationError(self.message, code=self.code)
228 raise ValidationError(self.message, code=self.code, params={'value': value})
229229
230230 def validate_domain_part(self, domain_part):
231231 if self.domain_regex.match(domain_part):
268268)
269269
270270
271def validate_ipv4_address(value):
271def validate_ipv4_address(value, message=None, code=None):
272272 try:
273273 ipaddress.IPv4Address(value)
274274 except ValueError:
275 raise ValidationError(_('Enter a valid IPv4 address.'), code='invalid')
275 if message is None:
276 message = _('Enter a valid IPv4 address.')
277 if code is None:
278 code = 'invalid'
279 raise ValidationError(message, code=code, params={'value': value})
276280
277281
278def validate_ipv6_address(value):
282def validate_ipv6_address(value, message=None, code=None):
279283 if not is_valid_ipv6_address(value):
280 raise ValidationError(_('Enter a valid IPv6 address.'), code='invalid')
284 if message is None:
285 message = _('Enter a valid IPv6 address.')
286 if code is None:
287 code = 'invalid'
288 raise ValidationError(message, code=code, params={'value': value})
281289
282290
283def validate_ipv46_address(value):
291def validate_ipv46_address(value, message=None, code=None):
284292 try:
285293 validate_ipv4_address(value)
286294 except ValidationError:
287295 try:
288296 validate_ipv6_address(value)
289297 except ValidationError:
290 raise ValidationError(_('Enter a valid IPv4 or IPv6 address.'), code='invalid')
298 if message is None:
299 message = _('Enter a valid IPv4 or IPv6 address.')
300 if code is None:
301 code = 'invalid'
302 raise ValidationError(message, code=code, params={'value': value})
291303
292304
293305ip_address_validator_map = {
550562
551563 def __call__(self, value):
552564 if '\x00' in str(value):
553 raise ValidationError(self.message, code=self.code)
565 raise ValidationError(self.message, code=self.code, params={'value': value})
554566
555567 def __eq__(self, other):
556568 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.