[Python-checkins] cpython (merge 3.2 -> 3.3): #17307 - merge from 3.2

senthil.kumaran python-checkins at python.org
Wed Mar 13 21:40:34 CET 2013


http://hg.python.org/cpython/rev/9941a9bbfeb6
changeset:   82652:9941a9bbfeb6
branch:      3.3
parent:      82646:e470370b4701
parent:      82651:d4ab6556ff97
user:        Senthil Kumaran <senthil at uthcode.com>
date:        Wed Mar 13 13:42:47 2013 -0700
summary:
  #17307 - merge from 3.2

files:
  Doc/library/http.client.rst    |  18 ++++++++++++++++++
  Doc/library/urllib.request.rst |   9 +++++++++
  2 files changed, 27 insertions(+), 0 deletions(-)


diff --git a/Doc/library/http.client.rst b/Doc/library/http.client.rst
--- a/Doc/library/http.client.rst
+++ b/Doc/library/http.client.rst
@@ -633,6 +633,24 @@
    b'Redirecting to <a href="http://bugs.python.org/issue12524">http://bugs.python.org/issue12524</a>'
    >>> conn.close()
 
+Client side ``HTTP PUT`` requests are very similar to ``POST`` requests. The
+difference lies only the server side where HTTP server will allow resources to
+be created via ``PUT`` request. It should be noted that custom HTTP methods
++are also handled in :class:`urllib.request.Request` by sending the appropriate
++method attribute.Here is an example session that shows how to do ``PUT``
+request using http.client::
+
+    >>> # This creates an HTTP message
+    >>> # with the content of BODY as the enclosed representation
+    >>> # for the resource http://localhost:8080/foobar
+    ...
+    >>> import http.client
+    >>> BODY = "***filecontents***"
+    >>> conn = http.client.HTTPConnection("localhost", 8080)
+    >>> conn.request("PUT", "/file", BODY)
+    >>> response = conn.getresponse()
+    >>> print(resp.status, response.reason)
+    200, OK
 
 .. _httpmessage-objects:
 
diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst
--- a/Doc/library/urllib.request.rst
+++ b/Doc/library/urllib.request.rst
@@ -1109,6 +1109,15 @@
    data = sys.stdin.read()
    print('Content-type: text-plain\n\nGot Data: "%s"' % data)
 
+Here is an example of doing a ``PUT`` request using :class:`Request`::
+
+    import urllib.request
+    DATA=b'some data'
+    req = urllib.request.Request(url='http://localhost:8080', data=DATA,method='PUT')
+    f = urllib.request.urlopen(req)
+    print(f.status)
+    print(f.reason)
+
 Use of Basic HTTP Authentication::
 
    import urllib.request

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list