Encode string according to RFC 2231. If neither charset nor language is given, then s is returned as-is. If charset is given but not language, the string is encoded using the empty string for language.
(s, charset=None, language=None)
| 375 | |
| 376 | |
| 377 | def encode_rfc2231(s, charset=None, language=None): |
| 378 | """Encode string according to RFC 2231. |
| 379 | |
| 380 | If neither charset nor language is given, then s is returned as-is. If |
| 381 | charset is given but not language, the string is encoded using the empty |
| 382 | string for language. |
| 383 | """ |
| 384 | s = urllib.parse.quote(s, safe='', encoding=charset or 'ascii') |
| 385 | if charset is None and language is None: |
| 386 | return s |
| 387 | if language is None: |
| 388 | language = '' |
| 389 | return "%s'%s'%s" % (charset, language, s) |
| 390 | |
| 391 | |
| 392 | rfc2231_continuation = re.compile(r'^(?P<name>\w+)\*((?P<num>[0-9]+)\*?)?$', |
nothing calls this directly
no test coverage detected
searching dependent graphs…