Urlencodes a string. Whereas percent_encode_sequence handles taking a dict/sequence and producing a percent encoded string, this function deals only with taking a string (not a dict/sequence) and percent encoding it. If given the binary type, will simply URL encode it. If given the
(input_str, safe=SAFE_CHARS)
| 755 | |
| 756 | |
| 757 | def percent_encode(input_str, safe=SAFE_CHARS): |
| 758 | """Urlencodes a string. |
| 759 | |
| 760 | Whereas percent_encode_sequence handles taking a dict/sequence and |
| 761 | producing a percent encoded string, this function deals only with |
| 762 | taking a string (not a dict/sequence) and percent encoding it. |
| 763 | |
| 764 | If given the binary type, will simply URL encode it. If given the |
| 765 | text type, will produce the binary type by UTF-8 encoding the |
| 766 | text. If given something else, will convert it to the text type |
| 767 | first. |
| 768 | """ |
| 769 | # If its not a binary or text string, make it a text string. |
| 770 | if not isinstance(input_str, (bytes, str)): |
| 771 | input_str = str(input_str) |
| 772 | # If it's not bytes, make it bytes by UTF-8 encoding it. |
| 773 | if not isinstance(input_str, bytes): |
| 774 | input_str = input_str.encode('utf-8') |
| 775 | return quote(input_str, safe=safe) |
| 776 | |
| 777 | |
| 778 | def _epoch_seconds_to_datetime(value, tzinfo): |