def encode_uri(uri): """Given a (presumed decoded) uri, return a well-encoded uri suitable for an html href.""" uri = urlsplit(uri) new_uri = encode_split_uri(uri) return urlunsplit(new_uri)
def decode_uri(uri): """Given a uri, return a decoded uri suitable for displaying to users.""" uri = urlsplit(uri) new_uri = decode_split_uri(uri) return urlunsplit(new_uri)
def recode_uri(uri): """Take an unknown uri and return a well-encoded uri suitable for an html href. This is essentially equivalent to encode(decode(uri)), but a little more efficient. """ uri = urlsplit(uri) new_uri = recode_split_uri(uri) return urlunsplit(new_uri)
def _emailsplit(email): """We don't support the full RFC6068 here, just a single email. To simplify processing, we treat the email as a username@hostname, rather than uri-path as specified. This is rather hackity. To do it the Right Way would probably necessitate a whole new namespace. """ email = urlsplit(email) if email.path: username, sep, hostname = email.path.rpartition('@') if not sep: username = None return email.replace(username=username, hostname=hostname, path='') else: return email