]> granicus.if.org Git - python/commitdiff
Merged revisions 83818 via svnmerge from
authorSenthil Kumaran <orsenthil@gmail.com>
Sun, 8 Aug 2010 11:30:58 +0000 (11:30 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Sun, 8 Aug 2010 11:30:58 +0000 (11:30 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r83818 | senthil.kumaran | 2010-08-08 16:57:53 +0530 (Sun, 08 Aug 2010) | 4 lines

  Fix Issue8280 - urllib2's Request method will remove fragements in the url.
  This is how it should work,wget and curl work like this way too. Old behavior was wrong.
........

Lib/test/test_urllib2.py
Lib/test/test_urllib2net.py
Lib/urllib/request.py

index 9d1ed9b616ab1974598e819704a2a936d634439c..83bd467177bd2e5e1c0a14d78d68b93ea9b8dc17 100644 (file)
@@ -1250,6 +1250,16 @@ class RequestTests(unittest.TestCase):
         self.assertEqual("www.python.org", self.get.get_origin_req_host())
         self.assertEqual("www.perl.org", self.get.get_host())
 
+    def test_wrapped_url(self):
+        req = Request("<URL:http://www.python.org>")
+        self.assertEqual("www.python.org", req.get_host())
+
+    def test_urlwith_fragment(self):
+        req = Request("http://www.python.org/?qs=query#fragment=true")
+        self.assertEqual("/?qs=query", req.get_selector())
+        req = Request("http://www.python.org/#fun=true")
+        self.assertEqual("/", req.get_selector())
+
 
 def test_main(verbose=None):
     from test import test_urllib2
index 0f109dc22acf1440d23a972d760b5ff6a5d658b3..eab9306ab96c29292607463e1b1404daf7f9a23a 100644 (file)
@@ -152,6 +152,13 @@ class OtherNetworkTests(unittest.TestCase):
 
 ##             self._test_urls(urls, self._extra_handlers()+[bauth, dauth])
 
+    def test_urlwithfrag(self):
+        urlwith_frag = "http://docs.python.org/glossary.html#glossary"
+        req = urllib.request.Request(urlwith_frag)
+        res = urllib.request.urlopen(req)
+        self.assertEqual(res.geturl(),
+                "http://docs.python.org/glossary.html")
+
     def _test_urls(self, urls, handlers, retry=True):
         import socket
         import time
index a26b763231baae90b12bdd28a9fe42ac6b2e09d4..3ea38f2bf02f46b86b8ce867ab7bb06cd12582b8 100644 (file)
@@ -99,7 +99,7 @@ from urllib.error import URLError, HTTPError, ContentTooShortError
 from urllib.parse import (
     urlparse, urlsplit, urljoin, unwrap, quote, unquote,
     splittype, splithost, splitport, splituser, splitpasswd,
-    splitattr, splitquery, splitvalue, to_bytes, urlunparse)
+    splitattr, splitquery, splitvalue, splittag, to_bytes, urlunparse)
 from urllib.response import addinfourl, addclosehook
 
 # check for SSL
@@ -163,6 +163,7 @@ class Request:
                  origin_req_host=None, unverifiable=False):
         # unwrap('<URL:type://host/path>') --> 'type://host/path'
         self.full_url = unwrap(url)
+        self.full_url, fragment = splittag(self.full_url)
         self.data = data
         self.headers = {}
         self._tunnel_host = None