]> granicus.if.org Git - python/commitdiff
Fix issue14826 - make urllib.request.Request quoted url consistent with URLOpener...
authorSenthil Kumaran <senthil@uthcode.com>
Sun, 8 Jul 2012 00:15:52 +0000 (17:15 -0700)
committerSenthil Kumaran <senthil@uthcode.com>
Sun, 8 Jul 2012 00:15:52 +0000 (17:15 -0700)
Patch contributed by Stephen Thorne.

1  2 
Lib/test/test_urllib.py
Lib/urllib/request.py
Misc/NEWS

index 22ada56d0c8d15087535c78900c634f40e68eb31,69d543855e5cf8f004704f16be58c5bb323f49e8..af3f0ad3aef3aa91214036c4cfd070559482ab1a
@@@ -1249,29 -1245,12 +1249,34 @@@ class URLopener_Tests(unittest.TestCase
  #         self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
  #         ftp.close()
  
 +class RequestTests(unittest.TestCase):
 +    """Unit tests for urllib.request.Request."""
 +
 +    def test_default_values(self):
 +        Request = urllib.request.Request
 +        request = Request("http://www.python.org")
 +        self.assertEqual(request.get_method(), 'GET')
 +        request = Request("http://www.python.org", {})
 +        self.assertEqual(request.get_method(), 'POST')
 +
 +    def test_with_method_arg(self):
 +        Request = urllib.request.Request
 +        request = Request("http://www.python.org", method='HEAD')
 +        self.assertEqual(request.method, 'HEAD')
 +        self.assertEqual(request.get_method(), 'HEAD')
 +        request = Request("http://www.python.org", {}, method='HEAD')
 +        self.assertEqual(request.method, 'HEAD')
 +        self.assertEqual(request.get_method(), 'HEAD')
 +        request = Request("http://www.python.org", method='GET')
 +        self.assertEqual(request.get_method(), 'GET')
 +        request.method = 'HEAD'
 +        self.assertEqual(request.get_method(), 'HEAD')
  
+     def test_quote_url(self):
+         Request = urllib.request.Request
+         request = Request("http://www.python.org/foo bar")
+         self.assertEqual(request.full_url, "http://www.python.org/foo%20bar")
  
  def test_main():
      support.run_unittest(
index 67b4c795b36edc3af28d271c9c566f41216c09f9,796b700f99b663c7be688a7407b045583812cdc0..3896aa0ecf9caf03cfb7ca5a22d9d6d894ac4f5d
@@@ -260,10 -178,10 +260,11 @@@ def request_host(request)
  class Request:
  
      def __init__(self, url, data=None, headers={},
 -                 origin_req_host=None, unverifiable=False):
 +                 origin_req_host=None, unverifiable=False,
 +                 method=None):
          # unwrap('<URL:type://host/path>') --> 'type://host/path'
-         self.full_url = unwrap(url)
+         self.full_url = unwrap(to_bytes(url))
+         self.full_url = quote(self.full_url, safe="%/:=&?~#+!$,;'@()*[]|")
          self.full_url, self.fragment = splittag(self.full_url)
          self.data = data
          self.headers = {}
diff --cc Misc/NEWS
index 0e43c5f05525fe02aadadbbb9a1c90d33b1dea7a,18d03efa494c2932a373a937ba8aff5ebd06a1d5..c0d1d0115ba70ad6b8ed2012e64182e3356192f0
+++ b/Misc/NEWS
@@@ -16,106 -16,6 +16,111 @@@ Core and Builtin
  - Issue #15033: Fix the exit status bug when modules invoked using -m swith,
    return the proper failure return value (1). Patch contributed by Jeff Knupp.
  
 +- Issue #15229: An OSError subclass whose __init__ doesn't call back
 +  OSError.__init__ could produce incomplete instances, leading to crashes
 +  when calling str() on them.
 +
 +Library
 +-------
 +
++- Issue #14826: Quote urls in urllib.request.Request identically to how they
++  are quoted by urllib.request.URLopener. Allows urls to spaces in them to work
++  transparently with urllib.request.urlopen(...). Patch contributed by Stephen
++  Thorne.
++
 +- Issue #5931: wsgiref environ variable SERVER_SOFTWARE will specify an
 +  implementation specific term like Cpython, Jython instead of generic "Python"
 +
 +- Issue #13248: Remove obsolete argument "max_buffer_size" of BufferedWriter
 +  and BufferedRWPair, from the io module.
 +
 +- Issue #13248: Remove obsolete argument "version" of argparse.ArgumentParser.
 +
 +- Issue #14814: implement more consistent ordering and sorting behaviour
 +  for ipaddress objects
 +
 +- Issue #14814: ipaddress network objects correctly return NotImplemented
 +  when compared to arbitrary objects instead of raising TypeError
 +
 +- Issue #14990: Correctly fail with SyntaxError on invalid encoding
 +  declaration.
 +
 +- Issue #14814: ipaddress now provides more informative error messages when
 +  constructing instances directly (changes permitted during beta due to
 +  provisional API status)
 +
 +- Issue #15247: FileIO now raises an error when given a file descriptor
 +  pointing to a directory.
 +
 +- Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open.
 +
 +- Issue #15166: Implement imp.get_tag() using sys.implementation.cache_tag.
 +
 +- Issue #15210: Catch KeyError when imprortlib.__init__ can't find
 +  _frozen_importlib in sys.modules, not ImportError.
 +
 +- Issue #15030: importlib.abc.PyPycLoader now supports the new source size
 +  header field in .pyc files.
 +
 +- Issue #5346: Preserve permissions of mbox, MMDF and Babyl mailbox
 +  files on flush().
 +
 +- Issue #10571: Fix the "--sign" option of distutils' upload command.
 +  Patch by Jakub Wilk.
 +
 +- Issue #9559: If messages were only added, a new file is no longer
 +  created and renamed over the old file when flush() is called on an
 +  mbox, MMDF or Babyl mailbox.
 +
 +- Issue 10924: Fixed mksalt() to use a RNG that is suitable for cryptographic
 +  purpose.
 +
 +Extension Modules
 +-----------------
 +
 +- Issue #15194: Update libffi to the 3.0.11 release.
 +
 +Tools/Demos
 +-----------
 +
 +- Issue #12605: The gdb hooks for debugging CPython (within Tools/gdb) have
 +  been enhanced to show information on more C frames relevant to CPython within
 +  the "py-bt" and "py-bt-full" commands:
 +    * C frames that are waiting on the GIL
 +    * C frames that are garbage-collecting
 +    * C frames that are due to the invocation of a PyCFunction
 +
 +Tests
 +-----
 +
 +- Issue #15277: Fix a resource leak in support.py when IPv6 is disabled.
 +  Patch by Brian Brazil.
 +
 +Build
 +-----
 +
 +- Issue #14330: For cross builds, don't use host python, use host search paths
 +  for host compiler.
 +
 +- Issue #15235: Allow Berkley DB versions up to 5.3 to build the dbm module.
 +
 +- Issue #15268: Search curses.h in /usr/include/ncursesw.
 +
 +
 +What's New in Python 3.3.0 Beta 1?
 +==================================
 +
 +*Release date: 27-Jun-2012*
 +
 +Core and Builtins
 +-----------------
 +
 +- Fix a (most likely) very rare memory leak when calling main() and not being
 +  able to decode a command-line argument.
 +
 +- Issue #14815: Use Py_ssize_t instead of long for the object hash, to
 +  preserve all 64 bits of hash on Win64.
 +
  - Issue #12268: File readline, readlines and read() or readall() methods
    no longer lose data when an underlying read system call is interrupted.
    IOError is no longer raised due to a read system call returning EINTR