Skip to content

Commit

Permalink
Fix file content type check, refs #123.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed May 13, 2017
1 parent d52fa4f commit 2a0b565
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/OFS/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from email.generator import _make_boundary
from io import BytesIO
import struct
import sys

from AccessControl.class_init import InitializeClass
from AccessControl.Permissions import change_images_and_files
Expand All @@ -28,6 +27,7 @@
from Acquisition import Implicit
from DateTime.DateTime import DateTime
from Persistence import Persistent
from six import text_type
from zExceptions import Redirect, ResourceLockedError
from zope.contenttype import guess_content_type
from zope.event import notify
Expand All @@ -46,8 +46,6 @@
from ZPublisher import HTTPRangeSupport
from ZPublisher.HTTPRequest import FileUpload

if sys.version_info >= (3, ):
unicode = str

manage_addFileForm = DTMLFile(
'dtml/imageAdd', globals(), Kind='File', kind='file')
Expand Down Expand Up @@ -440,8 +438,8 @@ def PrincipiaSearchSource(self):

security.declarePrivate('update_data')
def update_data(self, data, content_type=None, size=None):
if isinstance(data, unicode):
raise TypeError('Data can only be str or file-like. '
if isinstance(data, text_type):
raise TypeError('Data can only be bytes or file-like. '
'Unicode objects are expressly forbidden.')

if content_type is not None:
Expand Down Expand Up @@ -519,7 +517,7 @@ def _read_data(self, file):

n = 1 << 16

if isinstance(file, str):
if isinstance(file, text_type):
raise ValueError("Must be bytes")

if isinstance(file, bytes):
Expand Down Expand Up @@ -822,8 +820,8 @@ class Image(File):

security.declarePrivate('update_data')
def update_data(self, data, content_type=None, size=None):
if isinstance(data, unicode):
raise TypeError('Data can only be str or file-like. '
if isinstance(data, text_type):
raise TypeError('Data can only be bytes or file-like. '
'Unicode objects are expressly forbidden.')

if size is None:
Expand Down

0 comments on commit 2a0b565

Please sign in to comment.