Closed hannesm closed 6 years ago
Thanks for using the library!
The "username" definition that you reference (RFC 8264, section 6.3) is not the same as the "Username Profile". Section 6.3 talks about what you might do if your application uses a non-Precis construct containing Precis elements. It would perhaps be clearer if the RFC example used "app_username" instead.
app_username = app_userpart *(1*SP app_userpart)
app_userpart = 1*(idpoint)
In this example, "app_username" is an application-layer construct: an identifier with spaces. The IdentifierClass does not allow spaces, so the RFC suggests you deal with this in your application code:
def enforce_app_username(app_username):
profile = precis_i18n.get_profile('UsernameCasePreserved')
userparts = [profile.enforce(userpart) for userpart in app_username.split(' ')]
return ' '.join(userparts)
Let me know if this doesn't make sense.
thanks for the quick reply, that makes sense!
first of all thanks for making this publicly available under a permissive license. While reading the specification (RFC8264, 8265), I came across the following definition for a username:
this means that a username could be
foo bar
. But when I try usingprecis_i18n
in a python shell:username.enforce('foo bar')
, I get:UnicodeEncodeError: 'UsernameCaseMapped' codec can't encode character '\x20' in position 3: DISALLOWED/spaces
(same in theUsernameCasePreserved
profile).thus: is username actually a userpart in this library?