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
a898abde
Commit
a898abde
authored
Sep 06, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #19524: Port fakehttp() from Py3 c1fb19907cc4 for use in test_urllib2
parent
d0dc72b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
22 deletions
+28
-22
Lib/test/test_urllib.py
Lib/test/test_urllib.py
+27
-22
Lib/test/test_urllib2.py
Lib/test/test_urllib2.py
+1
-0
No files found.
Lib/test/test_urllib.py
View file @
a898abde
...
...
@@ -3,12 +3,12 @@
import
collections
import
urllib
import
httplib
import
io
import
unittest
import
os
import
sys
import
mimetools
import
tempfile
import
StringIO
from
test
import
test_support
from
base64
import
b64encode
...
...
@@ -22,37 +22,42 @@ def hexescape(char):
return
"%"
+
hex_repr
class
FakeHTTPMixin
(
object
):
def
fakehttp
(
self
,
fakedata
):
class
FakeSocket
(
StringIO
.
StringIO
):
def
fakehttp
(
fakedata
):
class
FakeSocket
(
io
.
BytesIO
):
def
sendall
(
self
,
data
):
FakeHTTPConnection
.
buf
=
data
def
sendall
(
self
,
data
):
FakeHTTPConnection
.
buf
=
data
def
makefile
(
self
,
*
args
,
**
kwds
):
return
self
def
makefile
(
self
,
*
args
,
**
kwds
):
return
self
def
read
(
self
,
amt
=
None
):
if
self
.
closed
:
return
b""
return
io
.
BytesIO
.
read
(
self
,
amt
)
def
read
(
self
,
amt
=
None
):
if
self
.
closed
:
return
""
return
StringIO
.
StringIO
.
read
(
self
,
amt
)
def
readline
(
self
,
length
=
None
):
if
self
.
closed
:
return
b
""
return
io
.
BytesIO
.
readline
(
self
,
length
)
def
readline
(
self
,
length
=
None
):
if
self
.
closed
:
return
""
return
StringIO
.
StringIO
.
readline
(
self
,
length
)
class
FakeHTTPConnection
(
httplib
.
HTTPConnection
):
class
FakeHTTPConnection
(
httplib
.
HTTPConnection
):
# buffer to store data for verification in urlopen tests.
buf
=
""
fakesock
=
FakeSocket
(
fakedata
)
# buffer to store data for verification in urlopen tests.
buf
=
""
def
connect
(
self
):
self
.
sock
=
self
.
fakesock
def
connect
(
self
):
self
.
sock
=
FakeSocket
(
fakedata
)
return
FakeHTTPConnection
class
FakeHTTPMixin
(
object
):
def
fakehttp
(
self
,
fakedata
):
assert
httplib
.
HTTP
.
_connection_class
==
httplib
.
HTTPConnection
httplib
.
HTTP
.
_connection_class
=
FakeHTTPConnection
httplib
.
HTTP
.
_connection_class
=
fakehttp
(
fakedata
)
def
unfakehttp
(
self
):
httplib
.
HTTP
.
_connection_class
=
httplib
.
HTTPConnection
...
...
Lib/test/test_urllib2.py
View file @
a898abde
import
unittest
from
test
import
test_support
from
test
import
test_urllib
import
os
import
socket
...
...
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