fortitude

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 (
126126 raise
127127 else:
128128 # 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)
129 try:
130 host_match = re.search(r'^\[(.+)\](?::\d{2,5})?$', urlsplit(value).netloc)
131 if host_match:
132 potential_ip = host_match[1]
133 try:
134 validate_ipv6_address(potential_ip)
135 except ValidationError:
136 raise ValidationError(self.message, code=self.code, params={'value': value})
137 except ValueError:
138 # urlsplit can raise ValueError for malformed URLs
139 raise ValidationError(self.message, code=self.code, params={'value': value})
136140
137141 # The maximum length of a full host name is 253 characters per RFC 1034
138142 # section 3.1. It's defined to be 255 bytes or less, but this includes
139143 # one byte for the length of the name and one byte for the trailing dot
140144 # that's used to indicate absolute names in DNS.
141 if len(urlsplit(value).netloc) > 253:
142 raise ValidationError(self.message, code=self.code)
145 try:
146 if len(urlsplit(value).netloc) > 253:
147 raise ValidationError(self.message, code=self.code, params={'value': value})
148 except ValueError:
149 # urlsplit can raise ValueError for malformed URLs
150 raise ValidationError(self.message, code=self.code, params={'value': value})
143151
144152
145153integer_validator = RegexValidator(
208216
209217 def __call__(self, value):
210218 if not value or '@' not in value:
211 raise ValidationError(self.message, code=self.code)
219 raise ValidationError(self.message, code=self.code, params={'value': value})
212220
213221 user_part, domain_part = value.rsplit('@', 1)
214222
215223 if not self.user_regex.match(user_part):
216 raise ValidationError(self.message, code=self.code)
224 raise ValidationError(self.message, code=self.code, params={'value': value})
217225
218226 if (domain_part not in self.domain_allowlist and
219227 not self.validate_domain_part(domain_part)):
225233 else:
226234 if self.validate_domain_part(domain_part):
227235 return
228 raise ValidationError(self.message, code=self.code)
236 raise ValidationError(self.message, code=self.code, params={'value': value})
229237
230238 def validate_domain_part(self, domain_part):
231239 if self.domain_regex.match(domain_part):
272280 try:
273281 ipaddress.IPv4Address(value)
274282 except ValueError:
275 raise ValidationError(_('Enter a valid IPv4 address.'), code='invalid')
283 raise ValidationError(_('Enter a valid IPv4 address.'), code='invalid', params={'value': value})
276284
277285
278286def validate_ipv6_address(value):
279287 if not is_valid_ipv6_address(value):
280 raise ValidationError(_('Enter a valid IPv6 address.'), code='invalid')
288 raise ValidationError(_('Enter a valid IPv6 address.'), code='invalid', params={'value': value})
281289
282290
283291def validate_ipv46_address(value):
287295 try:
288296 validate_ipv6_address(value)
289297 except ValidationError:
290 raise ValidationError(_('Enter a valid IPv4 or IPv6 address.'), code='invalid')
298 raise ValidationError(_('Enter a valid IPv4 or IPv6 address.'), code='invalid', params={'value': value})
291299
292300
293301ip_address_validator_map = {
509517 code=self.code,
510518 params={
511519 'extension': extension,
512 'allowed_extensions': ', '.join(self.allowed_extensions)
520 'allowed_extensions': ', '.join(self.allowed_extensions),
521 'value': value
513522 }
514523 )
515524
550559
551560 def __call__(self, value):
552561 if '\x00' in str(value):
553 raise ValidationError(self.message, code=self.code)
562 raise ValidationError(self.message, code=self.code, params={'value': value})
554563
555564 def __eq__(self, other):
556565 return (
Test NameStatus
test_value_placeholder_with_char_field (forms_tests.tests.test_validators.ValidatorCustomMessageTests)
Fail
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_integer_field (forms_tests.tests.test_validators.ValidatorCustomMessageTests)
Fail
test_value_placeholder_with_null_character (forms_tests.tests.test_validators.ValidatorCustomMessageTests)
Fail
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.