Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4775def

Browse files
committed
merge
2 parents 13ec112 + 187fa8e commit 4775def

4 files changed

Lines changed: 18 additions & 10 deletions

File tree

Doc/howto/urllib2.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ library. ::
115115
'language' : 'Python' }
116116

117117
data = urllib.parse.urlencode(values)
118+
data = data.encode('utf-8') # data should be bytes
118119
req = urllib.request.Request(url, data)
119120
response = urllib.request.urlopen(req)
120121
the_page = response.read()
@@ -179,7 +180,8 @@ Explorer [#]_. ::
179180
'language' : 'Python' }
180181
headers = { 'User-Agent' : user_agent }
181182

182-
data = urllib.parse.urlencode(values)
183+
data = urllib.parse.urlencode(values)
184+
data = data.encode('utf-8')
183185
req = urllib.request.Request(url, data, headers)
184186
response = urllib.request.urlopen(req)
185187
the_page = response.read()

Doc/library/urllib.request.rst

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,13 @@ The following classes are provided:
138138

139139
*url* should be a string containing a valid URL.
140140

141-
*data* may be a string specifying additional data to send to the
142-
server, or ``None`` if no such data is needed. Currently HTTP
143-
requests are the only ones that use *data*, in order to choose between
144-
``'GET'`` and ``'POST'`` when *method* is not specified.
145-
*data* should be a buffer in the standard
146-
:mimetype:`application/x-www-form-urlencoded` format. The
147-
:func:`urllib.parse.urlencode` function takes a mapping or sequence
148-
of 2-tuples and returns a string in this format.
141+
*data* may be a bytes object specifying additional data to send to the
142+
server, or ``None`` if no such data is needed. Currently HTTP requests are
143+
the only ones that use *data*; the HTTP request will be a POST instead of a
144+
GET when the *data* parameter is provided. *data* should be a buffer in the
145+
standard :mimetype:`application/x-www-form-urlencoded` format. The
146+
:func:`urllib.parse.urlencode` function takes a mapping or sequence of
147+
2-tuples and returns a string in this format.
149148

150149
*headers* should be a dictionary, and will be treated as if
151150
:meth:`add_header` was called with each key and value as arguments.
@@ -1183,7 +1182,7 @@ some point in the future.
11831182

11841183
If the *url* uses the :file:`http:` scheme identifier, the optional *data*
11851184
argument may be given to specify a ``POST`` request (normally the request
1186-
type is ``GET``). The *data* argument must in standard
1185+
type is ``GET``). The *data* argument must be a bytes object in standard
11871186
:mimetype:`application/x-www-form-urlencoded` format; see the
11881187
:func:`urlencode` function below.
11891188

Modules/expat/expat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,8 @@ XMLPARSEAPI(int)
892892
XML_SetHashSalt(XML_Parser parser,
893893
unsigned long hash_salt);
894894

895+
#define XML_HAS_SET_HASH_SALT /* Python Only: Defined for pyexpat.c. */
896+
895897
/* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then
896898
XML_GetErrorCode returns information about the error.
897899
*/

Modules/pyexpat.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,8 +1156,13 @@ newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern)
11561156
else {
11571157
self->itself = XML_ParserCreate(encoding);
11581158
}
1159+
#if ((XML_MAJOR_VERSION >= 2) && (XML_MINOR_VERSION >= 1)) || defined(XML_HAS_SET_HASH_SALT)
1160+
/* This feature was added upstream in libexpat 2.1.0. Our expat copy
1161+
* has a backport of this feature where we also define XML_HAS_SET_HASH_SALT
1162+
* to indicate that we can still use it. */
11591163
XML_SetHashSalt(self->itself,
11601164
(unsigned long)_Py_HashSecret.prefix);
1165+
#endif
11611166
self->intern = intern;
11621167
Py_XINCREF(self->intern);
11631168
PyObject_GC_Track(self);

0 commit comments

Comments
 (0)