Commit 43423381 authored by Jérome Perrin's avatar Jérome Perrin

DMS py3

parent 9c762ee5
...@@ -2092,8 +2092,7 @@ class TestImage(ERP5TypeTestCase): ...@@ -2092,8 +2092,7 @@ class TestImage(ERP5TypeTestCase):
image_type, image_data = image.convert('jpg', display='thumbnail') image_type, image_data = image.convert('jpg', display='thumbnail')
self.assertEqual('image/jpeg', image_type) self.assertEqual('image/jpeg', image_type)
# magic # magic
self.assertEqual('\xff', image_data[0]) self.assertEqual(image_data[0:2], b'\xff\xd8')
self.assertEqual('\xd8', image_data[1])
def test_ImageSize(self): def test_ImageSize(self):
for filename, size in ( for filename, size in (
......
...@@ -234,10 +234,8 @@ class TestDocument(TestDocumentMixin): ...@@ -234,10 +234,8 @@ class TestDocument(TestDocumentMixin):
infile = urlopen(url) infile = urlopen(url)
# save as file with proper incl. format filename (for some reasons PIL uses this info) # save as file with proper incl. format filename (for some reasons PIL uses this info)
filename = "%s%stest-image-format-resize.%s" %(os.getcwd(), os.sep, format_) filename = "%s%stest-image-format-resize.%s" %(os.getcwd(), os.sep, format_)
f = open(filename, "w") with open(filename, "wb") as f:
image_data = infile.read() f.write(infile.read())
f.write(image_data)
f.close()
infile.close() infile.close()
file_size = len(image_data) file_size = len(image_data)
try: try:
...@@ -246,6 +244,7 @@ class TestDocument(TestDocumentMixin): ...@@ -246,6 +244,7 @@ class TestDocument(TestDocumentMixin):
image_size = image.size image_size = image.size
except ImportError: except ImportError:
identify_output = Popen(['identify', filename], identify_output = Popen(['identify', filename],
universal_newlines=True,
stdout=PIPE).communicate()[0] stdout=PIPE).communicate()[0]
image_size = tuple([int(x) for x in identify_output.split()[2].split('x')]) image_size = tuple([int(x) for x in identify_output.split()[2].split('x')])
os.remove(filename) os.remove(filename)
...@@ -3026,7 +3025,7 @@ class DocumentConsistencyTestCase(ERP5TypeTestCase): ...@@ -3026,7 +3025,7 @@ class DocumentConsistencyTestCase(ERP5TypeTestCase):
def afterSetUp(self): def afterSetUp(self):
self.document = self._getDocumentModule().newContent(portal_type=self.portal_type) self.document = self._getDocumentModule().newContent(portal_type=self.portal_type)
self.file_upload = makeFileUpload(self.filename) self.file_upload = makeFileUpload(self.filename)
with open(makeFilePath(self.filename)) as f: with open(makeFilePath(self.filename), 'rb') as f:
self.file_data = f.read() self.file_data = f.read()
self.file_size = len(self.file_data) self.file_size = len(self.file_data)
......
...@@ -315,7 +315,7 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, TextContent ...@@ -315,7 +315,7 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, TextContent
return text_content, message return text_content, message
content_type = self.getContentType() or DEFAULT_CONTENT_TYPE content_type = self.getContentType() or DEFAULT_CONTENT_TYPE
text_content = self.getData() text_content = self.getData() # TODO: don't we need to convert to bytes here ? what if it is PData ?
if content_type.endswith('xml'): if content_type.endswith('xml'):
try: try:
tree = etree.fromstring(text_content) tree = etree.fromstring(text_content)
...@@ -325,7 +325,10 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, TextContent ...@@ -325,7 +325,10 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, TextContent
except etree.XMLSyntaxError: # pylint: disable=catching-non-exception except etree.XMLSyntaxError: # pylint: disable=catching-non-exception
message = 'Conversion to base format without codec fails' message = 'Conversion to base format without codec fails'
elif content_type == 'text/html': elif content_type == 'text/html':
re_match = self.charset_parser.search(text_content) re_match = self.charset_parser.search(
# we don't really care about decoding errors for searching this
# regexp
text_content.decode('ascii', 'replace') if six.PY3 else text_content)
message = 'Conversion to base format succeeds' message = 'Conversion to base format succeeds'
if re_match is not None: if re_match is not None:
charset = re_match.group('charset') charset = re_match.group('charset')
...@@ -375,6 +378,12 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, TextContent ...@@ -375,6 +378,12 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, TextContent
"""Overriden method to check """Overriden method to check
permission to access content in raw format permission to access content in raw format
""" """
# XXX Zope4py3: should this return str ??
# We probably have "legacy" documents where `text_content` is a python2
# str encoded as something else than utf-8.
# Maybe we should introduce a new text_content_encoding property and
# expose API to getRawTextContent (as bytes) and getTextContent would return
# the decoded string.
self._checkConversionFormatPermission(None) self._checkConversionFormatPermission(None)
if default is _MARKER: if default is _MARKER:
return self._baseGetTextContent() return self._baseGetTextContent()
...@@ -407,6 +416,7 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, TextContent ...@@ -407,6 +416,7 @@ class TextDocument(CachedConvertableMixin, BaseConvertableFileMixin, TextContent
return self._setContentType(value) return self._setContentType(value)
def getData(self, default=_MARKER): def getData(self, default=_MARKER):
# type: () -> bytes | PData
"""getData must returns original content but TextDocument accepts """getData must returns original content but TextDocument accepts
data or text_content to store original content. data or text_content to store original content.
Fallback on text_content property if data is not defined Fallback on text_content property if data is not defined
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment