to_bytes(u"URL") --> 'URL'.
(url)
| 1207 | |
| 1208 | |
| 1209 | def _to_bytes(url): |
| 1210 | """to_bytes(u"URL") --> 'URL'.""" |
| 1211 | # Most URL schemes require ASCII. If that changes, the conversion |
| 1212 | # can be relaxed. |
| 1213 | # XXX get rid of to_bytes() |
| 1214 | if isinstance(url, str): |
| 1215 | try: |
| 1216 | url = url.encode("ASCII").decode() |
| 1217 | except UnicodeError: |
| 1218 | raise UnicodeError("URL " + repr(url) + |
| 1219 | " contains non-ASCII characters") |
| 1220 | return url |
| 1221 | |
| 1222 | |
| 1223 | def unwrap(url): |