]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix #17272 - Make Request.full_url and Request.get_full_url return same result under...
authorSenthil Kumaran <senthil@uthcode.com>
Fri, 24 May 2013 16:14:12 +0000 (09:14 -0700)
committerSenthil Kumaran <senthil@uthcode.com>
Fri, 24 May 2013 16:14:12 +0000 (09:14 -0700)
Document the change of Request.full_url to a property.

Doc/library/urllib.request.rst
Lib/test/test_urllib2.py
Lib/test/test_urllib2net.py
Lib/urllib/request.py

index 055cc820d0951c6b1fdf74c9ce37ed50ef7b05c8..91673f459cb4b13b3dbfbb46941df69c2efd78e5 100644 (file)
@@ -396,6 +396,12 @@ request.
 
    The original URL passed to the constructor.
 
+   .. versionchanged:: 3.4
+
+   Request.full_url is a property with setter, getter and a deleter. Getting
+   :attr:`~Request.full_url` returns the original request URL with the
+   fragment, if it was present.
+
 .. attribute:: Request.type
 
    The URI scheme.
@@ -482,6 +488,10 @@ request.
 
    Return the URL given in the constructor.
 
+   .. versionchanged:: 3.4
+
+   Returns :attr:`Request.full_url`
+
 
 .. method:: Request.set_proxy(host, type)
 
index b4f940ccf9696731cdb398f9da892dfffccd3221..b3659f442e415a11800e1035e3caeffc871b8b93 100644 (file)
@@ -11,6 +11,7 @@ import urllib.request
 # The proxy bypass method imported below has logic specific to the OSX
 # proxy config data structure but is testable on all platforms.
 from urllib.request import Request, OpenerDirector, _proxy_bypass_macosx_sysconf
+from urllib.parse import urlparse
 import urllib.error
 
 # XXX
@@ -919,7 +920,13 @@ class HandlerTests(unittest.TestCase):
         r = Request('http://example.com')
         for url in urls:
             r.full_url = url
+            parsed = urlparse(url)
+
             self.assertEqual(r.get_full_url(), url)
+            # full_url setter uses splittag to split into components.
+            # splittag sets the fragment as None while urlparse sets it to ''
+            self.assertEqual(r.fragment or '', parsed.fragment)
+            self.assertEqual(urlparse(r.get_full_url()).query, parsed.query)
 
     def test_full_url_deleter(self):
         r = Request('http://www.example.com')
@@ -1537,6 +1544,14 @@ class RequestTests(unittest.TestCase):
         req = Request(url)
         self.assertEqual(req.get_full_url(), url)
 
+    def test_url_fullurl_get_full_url(self):
+        urls = ['http://docs.python.org',
+                'http://docs.python.org/library/urllib2.html#OK',
+                'http://www.python.org/?qs=query#fragment=true' ]
+        for url in urls:
+            req = Request(url)
+            self.assertEqual(req.get_full_url(), req.full_url)
+
 def test_main(verbose=None):
     from test import test_urllib2
     support.run_doctest(test_urllib2, verbose)
index e276d2ebfca6aeb4b005dbee99a579a48e624477..b674be0478d7b7fb1cdb040fdab4c0776111da90 100644 (file)
@@ -164,6 +164,14 @@ class OtherNetworkTests(unittest.TestCase):
             self.assertEqual(res.geturl(),
                     "http://docs.python.org/2/glossary.html#glossary")
 
+    def test_redirect_url_withfrag(self):
+        redirect_url_with_frag = "http://bitly.com/urllibredirecttest"
+        with support.transient_internet(redirect_url_with_frag):
+            req = urllib.request.Request(redirect_url_with_frag)
+            res = urllib.request.urlopen(req)
+            self.assertEqual(res.geturl(),
+                    "http://docs.python.org/3.4/glossary.html#term-global-interpreter-lock")
+
     def test_custom_headers(self):
         url = "http://www.example.com"
         with support.transient_internet(url):
index 32581023a1eae724801a527267056347ca480486..fdb1ec87b051e3dc7c03f1bdd339573fc71ffa57 100644 (file)
@@ -275,6 +275,8 @@ class Request:
 
     @property
     def full_url(self):
+        if self.fragment:
+            return '{}#{}'.format(self._full_url, self.fragment)
         return self._full_url
 
     @full_url.setter
@@ -326,8 +328,6 @@ class Request:
             return "GET"
 
     def get_full_url(self):
-        if self.fragment:
-            return '{}#{}'.format(self.full_url, self.fragment)
         return self.full_url
 
     def set_proxy(self, host, type):