authnzerver.validators module

This module contains validation functions taken from the James Bennett’s excellent django-registration package. I’ve modified it a bit so the validators don’t need Django to work. The original docstring and the BSD License for that package are reproduced immediately below.

Copyright (c) 2007-2018, James Bennett All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the author nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Error messages, data and custom validation code used in django-registration’s various user-registration form classes.

authnzerver.validators.get_public_suffix_list(return_set: bool = False, save_to_currproc: bool = False) → Union[list, set][source]

Gets the public suffix list and caches it if necessary.

authnzerver.validators.normalize_value(value: str, casefold: bool = True) → str[source]

This normalizes a given value and casefolds it.

Assumes that the value has already passed validation.

authnzerver.validators.public_suffix_list(return_set: bool = False) → Union[list, set][source]

Retrieves the Internet names public suffix list and loads it into a set.

authnzerver.validators.validate_confusables(value: str)[source]

This validates if the value is not a confusable homoglyph.

authnzerver.validators.validate_confusables_email(value: str) → bool[source]

Validator which disallows ‘dangerous’ email addresses likely to represent homograph attacks.

An email address is ‘dangerous’ if either the local-part or the domain, considered on their own, are mixed-script and contain one or more characters appearing in the Unicode Visually Confusable Characters file.

authnzerver.validators.validate_email_address(emailaddr: str) → bool[source]

This validates an email address using the HTML5 specification, which is good enough for most purposes.

The regex is taken from here:

https://blog.gerv.net/2011/05/html5_email_address_regexp/

And was transformed to Python using the excellent https://regex101.com.

authnzerver.validators.validate_reserved_name(value: str) → bool[source]

This validates if the value is not one of the reserved names.

authnzerver.validators.validate_unique_value(value: str, check_list: Sequence[T_co]) → bool[source]

This checks if the input value does not already exist in the check_list.

The check_list comes from the DB and should contain user names, etc. that have been already normalized and casefolded.