def _encode_path_part(text, maximal=True):
    "Percent-encode a single segment of a URL path."
    if maximal:
        bytestr = normalize('NFC', text).encode('utf8')
        return u''.join([_PATH_PART_QUOTE_MAP[b] for b in bytestr])
    return u''.join([_PATH_PART_QUOTE_MAP[t] if t in _PATH_DELIMS else t
                     for t in text])
Percent-encode a single segment of a URL path.
stackoverflow/venv/lib/python3.6/site-packages/hyperlink/_url.py