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
df4a743a
Commit
df4a743a
authored
Jul 18, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix test_asyncore after merge. It needs to use bytes.
parent
b5a755e4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
14 deletions
+16
-14
Lib/asyncore.py
Lib/asyncore.py
+4
-3
Lib/test/test_asyncore.py
Lib/test/test_asyncore.py
+12
-11
No files found.
Lib/asyncore.py
View file @
df4a743a
...
@@ -344,14 +344,14 @@ class dispatcher:
...
@@ -344,14 +344,14 @@ class dispatcher:
# a closed connection is indicated by signaling
# a closed connection is indicated by signaling
# a read condition, and having recv() return 0.
# a read condition, and having recv() return 0.
self
.
handle_close
()
self
.
handle_close
()
return
''
return
b
''
else
:
else
:
return
data
return
data
except
socket
.
error
as
why
:
except
socket
.
error
as
why
:
# winsock sometimes throws ENOTCONN
# winsock sometimes throws ENOTCONN
if
why
[
0
]
in
[
ECONNRESET
,
ENOTCONN
,
ESHUTDOWN
]:
if
why
[
0
]
in
[
ECONNRESET
,
ENOTCONN
,
ESHUTDOWN
]:
self
.
handle_close
()
self
.
handle_close
()
return
''
return
b
''
else
:
else
:
raise
raise
...
@@ -447,7 +447,7 @@ class dispatcher_with_send(dispatcher):
...
@@ -447,7 +447,7 @@ class dispatcher_with_send(dispatcher):
def
__init__
(
self
,
sock
=
None
,
map
=
None
):
def
__init__
(
self
,
sock
=
None
,
map
=
None
):
dispatcher
.
__init__
(
self
,
sock
,
map
)
dispatcher
.
__init__
(
self
,
sock
,
map
)
self
.
out_buffer
=
''
self
.
out_buffer
=
b
''
def
initiate_send
(
self
):
def
initiate_send
(
self
):
num_sent
=
0
num_sent
=
0
...
@@ -461,6 +461,7 @@ class dispatcher_with_send(dispatcher):
...
@@ -461,6 +461,7 @@ class dispatcher_with_send(dispatcher):
return
(
not
self
.
connected
)
or
len
(
self
.
out_buffer
)
return
(
not
self
.
connected
)
or
len
(
self
.
out_buffer
)
def
send
(
self
,
data
):
def
send
(
self
,
data
):
assert
isinstance
(
data
,
bytes
)
if
self
.
debug
:
if
self
.
debug
:
self
.
log_info
(
'sending %s'
%
repr
(
data
))
self
.
log_info
(
'sending %s'
%
repr
(
data
))
self
.
out_buffer
=
self
.
out_buffer
+
data
self
.
out_buffer
=
self
.
out_buffer
+
data
...
...
Lib/test/test_asyncore.py
View file @
df4a743a
...
@@ -9,7 +9,7 @@ import time
...
@@ -9,7 +9,7 @@ import time
from
test
import
test_support
from
test
import
test_support
from
test.test_support
import
TESTFN
,
run_unittest
,
unlink
from
test.test_support
import
TESTFN
,
run_unittest
,
unlink
from
StringIO
import
String
IO
from
io
import
StringIO
,
Bytes
IO
HOST
=
"127.0.0.1"
HOST
=
"127.0.0.1"
PORT
=
54329
PORT
=
54329
...
@@ -66,9 +66,10 @@ def capture_server(evt, buf):
...
@@ -66,9 +66,10 @@ def capture_server(evt, buf):
n
=
200
n
=
200
while
n
>
0
:
while
n
>
0
:
data
=
conn
.
recv
(
10
)
data
=
conn
.
recv
(
10
)
assert
isinstance
(
data
,
bytes
)
# keep everything except for the newline terminator
# keep everything except for the newline terminator
buf
.
write
(
data
.
replace
(
'
\
n
'
,
''
))
buf
.
write
(
data
.
replace
(
b'
\
n
'
,
b
''
))
if
'
\
n
'
in
data
:
if
b
'
\
n
'
in
data
:
break
break
n
-=
1
n
-=
1
time
.
sleep
(
0.01
)
time
.
sleep
(
0.01
)
...
@@ -338,16 +339,16 @@ class DispatcherWithSendTests(unittest.TestCase):
...
@@ -338,16 +339,16 @@ class DispatcherWithSendTests(unittest.TestCase):
def
test_send
(
self
):
def
test_send
(
self
):
self
.
evt
=
threading
.
Event
()
self
.
evt
=
threading
.
Event
()
cap
=
String
IO
()
cap
=
Bytes
IO
()
threading
.
Thread
(
target
=
capture_server
,
args
=
(
self
.
evt
,
cap
)).
start
()
threading
.
Thread
(
target
=
capture_server
,
args
=
(
self
.
evt
,
cap
)).
start
()
time
.
sleep
(
1
)
# Give server time to initialize
time
.
sleep
(
1
)
# Give server time to initialize
data
=
"Suppose there isn't a 16-ton weight?"
*
5
data
=
b
"Suppose there isn't a 16-ton weight?"
*
5
d
=
dispatcherwithsend_noread
()
d
=
dispatcherwithsend_noread
()
d
.
create_socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
d
.
create_socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
d
.
connect
((
HOST
,
PORT
))
d
.
connect
((
HOST
,
PORT
))
d
.
send
(
data
)
d
.
send
(
data
)
d
.
send
(
'
\
n
'
)
d
.
send
(
b
'
\
n
'
)
n
=
1000
n
=
1000
while
d
.
out_buffer
and
n
>
0
:
while
d
.
out_buffer
and
n
>
0
:
...
@@ -366,7 +367,7 @@ if hasattr(asyncore, 'file_wrapper'):
...
@@ -366,7 +367,7 @@ if hasattr(asyncore, 'file_wrapper'):
class
FileWrapperTest
(
unittest
.
TestCase
):
class
FileWrapperTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
d
=
"It's not dead, it's sleeping!"
self
.
d
=
"It's not dead, it's sleeping!"
file
(
TESTFN
,
'w'
).
write
(
self
.
d
)
open
(
TESTFN
,
'w'
).
write
(
self
.
d
)
def
tearDown
(
self
):
def
tearDown
(
self
):
unlink
(
TESTFN
)
unlink
(
TESTFN
)
...
@@ -377,8 +378,8 @@ if hasattr(asyncore, 'file_wrapper'):
...
@@ -377,8 +378,8 @@ if hasattr(asyncore, 'file_wrapper'):
self
.
assertEqual
(
w
.
fd
,
fd
)
self
.
assertEqual
(
w
.
fd
,
fd
)
self
.
assertEqual
(
w
.
fileno
(),
fd
)
self
.
assertEqual
(
w
.
fileno
(),
fd
)
self
.
assertEqual
(
w
.
recv
(
13
),
"It's not dead"
)
self
.
assertEqual
(
w
.
recv
(
13
),
b
"It's not dead"
)
self
.
assertEqual
(
w
.
read
(
6
),
", it's"
)
self
.
assertEqual
(
w
.
read
(
6
),
b
", it's"
)
w
.
close
()
w
.
close
()
self
.
assertRaises
(
OSError
,
w
.
read
,
1
)
self
.
assertRaises
(
OSError
,
w
.
read
,
1
)
...
@@ -391,7 +392,7 @@ if hasattr(asyncore, 'file_wrapper'):
...
@@ -391,7 +392,7 @@ if hasattr(asyncore, 'file_wrapper'):
w
.
write
(
d1
)
w
.
write
(
d1
)
w
.
send
(
d2
)
w
.
send
(
d2
)
w
.
close
()
w
.
close
()
self
.
assertEqual
(
file
(
TESTFN
).
read
(),
self
.
d
+
d1
+
d2
)
self
.
assertEqual
(
open
(
TESTFN
).
read
(),
self
.
d
+
d1
+
d2
)
def
test_main
():
def
test_main
():
...
...
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