to_bytes(u"URL") --> 'URL'.
(url)
| 1027 | |
| 1028 | |
| 1029 | def _to_bytes(url): |
| 1030 | """to_bytes(u"URL") --> 'URL'.""" |
| 1031 | # Most URL schemes require ASCII. If that changes, the conversion |
| 1032 | # can be relaxed. |
| 1033 | # XXX get rid of to_bytes() |
| 1034 | if isinstance(url, str): |
| 1035 | try: |
| 1036 | url = url.encode("ASCII").decode() |
| 1037 | except UnicodeError: |
| 1038 | raise UnicodeError("URL " + repr(url) + |
| 1039 | " contains non-ASCII characters") |
| 1040 | return url |
| 1041 | |
| 1042 | |
| 1043 | def unwrap(url): |