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
5b29fe49
Commit
5b29fe49
authored
Dec 25, 2012
by
Kristján Valur Jónsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue #879399
Fix line buffering of socket._fileobject
parent
9154a29d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
3 deletions
+61
-3
Lib/socket.py
Lib/socket.py
+2
-2
Lib/test/test_socket.py
Lib/test/test_socket.py
+59
-1
No files found.
Lib/socket.py
View file @
5b29fe49
...
...
@@ -319,8 +319,8 @@ class _fileobject(object):
self
.
_wbuf
.
append
(
data
)
self
.
_wbuf_len
+=
len
(
data
)
if
(
self
.
_wbufsize
==
0
or
self
.
_wbufsize
==
1
and
'
\
n
'
in
data
or
self
.
_wbuf_len
>=
self
.
_wbufsize
):
(
self
.
_wbufsize
==
1
and
'
\
n
'
in
data
)
or
(
self
.
_wbufsize
>
1
and
self
.
_wbuf_len
>=
self
.
_wbufsize
)
):
self
.
flush
()
def
writelines
(
self
,
list
):
...
...
Lib/test/test_socket.py
View file @
5b29fe49
...
...
@@ -962,8 +962,8 @@ class FileObjectClassTestCase(SocketConnectedTest):
def
tearDown
(
self
):
self
.
serv_file
.
close
()
self
.
assertTrue
(
self
.
serv_file
.
closed
)
self
.
serv_file
=
None
SocketConnectedTest
.
tearDown
(
self
)
self
.
serv_file
=
None
def
clientSetUp
(
self
):
SocketConnectedTest
.
clientSetUp
(
self
)
...
...
@@ -1151,6 +1151,64 @@ class LineBufferedFileObjectClassTestCase(FileObjectClassTestCase):
bufsize
=
1
# Default-buffered for reading; line-buffered for writing
class
SocketMemo
(
object
):
"""A wrapper to keep track of sent data, needed to examine write behaviour"""
def
__init__
(
self
,
sock
):
self
.
_sock
=
sock
self
.
sent
=
[]
def
send
(
self
,
data
,
flags
=
0
):
n
=
self
.
_sock
.
send
(
data
,
flags
)
self
.
sent
.
append
(
data
[:
n
])
return
n
def
sendall
(
self
,
data
,
flags
=
0
):
self
.
_sock
.
sendall
(
data
,
flags
)
self
.
sent
.
append
(
data
)
def
__getattr__
(
self
,
attr
):
return
getattr
(
self
.
_sock
,
attr
)
def
getsent
(
self
):
return
[
e
.
tobytes
()
if
isinstance
(
e
,
memoryview
)
else
e
for
e
in
self
.
sent
]
def
setUp
(
self
):
FileObjectClassTestCase
.
setUp
(
self
)
self
.
serv_file
.
_sock
=
self
.
SocketMemo
(
self
.
serv_file
.
_sock
)
def
testLinebufferedWrite
(
self
):
# Write two lines, in small chunks
msg
=
MSG
.
strip
()
print
>>
self
.
serv_file
,
msg
,
print
>>
self
.
serv_file
,
msg
# second line:
print
>>
self
.
serv_file
,
msg
,
print
>>
self
.
serv_file
,
msg
,
print
>>
self
.
serv_file
,
msg
# third line
print
>>
self
.
serv_file
,
''
self
.
serv_file
.
flush
()
msg1
=
"%s %s
\
n
"
%
(
msg
,
msg
)
msg2
=
"%s %s %s
\
n
"
%
(
msg
,
msg
,
msg
)
msg3
=
"
\
n
"
self
.
assertEqual
(
self
.
serv_file
.
_sock
.
getsent
(),
[
msg1
,
msg2
,
msg3
])
def
_testLinebufferedWrite
(
self
):
msg
=
MSG
.
strip
()
msg1
=
"%s %s
\
n
"
%
(
msg
,
msg
)
msg2
=
"%s %s %s
\
n
"
%
(
msg
,
msg
,
msg
)
msg3
=
"
\
n
"
l1
=
self
.
cli_file
.
readline
()
self
.
assertEqual
(
l1
,
msg1
)
l2
=
self
.
cli_file
.
readline
()
self
.
assertEqual
(
l2
,
msg2
)
l3
=
self
.
cli_file
.
readline
()
self
.
assertEqual
(
l3
,
msg3
)
class
SmallBufferedFileObjectClassTestCase
(
FileObjectClassTestCase
):
...
...
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