If you want your application to accept unicode user names and passwords, you must be careful in how you validate and compare them. The PRECIS framework makes internationalized user names and passwords safer for use by applications. PRECIS profiles transform unicode strings into a canonical form, suitable for comparison.
This module implements the PRECIS Framework as described in:
PRECIS Framework: Preparation, Enforcement, and Comparison of Internationalized Strings in Application Protocols (RFC 7564)
Preparation, Enforcement, and Comparison of Internationalized Strings Representing Usernames and Passwords (RFC 7613)
Preparation, Enforcement, and Comparison of Internationalized Strings Representing Nicknames (RFC 7700)
Requires Python 3.3 or later.
Usage
Use the get_profile function to obtain a profile object, then use its enforce method. The enforce method returns a Unicode string.
>>> from precis_i18n import get_profile
>>> username = get_profile('UsernameCaseMapped')
>>> username.enforce('Kevin')
'kevin'
>>> username.enforce('\u212Aevin')
'kevin'
>>> username.enforce('\uFF2Bevin')
'kevin'
>>> username.enforce('\U0001F17Aevin')
Traceback (most recent call last):
...
UnicodeEncodeError: 'UsernameCaseMapped' codec can't encode character '\U0001f17a' in position 0: DISALLOWED/symbols
Alternatively, you can use the Python str.encode API. Import the precis_i18n.codec module to register the PRECIS codec names. Now you can use the str.encode method with any unicode string. The result will be a UTF-8 encoded byte string or a UnicodeEncodeError if the string is disallowed.
>>> import precis_i18n.codec
>>> 'Kevin'.encode('UsernameCasePreserved')
b'Kevin'
>>> '\u212Aevin'.encode('UsernameCasePreserved')
b'Kevin'
>>> '\uFF2Bevin'.encode('UsernameCasePreserved')
b'Kevin'
>>> '\u212Aevin'.encode('UsernameCaseMapped')
b'kevin'
>>> '\uFF2Bevin'.encode('OpaqueString')
b'\xef\xbc\xabevin'
>>> '\U0001F17Aevin'.encode('UsernameCasePreserved')
Traceback (most recent call last):
...
UnicodeEncodeError: 'UsernameCasePreserved' codec can't encode character '\U0001f17a' in position 0: DISALLOWED/symbols
Supported Profiles and Codecs
Each PRECIS profile has a corresponding codec name. The CaseMapped variant converts the string to lower case for implementing case-insensitive comparison.
UsernameCasePreserved
UsernameCaseMapped
OpaqueString
NicknameCasePreserved
NicknameCaseMapped
The CaseMapped profiles use Unicode Default Case Folding. There are additional codecs that use Unicode ToLower to support draft RFC changes.
UsernameCaseMapped:ToLower
NicknameCaseMapped:ToLower
The PRECIS base string classes are also available:
IdentifierClass
FreeFormClass
Metadata
Release files for precis-i18n 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| precis_i18n-0.5.0.tar.gz | 50.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| precis_i18n-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 72.3 kB
Release files / precis_i18n-0.5.0.tar.gz
| Download URL | precis_i18n-0.5.0.tar.gz |
|---|---|
| Size | 50.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
177dec8682c303c06a6029e00b1b918553a60874fb69410aa58050b447093be1
|
|
BLAKE2b-256 checksum How to use checksums |
e11d6dce519ee25cff596bb21f69a56b74f42cae91520970f771fca217e47cda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / precis_i18n-0.5.0-py3-none-any.whl
| Download URL | precis_i18n-0.5.0-py3-none-any.whl |
|---|---|
| Size | 21.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c2578fae3e0cefa5becf160800546cd26b02a5916acfe7cbedb9139e453fc805
|
|
BLAKE2b-256 checksum How to use checksums |
9d79c7f0274767a47edbc03915f39c5e22e7e41bd7d33e1f3d64f0d250a59f45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |