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
66dc8c59
Commit
66dc8c59
authored
Aug 04, 2007
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tests that tried to sneak strings through httplib.
The httplib interface returns bytes for now.
parent
04319c78
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
13 deletions
+13
-13
Lib/test/test_urllib.py
Lib/test/test_urllib.py
+13
-13
No files found.
Lib/test/test_urllib.py
View file @
66dc8c59
...
...
@@ -2,12 +2,12 @@
import
urllib
import
httplib
import
io
import
unittest
from
test
import
test_support
import
os
import
mimetools
import
tempfile
import
StringIO
import
ftplib
import
threading
import
socket
...
...
@@ -99,15 +99,15 @@ class urlopen_HttpTests(unittest.TestCase):
"""Test urlopen() opening a fake http connection."""
def
fakehttp
(
self
,
fakedata
):
class
FakeSocket
(
StringIO
.
String
IO
):
class
FakeSocket
(
io
.
Bytes
IO
):
def
sendall
(
self
,
str
):
pass
def
makefile
(
self
,
mode
,
name
):
return
self
def
read
(
self
,
amt
=
None
):
if
self
.
closed
:
return
''
return
StringIO
.
String
IO
.
read
(
self
,
amt
)
if
self
.
closed
:
return
b""
return
io
.
Bytes
IO
.
read
(
self
,
amt
)
def
readline
(
self
,
length
=
None
):
if
self
.
closed
:
return
''
return
StringIO
.
String
IO
.
readline
(
self
,
length
)
if
self
.
closed
:
return
b""
return
io
.
Bytes
IO
.
readline
(
self
,
length
)
class
FakeHTTPConnection
(
httplib
.
HTTPConnection
):
def
connect
(
self
):
self
.
sock
=
FakeSocket
(
fakedata
)
...
...
@@ -118,20 +118,20 @@ class urlopen_HttpTests(unittest.TestCase):
httplib
.
HTTP
.
_connection_class
=
httplib
.
HTTPConnection
def
test_read
(
self
):
self
.
fakehttp
(
'Hello!'
)
self
.
fakehttp
(
b"Hello!"
)
try
:
fp
=
urllib
.
urlopen
(
"http://python.org/"
)
self
.
assertEqual
(
fp
.
readline
(),
'Hello!'
)
self
.
assertEqual
(
fp
.
readline
(),
''
)
self
.
assertEqual
(
fp
.
readline
(),
b"Hello!"
)
self
.
assertEqual
(
fp
.
readline
(),
b""
)
finally
:
self
.
unfakehttp
()
def
test_empty_socket
(
self
):
"""
urlopen() raises IOError if the underlying socket does not send any
data. (#1680230) """
self
.
fakehttp
(
''
)
#
urlopen() raises IOError if the underlying socket does not send any
# data. (#1680230)
self
.
fakehttp
(
b""
)
try
:
self
.
assertRaises
(
IOError
,
urllib
.
urlopen
,
'http://something'
)
self
.
assertRaises
(
IOError
,
urllib
.
urlopen
,
"http://something"
)
finally
:
self
.
unfakehttp
()
...
...
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