Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_bad_ip6address_raises(address, dummy_form, dummy_field):
adr = ip_address()
dummy_field.data = address
with pytest.raises(ValidationError):
adr(dummy_form, dummy_field)
def does_not_start_with_wildcard(form: Form, field: StringField) -> None:
"""Check that ``value`` does not start with a wildcard character."""
if not field.data:
return
if field.data.startswith('?') or field.data.startswith('*'):
raise validators.ValidationError(
'Search cannot start with a wildcard (? *).')
if any([part.startswith('?') or part.startswith('*')
for part in field.data.split()]):
raise validators.ValidationError('Search terms cannot start with a'
' wildcard (? *).')
def password_confirm(form, field):
if field.data != form.password_confirm.data:
raise ValidationError('password confirm failed')
def validate_avatar(self, field):
if field.data is not None:
error, status = check_image(field.data)
if error is not None:
raise ValidationError(error)
return status
def _check_if_payment_required(form, field):
if not field.data:
return
if not is_feature_enabled(form.event, 'payment'):
raise ValidationError(_('You have to enable the payment feature in order to set a registration fee.'))
def book_insert_num(form, field):
message = '单次添加数量必须为正整数,且小于1000'
if field.data:
try:
data = int(field.data)
except:
raise ValidationError(message)
else:
if data < 0 or data > 999:
raise ValidationError(message)
def validate_user_nicks(form, field):
"""Find not valid users."""
if field.data:
test = set(msg_split_addr(field.data))
comp = set([u for u, in db.session.query(User.nickname).
filter(User.nickname.in_(test)).all()])
diff = test.difference(comp)
if len(diff) > 0:
raise validators.ValidationError(
_('Not valid users: %{diff}s', diff=', '.join(diff)))
def validate_totp_value(self, field):
totp_value = field.data.encode("utf8")
if not self.user_service.check_totp_value(self.user_id, totp_value):
raise wtforms.validators.ValidationError(_("Invalid TOTP code."))
def validate_unique_email(form, field):
"""Validates that an email address hasn't been registered already"""
if User.query.filter_by(email=field.data).count() > 0:
raise validators.ValidationError('This email address has already been registered.')
def validate_youtube_channel(form, field):
yc = form.youtube_channel_extract()
if yc is None:
# fixme. add explanation here or hint to page
raise ValidationError("This field should contain valid youtube channel.")
streamer = Streamer.query.filter_by(youtube_channel=yc).first()
if streamer and streamer.checked and streamer != current_user:
raise ValidationError("There is another user with this channel. If it is your channel, please message about that to r/WatchPeoplecode moderators.")