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 _emailunsplit(split_email): """Given a result from _emailsplit, return an email string.""" # I know. Gross. I don't see a better way. email_path = '@'.join(s for s in (split_email.username, split_email.hostname) if s is not None) split_email = split_email.replace(username=None, hostname=None, path=email_path) return urlunsplit(split_email)