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
72144a9e
Commit
72144a9e
authored
Jan 10, 2014
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asyncio: Minimal pty support in UNIX read pipe, by Jonathan Slenders.
parent
35456b07
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
2 deletions
+47
-2
Lib/asyncio/unix_events.py
Lib/asyncio/unix_events.py
+5
-2
Lib/test/test_asyncio/test_events.py
Lib/test/test_asyncio/test_events.py
+42
-0
No files found.
Lib/asyncio/unix_events.py
View file @
72144a9e
...
@@ -190,7 +190,9 @@ class _UnixReadPipeTransport(transports.ReadTransport):
...
@@ -190,7 +190,9 @@ class _UnixReadPipeTransport(transports.ReadTransport):
self
.
_pipe
=
pipe
self
.
_pipe
=
pipe
self
.
_fileno
=
pipe
.
fileno
()
self
.
_fileno
=
pipe
.
fileno
()
mode
=
os
.
fstat
(
self
.
_fileno
).
st_mode
mode
=
os
.
fstat
(
self
.
_fileno
).
st_mode
if
not
(
stat
.
S_ISFIFO
(
mode
)
or
stat
.
S_ISSOCK
(
mode
)):
if
not
(
stat
.
S_ISFIFO
(
mode
)
or
stat
.
S_ISSOCK
(
mode
)
or
stat
.
S_ISCHR
(
mode
)):
raise
ValueError
(
"Pipe transport is for pipes/sockets only."
)
raise
ValueError
(
"Pipe transport is for pipes/sockets only."
)
_set_nonblocking
(
self
.
_fileno
)
_set_nonblocking
(
self
.
_fileno
)
self
.
_protocol
=
protocol
self
.
_protocol
=
protocol
...
@@ -228,6 +230,7 @@ class _UnixReadPipeTransport(transports.ReadTransport):
...
@@ -228,6 +230,7 @@ class _UnixReadPipeTransport(transports.ReadTransport):
def
_fatal_error
(
self
,
exc
):
def
_fatal_error
(
self
,
exc
):
# should be called by exception handler only
# should be called by exception handler only
if
not
(
isinstance
(
exc
,
OSError
)
and
exc
.
errno
==
errno
.
EIO
):
logger
.
exception
(
'Fatal error for %s'
,
self
)
logger
.
exception
(
'Fatal error for %s'
,
self
)
self
.
_close
(
exc
)
self
.
_close
(
exc
)
...
...
Lib/test/test_asyncio/test_events.py
View file @
72144a9e
...
@@ -132,6 +132,8 @@ class MyReadPipeProto(protocols.Protocol):
...
@@ -132,6 +132,8 @@ class MyReadPipeProto(protocols.Protocol):
self
.
state
.
append
(
'EOF'
)
self
.
state
.
append
(
'EOF'
)
def
connection_lost
(
self
,
exc
):
def
connection_lost
(
self
,
exc
):
if
'EOF'
not
in
self
.
state
:
self
.
state
.
append
(
'EOF'
)
# It is okay if EOF is missed.
assert
self
.
state
==
[
'INITIAL'
,
'CONNECTED'
,
'EOF'
],
self
.
state
assert
self
.
state
==
[
'INITIAL'
,
'CONNECTED'
,
'EOF'
],
self
.
state
self
.
state
.
append
(
'CLOSED'
)
self
.
state
.
append
(
'CLOSED'
)
if
self
.
done
:
if
self
.
done
:
...
@@ -953,6 +955,46 @@ class EventLoopTestsMixin:
...
@@ -953,6 +955,46 @@ class EventLoopTestsMixin:
# extra info is available
# extra info is available
self
.
assertIsNotNone
(
proto
.
transport
.
get_extra_info
(
'pipe'
))
self
.
assertIsNotNone
(
proto
.
transport
.
get_extra_info
(
'pipe'
))
@
unittest
.
skipUnless
(
sys
.
platform
!=
'win32'
,
"Don't support pipes for Windows"
)
def
test_read_pty_output
(
self
):
proto
=
None
def
factory
():
nonlocal
proto
proto
=
MyReadPipeProto
(
loop
=
self
.
loop
)
return
proto
master
,
slave
=
os
.
openpty
()
master_read_obj
=
io
.
open
(
master
,
'rb'
,
0
)
@
tasks
.
coroutine
def
connect
():
t
,
p
=
yield
from
self
.
loop
.
connect_read_pipe
(
factory
,
master_read_obj
)
self
.
assertIs
(
p
,
proto
)
self
.
assertIs
(
t
,
proto
.
transport
)
self
.
assertEqual
([
'INITIAL'
,
'CONNECTED'
],
proto
.
state
)
self
.
assertEqual
(
0
,
proto
.
nbytes
)
self
.
loop
.
run_until_complete
(
connect
())
os
.
write
(
slave
,
b'1'
)
test_utils
.
run_until
(
self
.
loop
,
lambda
:
proto
.
nbytes
)
self
.
assertEqual
(
1
,
proto
.
nbytes
)
os
.
write
(
slave
,
b'2345'
)
test_utils
.
run_until
(
self
.
loop
,
lambda
:
proto
.
nbytes
>=
5
)
self
.
assertEqual
([
'INITIAL'
,
'CONNECTED'
],
proto
.
state
)
self
.
assertEqual
(
5
,
proto
.
nbytes
)
os
.
close
(
slave
)
self
.
loop
.
run_until_complete
(
proto
.
done
)
self
.
assertEqual
(
[
'INITIAL'
,
'CONNECTED'
,
'EOF'
,
'CLOSED'
],
proto
.
state
)
# extra info is available
self
.
assertIsNotNone
(
proto
.
transport
.
get_extra_info
(
'pipe'
))
@
unittest
.
skipUnless
(
sys
.
platform
!=
'win32'
,
@
unittest
.
skipUnless
(
sys
.
platform
!=
'win32'
,
"Don't support pipes for Windows"
)
"Don't support pipes for Windows"
)
def
test_write_pipe
(
self
):
def
test_write_pipe
(
self
):
...
...
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