Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
192697e3
Commit
192697e3
authored
Feb 09, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Plain Diff
Issue #26045: Merge http.client error addition from 3.5
parents
d0c1f774
44391481
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
2 deletions
+20
-2
Lib/http/client.py
Lib/http/client.py
+16
-1
Lib/test/test_httplib.py
Lib/test/test_httplib.py
+1
-1
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/http/client.py
View file @
192697e3
...
...
@@ -146,6 +146,21 @@ _is_illegal_header_value = re.compile(rb'\n(?![ \t])|\r(?![ \t\n])').search
_METHODS_EXPECTING_BODY
=
{
'PATCH'
,
'POST'
,
'PUT'
}
def
_encode
(
data
,
name
=
'data'
):
"""Call data.encode("latin-1") but show a better error message."""
try
:
return
data
.
encode
(
"latin-1"
)
except
UnicodeEncodeError
as
err
:
raise
UnicodeEncodeError
(
err
.
encoding
,
err
.
object
,
err
.
start
,
err
.
end
,
"%s (%.20r) is not valid Latin-1. Use %s.encode('utf-8') "
"if you want to send it encoded in UTF-8."
%
(
name
.
title
(),
data
[
err
.
start
:
err
.
end
],
name
))
from
None
class
HTTPMessage
(
email
.
message
.
Message
):
# XXX The only usage of this method is in
# http.server.CGIHTTPRequestHandler. Maybe move the code there so
...
...
@@ -1173,7 +1188,7 @@ class HTTPConnection:
if
isinstance
(
body
,
str
):
# RFC 2616 Section 3.7.1 says that text default has a
# default charset of iso-8859-1.
body
=
body
.
encode
(
'iso-8859-1
'
)
body
=
_encode
(
body
,
'body
'
)
self
.
endheaders
(
body
)
def
getresponse
(
self
):
...
...
Lib/test/test_httplib.py
View file @
192697e3
...
...
@@ -1042,7 +1042,7 @@ class OfflineTest(TestCase):
# intentionally omitted for simplicity
blacklist
=
{
"HTTPMessage"
,
"parse_headers"
}
for
name
in
dir
(
client
):
if
name
in
blacklist
:
if
name
.
startswith
(
"_"
)
or
name
in
blacklist
:
continue
module_object
=
getattr
(
client
,
name
)
if
getattr
(
module_object
,
"__module__"
,
None
)
==
"http.client"
:
...
...
Misc/NEWS
View file @
192697e3
...
...
@@ -170,6 +170,9 @@ Core and Builtins
Library
-------
-
Issue
#
26045
:
Add
UTF
-
8
suggestion
to
error
message
when
posting
a
non
-
Latin
-
1
string
with
http
.
client
.
-
Issue
#
26039
:
Added
zipfile
.
ZipInfo
.
from_file
()
and
zipinfo
.
ZipInfo
.
is_dir
().
Patch
by
Thomas
Kluyver
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment