Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
033fdbb8
Commit
033fdbb8
authored
Jun 22, 2015
by
Gerhard Weis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce IUnboundStreamIterator to support publishing iterators of unknown length
parent
91f54a4e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
14 deletions
+48
-14
src/ZPublisher/Iterators.py
src/ZPublisher/Iterators.py
+18
-12
src/ZPublisher/WSGIPublisher.py
src/ZPublisher/WSGIPublisher.py
+5
-2
src/ZPublisher/tests/test_WSGIPublisher.py
src/ZPublisher/tests/test_WSGIPublisher.py
+25
-0
No files found.
src/ZPublisher/Iterators.py
View file @
033fdbb8
from
zope.interface
import
Interface
from
zope.interface
import
implements
class
IUnboundStreamIterator
(
Interface
):
"""
An iterator with unknown length that can be published.
"""
def
next
():
"""
Return a sequence of bytes out of the bytestream, or raise
StopIeration if we've reached the end of the bytestream.
"""
class
IStreamIterator
(
Interface
):
"""
An iterator that can be published.
An iterator
with known length
that can be published.
IStreamIterators must not read from the object database.
After the application finishes interpreting a request and
...
...
@@ -15,12 +27,6 @@ class IStreamIterator(Interface):
but it has a chance of going insane if it happens to be loading
or storing something in the other thread at the same time. """
def
next
():
"""
Return a sequence of bytes out of the bytestream, or raise
StopIeration if we've reached the end of the bytestream.
"""
def
__len__
():
"""
Return an integer representing the length of the object
...
...
src/ZPublisher/WSGIPublisher.py
View file @
033fdbb8
...
...
@@ -32,7 +32,7 @@ from ZPublisher.Publish import dont_publish_class
from
ZPublisher.Publish
import
get_module_info
from
ZPublisher.Publish
import
missing_name
from
ZPublisher.pubevents
import
PubStart
,
PubBeforeCommit
,
PubAfterTraversal
from
ZPublisher.Iterators
import
IStreamIterator
from
ZPublisher.Iterators
import
I
UnboundStreamIterator
,
I
StreamIterator
_NOW
=
None
# overwrite for testing
def
_now
():
...
...
@@ -137,10 +137,13 @@ class WSGIResponse(HTTPResponse):
body
.
seek
(
0
)
self
.
setHeader
(
'Content-Length'
,
'%d'
%
length
)
self
.
body
=
body
elif
IStreamIterator
.
providedBy
(
body
):
elif
I
Unbound
StreamIterator
.
providedBy
(
body
):
self
.
body
=
body
self
.
_streaming
=
1
HTTPResponse
.
setBody
(
self
,
''
,
title
,
is_error
)
elif
IStreamIterator
.
providedBy
(
body
):
self
.
body
=
body
HTTPResponse
.
setBody
(
self
,
''
,
title
,
is_error
)
else
:
HTTPResponse
.
setBody
(
self
,
body
,
title
,
is_error
)
...
...
src/ZPublisher/tests/test_WSGIPublisher.py
View file @
033fdbb8
...
...
@@ -136,6 +136,28 @@ class WSGIResponseTests(unittest.TestCase):
time
.
gmtime
(
time
.
mktime
(
WHEN
)))
self
.
assertTrue
((
'Date'
,
whenstr
)
in
headers
)
def
test_setBody_IUnboundStreamIterator
(
self
):
from
ZPublisher.Iterators
import
IUnboundStreamIterator
from
zope.interface
import
implements
class
test_streamiterator
:
implements
(
IUnboundStreamIterator
)
data
=
"hello"
done
=
0
def
next
(
self
):
if
not
self
.
done
:
self
.
done
=
1
return
self
.
data
raise
StopIteration
response
=
self
.
_makeOne
()
response
.
setStatus
(
200
)
body
=
test_streamiterator
()
response
.
setBody
(
body
)
response
.
finalize
()
self
.
assertTrue
(
body
is
response
.
body
)
def
test_setBody_IStreamIterator
(
self
):
from
ZPublisher.Iterators
import
IStreamIterator
from
zope.interface
import
implements
...
...
@@ -151,6 +173,9 @@ class WSGIResponseTests(unittest.TestCase):
return
self
.
data
raise
StopIteration
def
__len__
(
self
):
return
len
(
self
.
data
)
response
=
self
.
_makeOne
()
response
.
setStatus
(
200
)
body
=
test_streamiterator
()
...
...
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