Skip to content

Commit

Permalink
Fix for issue1153027, making Py3k changes similar to fix in issue918368.
Browse files Browse the repository at this point in the history
This will address:
a) urllib/ in py3k,
b) urllib in py2x is addressed by issue918368.
c) urllib2 in py2x was already addressed in Revision 43132.
  • Loading branch information
orsenthil committed May 5, 2009
1 parent 501927d commit 690ce9b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/nturl2path.py
Expand Up @@ -56,7 +56,7 @@ def pathname2url(p):

drive = urllib.parse.quote(comp[0].upper())
components = comp[1].split('\\')
path = '///' + drive + '|'
path = '///' + drive + ':'
for comp in components:
if comp:
path = path + '/' + urllib.parse.quote(comp)
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_urllib.py
Expand Up @@ -837,6 +837,18 @@ def test_splitpasswd(self):
self.assertEqual(('user', 'a\vb'),urllib.parse.splitpasswd('user:a\vb'))
self.assertEqual(('user', 'a:b'),urllib.parse.splitpasswd('user:a:b'))


class URLopener_Tests(unittest.TestCase):
"""Testcase to test the open method of URLopener class."""

def test_quoted_open(self):
class DummyURLopener(urllib.request.URLopener):
def open_spam(self, url):
return url

self.assertEqual(DummyURLopener().open(
'spam://example/ /'),'//example/%20/')

# Just commented them out.
# Can't really tell why keep failing in windows and sparc.
# Everywhere else they work ok, but on those machines, someteimes
Expand Down Expand Up @@ -928,6 +940,7 @@ def test_main():
urlencode_Tests,
Pathname_Tests,
Utility_Tests,
URLopener_Tests,
#FTPWrapperTests,
)

Expand Down
1 change: 1 addition & 0 deletions Lib/urllib/request.py
Expand Up @@ -1398,6 +1398,7 @@ def addheader(self, *args):
def open(self, fullurl, data=None):
"""Use URLopener().open(file) instead of open(file, 'r')."""
fullurl = unwrap(to_bytes(fullurl))
fullurl = quote(fullurl, safe="%/:=&?~#+!$,;'@()*[]")
if self.tempcache and fullurl in self.tempcache:
filename, headers = self.tempcache[fullurl]
fp = open(filename, 'rb')
Expand Down

0 comments on commit 690ce9b

Please sign in to comment.