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
32e810f1
Commit
32e810f1
authored
Sep 12, 2016
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace file class by Python 3 compatible io classes.
parent
3c669886
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
12 deletions
+47
-12
src/App/tests/testImageFile.py
src/App/tests/testImageFile.py
+29
-1
src/OFS/tests/testFileAndImage.py
src/OFS/tests/testFileAndImage.py
+4
-1
src/ZPublisher/Iterators.py
src/ZPublisher/Iterators.py
+8
-6
src/ZPublisher/WSGIPublisher.py
src/ZPublisher/WSGIPublisher.py
+4
-3
src/ZPublisher/tests/test_WSGIPublisher.py
src/ZPublisher/tests/test_WSGIPublisher.py
+2
-1
No files found.
src/App/tests/testImageFile.py
View file @
32e810f1
import
unittest
import
io
import
os.path
from
StringIO
import
StringIO
import
unittest
import
App
from
Testing.ZopeTestCase.warnhook
import
WarningsHook
from
ZPublisher.HTTPRequest
import
WSGIRequest
from
ZPublisher.HTTPResponse
import
WSGIResponse
class
TestImageFile
(
unittest
.
TestCase
):
...
...
@@ -39,3 +44,26 @@ class TestImageFile(unittest.TestCase):
prefix
=
App
.
__dict__
App
.
ImageFile
.
ImageFile
(
'www/zopelogo.png'
,
prefix
)
self
.
assertFalse
(
self
.
warningshook
.
warnings
)
class
TestImageFileFunctional
(
unittest
.
TestCase
):
def
test_index_html
(
self
):
env
=
{
'SERVER_NAME'
:
'localhost'
,
'SERVER_PORT'
:
'80'
,
'SERVER_PROTOCOL'
:
'HTTP/1.1'
,
'REQUEST_METHOD'
:
'GET'
,
}
stdin
=
StringIO
()
stdout
=
StringIO
()
response
=
WSGIResponse
(
stdout
)
request
=
WSGIRequest
(
stdin
,
env
,
response
)
path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
App
.
__file__
),
'www'
,
'zopelogo.png'
)
image
=
App
.
ImageFile
.
ImageFile
(
path
)
result
=
image
.
index_html
(
request
,
response
)
self
.
assertEqual
(
stdout
.
getvalue
(),
''
)
self
.
assertTrue
(
isinstance
(
result
,
io
.
FileIO
))
self
.
assertTrue
(
b''
.
join
(
result
).
startswith
(
b'
\
x89
PNG
\
r
\
n
'
))
self
.
assertEqual
(
len
(
result
),
image
.
size
)
src/OFS/tests/testFileAndImage.py
View file @
32e810f1
...
...
@@ -273,7 +273,10 @@ class ImageTests(FileTests):
self
.
assertEqual
(
self
.
file
.
tag
(),
(
tag_fmt
%
(
'bar'
,
'foo'
)))
def
testViewImageOrFile
(
self
):
pass
# dtml method,screw it
request
=
self
.
app
.
REQUEST
response
=
request
.
RESPONSE
result
=
self
.
file
.
index_html
(
request
,
response
)
self
.
assertEqual
(
result
,
self
.
data
)
def
test_interfaces
(
self
):
from
zope.interface.verify
import
verifyClass
...
...
src/ZPublisher/Iterators.py
View file @
32e810f1
import
io
from
zope.interface
import
Interface
from
zope.interface
import
implements
...
...
@@ -36,16 +38,16 @@ class IStreamIterator(IUnboundStreamIterator):
"""
class
filestream_iterator
(
file
):
class
filestream_iterator
(
io
.
FileIO
):
"""
a file
subclass which implements an iterator that returns a
A FileIO
subclass which implements an iterator that returns a
fixed-sized sequence of bytes.
"""
implements
(
IStreamIterator
)
def
__init__
(
self
,
name
,
mode
=
'r'
,
bufsize
=-
1
,
streamsize
=
1
<<
16
):
file
.
__init__
(
self
,
name
,
mode
,
bufsiz
e
)
def
__init__
(
self
,
name
,
mode
=
'r
b
'
,
bufsize
=-
1
,
streamsize
=
1
<<
16
):
super
(
filestream_iterator
,
self
).
__init__
(
name
,
mod
e
)
self
.
streamsize
=
streamsize
def
next
(
self
):
...
...
@@ -56,7 +58,7 @@ class filestream_iterator(file):
def
__len__
(
self
):
cur_pos
=
self
.
tell
()
self
.
seek
(
0
,
2
)
self
.
seek
(
0
,
io
.
SEEK_END
)
size
=
self
.
tell
()
self
.
seek
(
cur_pos
,
0
)
self
.
seek
(
cur_pos
,
io
.
SEEK_SET
)
return
size
src/ZPublisher/WSGIPublisher.py
View file @
32e810f1
...
...
@@ -14,6 +14,7 @@
"""
from
contextlib
import
contextmanager
,
closing
from
cStringIO
import
StringIO
from
io
import
IOBase
import
sys
from
thread
import
allocate_lock
...
...
@@ -40,9 +41,9 @@ from ZPublisher import pubevents
from
ZPublisher.utils
import
recordMetaData
if
sys
.
version_info
>=
(
3
,
):
from
io
import
IOBase
_FILE_TYPES
=
(
IOBase
,
)
else
:
IOBase
=
file
# NOQA
_FILE_TYPES
=
(
IOBase
,
file
)
# NOQA
_DEFAULT_DEBUG_MODE
=
False
_DEFAULT_REALM
=
None
...
...
@@ -229,7 +230,7 @@ def publish_module(environ, start_response,
status
,
headers
=
response
.
finalize
()
start_response
(
status
,
headers
)
if
(
isinstance
(
response
.
body
,
IOBase
)
or
if
(
isinstance
(
response
.
body
,
_FILE_TYPES
)
or
IUnboundStreamIterator
.
providedBy
(
response
.
body
)):
result
=
response
.
body
else
:
...
...
src/ZPublisher/tests/test_WSGIPublisher.py
View file @
32e810f1
...
...
@@ -320,8 +320,9 @@ class TestPublishModule(unittest.TestCase, PlacelessSetup):
self
.
assertEqual
(
kw
,
{})
def
test_response_body_is_file
(
self
):
from
io
import
BytesIO
class
DummyFile
(
file
):
class
DummyFile
(
BytesIO
):
def
__init__
(
self
):
pass
...
...
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