summaryrefslogtreecommitdiffstats
path: root/Doc/library/urllib.request.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/urllib.request.rst')
-rw-r--r--Doc/library/urllib.request.rst123
1 files changed, 54 insertions, 69 deletions
diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst
index 9f3e12e..ef902b1 100644
--- a/Doc/library/urllib.request.rst
+++ b/Doc/library/urllib.request.rst
@@ -220,10 +220,15 @@ The following classes are provided:
*method* should be a string that indicates the HTTP request method that
will be used (e.g. ``'HEAD'``). Its value is stored in the
:attr:`~Request.method` attribute and is used by :meth:`get_method()`.
+ Subclasses may indicate a default method by setting the
+ :attr:`~Request.method` attribute in the class itself.
.. versionchanged:: 3.3
:attr:`Request.method` argument is added to the Request class.
+ .. versionchanged:: 3.4
+ Default :attr:`Request.method` may be indicated at the class level.
+
.. class:: OpenerDirector()
@@ -356,6 +361,11 @@ The following classes are provided:
Open local files.
+.. class:: DataHandler()
+
+ Open data URLs.
+
+ .. versionadded:: 3.4
.. class:: FTPHandler()
@@ -391,6 +401,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.
@@ -413,6 +429,10 @@ request.
The entity body for the request, or None if not specified.
+ .. versionchanged:: 3.4
+ Changing value of :attr:`Request.data` now deletes "Content-Length"
+ header if it was previously set or calculated.
+
.. attribute:: Request.unverifiable
boolean, indicates whether the request is unverifiable as defined
@@ -461,65 +481,29 @@ request.
unredirected).
-.. method:: Request.get_full_url()
-
- Return the URL given in the constructor.
-
-
-.. method:: Request.set_proxy(host, type)
-
- Prepare the request by connecting to a proxy server. The *host* and *type* will
- replace those of the instance, and the instance's selector will be the original
- URL given in the constructor.
-
-
-.. method:: Request.add_data(data)
-
- Set the :class:`Request` data to *data*. This is ignored by all handlers except
- HTTP handlers --- and there it should be a byte string, and will change the
- request to be ``POST`` rather than ``GET``. Deprecated in 3.3, use
- :attr:`Request.data`.
-
- .. deprecated-removed:: 3.3 3.4
-
-
-.. method:: Request.has_data()
-
- Return whether the instance has a non-\ ``None`` data. Deprecated in 3.3,
- use :attr:`Request.data`.
-
- .. deprecated-removed:: 3.3 3.4
-
-
-.. method:: Request.get_data()
+.. method:: Request.remove_header(header)
- Return the instance's data. Deprecated in 3.3, use :attr:`Request.data`.
+ Remove named header from the request instance (both from regular and
+ unredirected headers).
- .. deprecated-removed:: 3.3 3.4
+ .. versionadded:: 3.4
-.. method:: Request.get_type()
-
- Return the type of the URL --- also known as the scheme. Deprecated in 3.3,
- use :attr:`Request.type`.
-
- .. deprecated-removed:: 3.3 3.4
-
+.. method:: Request.get_full_url()
-.. method:: Request.get_host()
+ Return the URL given in the constructor.
- Return the host to which a connection will be made. Deprecated in 3.3, use
- :attr:`Request.host`.
+ .. versionchanged:: 3.4
- .. deprecated-removed:: 3.3 3.4
+ Returns :attr:`Request.full_url`
-.. method:: Request.get_selector()
+.. method:: Request.set_proxy(host, type)
- Return the selector --- the part of the URL that is sent to the server.
- Deprecated in 3.3, use :attr:`Request.selector`.
+ Prepare the request by connecting to a proxy server. The *host* and *type* will
+ replace those of the instance, and the instance's selector will be the original
+ URL given in the constructor.
- .. deprecated-removed:: 3.3 3.4
.. method:: Request.get_header(header_name, default=None)
@@ -531,26 +515,10 @@ request.
Return a list of tuples (header_name, header_value) of the Request headers.
-
-.. method:: Request.set_proxy(host, type)
-
-.. method:: Request.get_origin_req_host()
-
- Return the request-host of the origin transaction, as defined by
- :rfc:`2965`. See the documentation for the :class:`Request` constructor.
- Deprecated in 3.3, use :attr:`Request.origin_req_host`.
-
- .. deprecated-removed:: 3.3 3.4
-
-
-.. method:: Request.is_unverifiable()
-
- Return whether the request is unverifiable, as defined by RFC 2965. See the
- documentation for the :class:`Request` constructor. Deprecated in 3.3, use
- :attr:`Request.unverifiable`.
-
- .. deprecated-removed:: 3.3 3.4
-
+.. versionchanged:: 3.4
+ Request methods add_data, has_data, get_data, get_type, get_host,
+ get_selector, get_origin_req_host and is_unverifiable deprecated since 3.3
+ have been removed.
.. _opener-director-objects:
@@ -982,6 +950,21 @@ FileHandler Objects
hostname is given, an :exc:`URLError` is raised.
+.. _data-handler-objects:
+
+DataHandler Objects
+-------------------
+
+.. method:: DataHandler.data_open(req)
+
+ Read a data URL. This kind of URL contains the content encoded in the URL
+ itself. The data URL syntax is specified in :rfc:`2397`. This implementation
+ ignores white spaces in base64 encoded data URLs so the URL may be wrapped
+ in whatever source file it comes from. But even though some browsers don't
+ mind about a missing padding at the end of a base64 encoded data URL, this
+ implementation will raise an :exc:`ValueError` in that case.
+
+
.. _ftp-handler-objects:
FTPHandler Objects
@@ -1397,7 +1380,9 @@ some point in the future.
pair: FTP; protocol
* Currently, only the following protocols are supported: HTTP (versions 0.9 and
- 1.0), FTP, and local files.
+ 1.0), FTP, local files, and data URLs.
+
+ .. versionchanged:: 3.4 Added support for data URLs.
* The caching feature of :func:`urlretrieve` has been disabled until someone
finds the time to hack proper processing of Expiration time headers.