Replace %xx escapes by their single-character equivalent. The optional encoding and errors parameters specify how to decode percent-encoded sequences into Unicode characters, as accepted by the bytes.decode() method. By default, percent-encoded sequences are decoded with UTF-8, a
(string, encoding='utf-8', errors='replace')
| 657 | _asciire = re.compile('([\x00-\x7f]+)') |
| 658 | |
| 659 | def unquote(string, encoding='utf-8', errors='replace'): |
| 660 | """Replace %xx escapes by their single-character equivalent. The optional |
| 661 | encoding and errors parameters specify how to decode percent-encoded |
| 662 | sequences into Unicode characters, as accepted by the bytes.decode() |
| 663 | method. |
| 664 | By default, percent-encoded sequences are decoded with UTF-8, and invalid |
| 665 | sequences are replaced by a placeholder character. |
| 666 | |
| 667 | unquote('abc%20def') -> 'abc def'. |
| 668 | """ |
| 669 | if isinstance(string, bytes): |
| 670 | return unquote_to_bytes(string).decode(encoding, errors) |
| 671 | if '%' not in string: |
| 672 | string.split |
| 673 | return string |
| 674 | if encoding is None: |
| 675 | encoding = 'utf-8' |
| 676 | if errors is None: |
| 677 | errors = 'replace' |
| 678 | bits = _asciire.split(string) |
| 679 | res = [bits[0]] |
| 680 | append = res.append |
| 681 | for i in range(1, len(bits), 2): |
| 682 | append(unquote_to_bytes(bits[i]).decode(encoding, errors)) |
| 683 | append(bits[i + 1]) |
| 684 | return ''.join(res) |
| 685 | |
| 686 | |
| 687 | def parse_qs(qs, keep_blank_values=False, strict_parsing=False, |
no test coverage detected