"Martin v. Löwis" wrote: > > Update of /cvsroot/python/python/dist/src/Lib > In directory slayer.i.sourceforge.net:/tmp/cvs-serv30506 > > Modified Files: > urllib.py > Log Message: > Convert Unicode strings to byte strings before passing them into specific > protocols. Closes bug #119822. > > ... > + > + def toBytes(url): > + """toBytes(u"URL") --> 'URL'.""" > + # Most URL schemes require ASCII. If that changes, the conversion > + # can be relaxed > + if type(url) is types.UnicodeType: > + try: > + url = url.encode("ASCII") You should make this: 'ascii' -- encoding names are lower case per convention (and the implementation has a short-cut to speed up conversion to 'ascii' -- not for 'ASCII'). > + except UnicodeError: > + raise UnicodeError("URL "+repr(url)+" contains non-ASCII characters") Would it be better to use a simple ValueError here ? (UnicodeError is a subclass of ValueError, but the error doesn't really have something to do with Unicode conversions...) > + return url > > def unwrap(url): -- Marc-Andre Lemburg ______________________________________________________________________ Company: http://www.egenix.com/ Consulting: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4