summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2012-03-14 18:17:20 -0700
committerRaymond Hettinger <python@rcn.com>2012-03-14 18:17:20 -0700
commit4775def25d5f7428d83c3ea15055f27178f3daf3 (patch)
tree0714100c04a1b6a2ec0260155a462311ec80cb91
parent13ec112b3a11e5a04fb83808006a712ef4b6657e (diff)
parent187fa8e4b7984343a4131da94ce4bd125b532a86 (diff)
downloadcpython-git-4775def25d5f7428d83c3ea15055f27178f3daf3.tar.gz
merge
-rw-r--r--Doc/howto/urllib2.rst4
-rw-r--r--Doc/library/urllib.request.rst17
-rw-r--r--Modules/expat/expat.h2
-rw-r--r--Modules/pyexpat.c5
4 files changed, 18 insertions, 10 deletions
diff --git a/Doc/howto/urllib2.rst b/Doc/howto/urllib2.rst
index 058cf967ec..3ac8312e9c 100644
--- a/Doc/howto/urllib2.rst
+++ b/Doc/howto/urllib2.rst
@@ -115,6 +115,7 @@ library. ::
'language' : 'Python' }
data = urllib.parse.urlencode(values)
+ data = data.encode('utf-8') # data should be bytes
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req)
the_page = response.read()
@@ -179,7 +180,8 @@ Explorer [#]_. ::
'language' : 'Python' }
headers = { 'User-Agent' : user_agent }
- data = urllib.parse.urlencode(values)
+ data = urllib.parse.urlencode(values)
+ data = data.encode('utf-8')
req = urllib.request.Request(url, data, headers)
response = urllib.request.urlopen(req)
the_page = response.read()
diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst
index ef5d2daf6f..0bcd0bca55 100644
--- a/Doc/library/urllib.request.rst
+++ b/Doc/library/urllib.request.rst
@@ -138,14 +138,13 @@ The following classes are provided:
*url* should be a string containing a valid URL.
- *data* may be a string specifying additional data to send to the
- server, or ``None`` if no such data is needed. Currently HTTP
- requests are the only ones that use *data*, in order to choose between
- ``'GET'`` and ``'POST'`` when *method* is not specified.
- *data* should be a buffer in the standard
- :mimetype:`application/x-www-form-urlencoded` format. The
- :func:`urllib.parse.urlencode` function takes a mapping or sequence
- of 2-tuples and returns a string in this format.
+ *data* may be a bytes object specifying additional data to send to the
+ server, or ``None`` if no such data is needed. Currently HTTP requests are
+ the only ones that use *data*; the HTTP request will be a POST instead of a
+ GET when the *data* parameter is provided. *data* should be a buffer in the
+ standard :mimetype:`application/x-www-form-urlencoded` format. The
+ :func:`urllib.parse.urlencode` function takes a mapping or sequence of
+ 2-tuples and returns a string in this format.
*headers* should be a dictionary, and will be treated as if
:meth:`add_header` was called with each key and value as arguments.
@@ -1183,7 +1182,7 @@ some point in the future.
If the *url* uses the :file:`http:` scheme identifier, the optional *data*
argument may be given to specify a ``POST`` request (normally the request
- type is ``GET``). The *data* argument must in standard
+ type is ``GET``). The *data* argument must be a bytes object in standard
:mimetype:`application/x-www-form-urlencoded` format; see the
:func:`urlencode` function below.
diff --git a/Modules/expat/expat.h b/Modules/expat/expat.h
index cffdb8f629..89646d2bce 100644
--- a/Modules/expat/expat.h
+++ b/Modules/expat/expat.h
@@ -892,6 +892,8 @@ XMLPARSEAPI(int)
XML_SetHashSalt(XML_Parser parser,
unsigned long hash_salt);
+#define XML_HAS_SET_HASH_SALT /* Python Only: Defined for pyexpat.c. */
+
/* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then
XML_GetErrorCode returns information about the error.
*/
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index a2da67a3fd..fb023298f5 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1156,8 +1156,13 @@ newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern)
else {
self->itself = XML_ParserCreate(encoding);
}
+#if ((XML_MAJOR_VERSION >= 2) && (XML_MINOR_VERSION >= 1)) || defined(XML_HAS_SET_HASH_SALT)
+ /* This feature was added upstream in libexpat 2.1.0. Our expat copy
+ * has a backport of this feature where we also define XML_HAS_SET_HASH_SALT
+ * to indicate that we can still use it. */
XML_SetHashSalt(self->itself,
(unsigned long)_Py_HashSecret.prefix);
+#endif
self->intern = intern;
Py_XINCREF(self->intern);
PyObject_GC_Track(self);