Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
tweepy
Commits
74bdefd4
Commit
74bdefd4
authored
Feb 18, 2015
by
Michael Brooks
Browse files
use closed property, not _fp
parent
875bcdd3
Changes
2
Show whitespace changes
Inline
Side-by-side
tests/test_streaming.py
View file @
74bdefd4
...
...
@@ -162,12 +162,8 @@ class TweepyStreamReadBuffer(unittest.TestCase):
# Mock it's read function so it can't be called too many times
mock_read
=
MagicMock
(
side_effect
=
on_read
)
# Add an _fp member to it, like a real requests.raw stream
mock_fp
=
MagicMock
()
mock_fp
.
isclosed
.
return_value
=
True
try
:
with
patch
.
multiple
(
stream
,
rea
d
=
mock_read
,
_fp
=
mock_fp
,
create
=
True
):
with
patch
.
multiple
(
stream
,
c
rea
te
=
True
,
read
=
mock_read
,
closed
=
True
):
# Now the stream can't call 'read' more than call_limit times
# and it looks like a requests stream that is closed
buf
=
ReadBuffer
(
stream
,
50
)
...
...
@@ -175,7 +171,6 @@ class TweepyStreamReadBuffer(unittest.TestCase):
except
InfiniteLoopException
:
self
.
fail
(
"ReadBuffer.read_line tried to loop infinitely."
)
self
.
assertEqual
(
mock_fp
.
isclosed
.
call_count
,
1
)
# The mocked function not have been called at all since the stream looks closed
self
.
assertEqual
(
mock_read
.
call_count
,
0
)
...
...
tweepy/streaming.py
View file @
74bdefd4
...
...
@@ -154,7 +154,7 @@ class ReadBuffer(object):
self
.
_chunk_size
=
chunk_size
def
read_len
(
self
,
length
):
while
not
self
.
_stream
.
_fp
.
is
closed
()
:
while
not
self
.
_stream
.
closed
:
if
len
(
self
.
_buffer
)
>=
length
:
return
self
.
_pop
(
length
)
read_len
=
max
(
self
.
_chunk_size
,
length
-
len
(
self
.
_buffer
))
...
...
@@ -162,7 +162,7 @@ class ReadBuffer(object):
def
read_line
(
self
,
sep
=
'
\n
'
):
start
=
0
while
not
self
.
_stream
.
_fp
.
is
closed
()
:
while
not
self
.
_stream
.
closed
:
loc
=
self
.
_buffer
.
find
(
sep
,
start
)
if
loc
>=
0
:
return
self
.
_pop
(
loc
+
len
(
sep
))
...
...
@@ -292,9 +292,9 @@ class Stream(object):
def
_read_loop
(
self
,
resp
):
buf
=
ReadBuffer
(
resp
.
raw
,
self
.
chunk_size
)
while
self
.
running
and
not
resp
.
raw
.
_fp
.
is
closed
()
:
while
self
.
running
and
not
resp
.
raw
.
closed
:
length
=
0
while
not
resp
.
raw
.
_fp
.
is
closed
()
:
while
not
resp
.
raw
.
closed
:
line
=
buf
.
read_line
().
strip
()
if
not
line
:
self
.
listener
.
keep_alive
()
# keep-alive new lines are expected
...
...
@@ -334,7 +334,7 @@ class Stream(object):
# self._data(next_status_obj.decode('utf-8'))
if
resp
.
raw
.
_fp
.
is
closed
()
:
if
resp
.
raw
.
closed
:
self
.
on_closed
(
resp
)
def
_start
(
self
,
async
):
...
...
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