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
db3e2bd8
Commit
db3e2bd8
authored
Apr 09, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Plain Diff
Issue #21069: Merge test_fileno() from 3.5
parents
ae197c93
d979b2cf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
11 deletions
+41
-11
Lib/test/test_httplib.py
Lib/test/test_httplib.py
+41
-0
Lib/test/test_urllibnet.py
Lib/test/test_urllibnet.py
+0
-11
No files found.
Lib/test/test_httplib.py
View file @
db3e2bd8
...
...
@@ -915,6 +915,47 @@ class BasicTest(TestCase):
self
.
assertEqual
(
sock
.
file
.
read
(),
extradata
)
#we read to the end
resp
.
close
()
def
test_response_fileno
(
self
):
# Make sure fd returned by fileno is valid.
threading
=
support
.
import_module
(
"threading"
)
serv
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
,
socket
.
IPPROTO_TCP
)
self
.
addCleanup
(
serv
.
close
)
serv
.
bind
((
HOST
,
0
))
serv
.
listen
()
result
=
None
def
run_server
():
[
conn
,
address
]
=
serv
.
accept
()
with
conn
,
conn
.
makefile
(
"rb"
)
as
reader
:
# Read the request header until a blank line
while
True
:
line
=
reader
.
readline
()
if
not
line
.
rstrip
(
b"
\
r
\
n
"
):
break
conn
.
sendall
(
b"HTTP/1.1 200 Connection established
\
r
\
n
\
r
\
n
"
)
nonlocal
result
result
=
reader
.
read
()
thread
=
threading
.
Thread
(
target
=
run_server
)
thread
.
start
()
conn
=
client
.
HTTPConnection
(
*
serv
.
getsockname
())
conn
.
request
(
"CONNECT"
,
"dummy:1234"
)
response
=
conn
.
getresponse
()
try
:
self
.
assertEqual
(
response
.
status
,
client
.
OK
)
s
=
socket
.
socket
(
fileno
=
response
.
fileno
())
try
:
s
.
sendall
(
b"proxied data
\
n
"
)
finally
:
s
.
detach
()
finally
:
response
.
close
()
conn
.
close
()
thread
.
join
()
self
.
assertEqual
(
result
,
b"proxied data
\
n
"
)
class
ExtendedReadTest
(
TestCase
):
"""
Test peek(), read1(), readline()
...
...
Lib/test/test_urllibnet.py
View file @
db3e2bd8
...
...
@@ -99,17 +99,6 @@ class urlopenNetworkTests(unittest.TestCase):
open_url
.
close
()
self
.
assertEqual
(
code
,
404
)
# On Windows, socket handles are not file descriptors; this
# test can't pass on Windows.
@
unittest
.
skipIf
(
sys
.
platform
in
(
'win32'
,),
'not appropriate for Windows'
)
def
test_fileno
(
self
):
# Make sure fd returned by fileno is valid.
with
self
.
urlopen
(
"http://www.google.com/"
)
as
open_url
:
fd
=
open_url
.
fileno
()
with
os
.
fdopen
(
fd
,
'rb'
)
as
f
:
self
.
assertTrue
(
f
.
read
(),
"reading from file created using fd "
"returned by fileno failed"
)
def
test_bad_address
(
self
):
# Make sure proper exception is raised when connecting to a bogus
# address.
...
...
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