[Zope-Checkins] SVN: Zope/branches/2.10/ OFS Image: Image and File now both support simple unicode objects for data (they function the same as strings for data).
Log message for revision 68876: OFS Image: Image and File now both support simple unicode objects for data (they function the same as strings for data). Changed: U Zope/branches/2.10/doc/CHANGES.txt U Zope/branches/2.10/lib/python/OFS/Image.py U Zope/branches/2.10/lib/python/OFS/tests/testFileAndImage.py -=- Modified: Zope/branches/2.10/doc/CHANGES.txt === --- Zope/branches/2.10/doc/CHANGES.txt 2006-06-28 11:20:16 UTC (rev 68875) +++ Zope/branches/2.10/doc/CHANGES.txt 2006-06-28 11:24:05 UTC (rev 68876) @@ -18,6 +18,9 @@ Bugs Fixed + - OFS Image: Image and File now both support simple unicode objects +for data (they function the same as strings for data). + - OFS Application: Updated deprecation warnings. Support for '__ac_permissions__' and 'meta_types' will be removed in Zope 2.11, 'methods' support might remain longer. Modified: Zope/branches/2.10/lib/python/OFS/Image.py === --- Zope/branches/2.10/lib/python/OFS/Image.py 2006-06-28 11:20:16 UTC (rev 68875) +++ Zope/branches/2.10/lib/python/OFS/Image.py 2006-06-28 11:24:05 UTC (rev 68876) @@ -43,7 +43,6 @@ from cgi import escape import transaction -StringType=type('') manage_addFileForm=DTMLFile('dtml/imageAdd', globals(),Kind='File',kind='file') def manage_addFile(self,id,file='',title='',precondition='', content_type='', REQUEST=None): @@ -231,7 +230,7 @@ RESPONSE.setStatus(206) # Partial content data = self.data -if type(data) is StringType: +if isinstance(data, basestring): RESPONSE.write(data[start:end]) return True @@ -302,7 +301,7 @@ 'Content-Range: bytes %d-%d/%d\r\n\r\n' % ( start, end - 1, self.size)) -if type(data) is StringType: +if isinstance(data, basestring): RESPONSE.write(data[start:end]) else: @@ -401,7 +400,7 @@ self.ZCacheable_set(None) data=self.data -if type(data) is type(''): +if isinstance(data, basestring): RESPONSE.setBase(None) return data @@ -481,7 +480,7 @@ if headers and headers.has_key('content-type'): content_type=headers['content-type'] else: -if type(body) is not type(''): body=body.data +if not isinstance(body, basestring): body=body.data content_type, enc=guess_content_type( getattr(file, 'filename',id), body, content_type) return content_type @@ -490,7 +489,7 @@ n=1 16 -if type(file) is StringType: +if isinstance(file, basestring): size=len(file) if size n: return file, size # Big string: cut it into smaller chunks @@ -617,7 +616,7 @@ return result data = self.data -if type(data) is type(''): +if isinstance(data, basestring): RESPONSE.setBase(None) return data Modified: Zope/branches/2.10/lib/python/OFS/tests/testFileAndImage.py === --- Zope/branches/2.10/lib/python/OFS/tests/testFileAndImage.py 2006-06-28 11:20:16 UTC (rev 68875) +++ Zope/branches/2.10/lib/python/OFS/tests/testFileAndImage.py 2006-06-28 11:24:05 UTC (rev 68876) @@ -252,7 +252,15 @@ verifyClass(HTTPRangeInterface, File) verifyClass(WriteLockInterface, File) - +def testUnicodeWithIndexHtml(self): +# Introduced to help test the fact that Image.py has been +# changed to be lenient towards any basestring type, not just str + +val = u'some unicode string here' +self.file.manage_edit('foobar', 'text/plain', filedata=val) +s = self.file.index_html(self.app.REQUEST, self.app.REQUEST.RESPONSE) +self.assertEquals(s, val) + class ImageTests(FileTests): data = open(filedata, 'rb').read() content_type = 'image/gif' @@ -285,7 +293,6 @@ verifyClass(WriteLockInterface, Image) - def test_suite(): return unittest.TestSuite(( unittest.makeSuite(FileTests), ___ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins
[Zope-Checkins] SVN: Zope/trunk/ OFS Image: Image and File now both support simple unicode objects for data (they function the same as strings for data).
Log message for revision 68877: OFS Image: Image and File now both support simple unicode objects for data (they function the same as strings for data). Changed: U Zope/trunk/doc/CHANGES.txt U Zope/trunk/lib/python/OFS/Image.py U Zope/trunk/lib/python/OFS/tests/testFileAndImage.py -=- Modified: Zope/trunk/doc/CHANGES.txt === --- Zope/trunk/doc/CHANGES.txt 2006-06-28 11:24:05 UTC (rev 68876) +++ Zope/trunk/doc/CHANGES.txt 2006-06-28 11:38:18 UTC (rev 68877) @@ -27,6 +27,9 @@ Bugs Fixed + - OFS Image: Image and File now both support simple unicode objects +for data (they function the same as strings for data). + - Collector #2122: fixed missing is_proxying_match definition in ZServer/HTTPServer Modified: Zope/trunk/lib/python/OFS/Image.py === --- Zope/trunk/lib/python/OFS/Image.py 2006-06-28 11:24:05 UTC (rev 68876) +++ Zope/trunk/lib/python/OFS/Image.py 2006-06-28 11:38:18 UTC (rev 68877) @@ -43,7 +43,6 @@ from cgi import escape import transaction -StringType=type('') manage_addFileForm=DTMLFile('dtml/imageAdd', globals(),Kind='File',kind='file') def manage_addFile(self,id,file='',title='',precondition='', content_type='', REQUEST=None): @@ -231,7 +230,7 @@ RESPONSE.setStatus(206) # Partial content data = self.data -if type(data) is StringType: +if isinstance(data, basestring): RESPONSE.write(data[start:end]) return True @@ -302,7 +301,7 @@ 'Content-Range: bytes %d-%d/%d\r\n\r\n' % ( start, end - 1, self.size)) -if type(data) is StringType: +if isinstance(data, basestring): RESPONSE.write(data[start:end]) else: @@ -401,7 +400,7 @@ self.ZCacheable_set(None) data=self.data -if type(data) is type(''): +if isinstance(data, basestring): RESPONSE.setBase(None) return data @@ -481,7 +480,7 @@ if headers and headers.has_key('content-type'): content_type=headers['content-type'] else: -if type(body) is not type(''): body=body.data +if not isinstance(body, basestring): body=body.data content_type, enc=guess_content_type( getattr(file, 'filename',id), body, content_type) return content_type @@ -490,7 +489,7 @@ n=1 16 -if type(file) is StringType: +if isinstance(file, basestring): size=len(file) if size n: return file, size # Big string: cut it into smaller chunks @@ -617,7 +616,7 @@ return result data = self.data -if type(data) is type(''): +if isinstance(data, basestring): RESPONSE.setBase(None) return data Modified: Zope/trunk/lib/python/OFS/tests/testFileAndImage.py === --- Zope/trunk/lib/python/OFS/tests/testFileAndImage.py 2006-06-28 11:24:05 UTC (rev 68876) +++ Zope/trunk/lib/python/OFS/tests/testFileAndImage.py 2006-06-28 11:38:18 UTC (rev 68877) @@ -252,7 +252,15 @@ verifyClass(HTTPRangeInterface, File) verifyClass(WriteLockInterface, File) - +def testUnicodeWithIndexHtml(self): +# Introduced to help test the fact that Image.py has been +# changed to be lenient towards any basestring type, not just str + +val = u'some unicode string here' +self.file.manage_edit('foobar', 'text/plain', filedata=val) +s = self.file.index_html(self.app.REQUEST, self.app.REQUEST.RESPONSE) +self.assertEquals(s, val) + class ImageTests(FileTests): data = open(filedata, 'rb').read() content_type = 'image/gif' @@ -285,7 +293,6 @@ verifyClass(WriteLockInterface, Image) - def test_suite(): return unittest.TestSuite(( unittest.makeSuite(FileTests), ___ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins
[Zope-Checkins] SVN: Zope/branches/2.10/ OFS Image: Image and File updated to use isinstance(data, str) and raises TypeError upon encountering unicode objects.
Log message for revision 68879: OFS Image: Image and File updated to use isinstance(data, str) and raises TypeError upon encountering unicode objects. Changed: U Zope/branches/2.10/doc/CHANGES.txt U Zope/branches/2.10/lib/python/OFS/Image.py U Zope/branches/2.10/lib/python/OFS/tests/testFileAndImage.py -=- Modified: Zope/branches/2.10/doc/CHANGES.txt === --- Zope/branches/2.10/doc/CHANGES.txt 2006-06-28 11:40:37 UTC (rev 68878) +++ Zope/branches/2.10/doc/CHANGES.txt 2006-06-28 12:43:34 UTC (rev 68879) @@ -18,8 +18,8 @@ Bugs Fixed - - OFS Image: Image and File now both support simple unicode objects -for data (they function the same as strings for data). + - OFS Image: Image and File updated to use isinstance(data, str) +and raises TypeError upon encountering unicode objects. - OFS Application: Updated deprecation warnings. Support for '__ac_permissions__' and 'meta_types' will be removed in Modified: Zope/branches/2.10/lib/python/OFS/Image.py === --- Zope/branches/2.10/lib/python/OFS/Image.py 2006-06-28 11:40:37 UTC (rev 68878) +++ Zope/branches/2.10/lib/python/OFS/Image.py 2006-06-28 12:43:34 UTC (rev 68879) @@ -230,7 +230,7 @@ RESPONSE.setStatus(206) # Partial content data = self.data -if isinstance(data, basestring): +if isinstance(data, str): RESPONSE.write(data[start:end]) return True @@ -301,7 +301,7 @@ 'Content-Range: bytes %d-%d/%d\r\n\r\n' % ( start, end - 1, self.size)) -if isinstance(data, basestring): +if isinstance(data, str): RESPONSE.write(data[start:end]) else: @@ -400,7 +400,7 @@ self.ZCacheable_set(None) data=self.data -if isinstance(data, basestring): +if isinstance(data, str): RESPONSE.setBase(None) return data @@ -427,6 +427,10 @@ 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. ' +'Unicode objects are expressly forbidden.') + if content_type is not None: self.content_type=content_type if size is None: size=len(data) self.size=size @@ -480,7 +484,7 @@ if headers and headers.has_key('content-type'): content_type=headers['content-type'] else: -if not isinstance(body, basestring): body=body.data +if not isinstance(body, str): body=body.data content_type, enc=guess_content_type( getattr(file, 'filename',id), body, content_type) return content_type @@ -489,7 +493,7 @@ n=1 16 -if isinstance(file, basestring): +if isinstance(file, str): size=len(file) if size n: return file, size # Big string: cut it into smaller chunks @@ -616,7 +620,7 @@ return result data = self.data -if isinstance(data, basestring): +if isinstance(data, str): RESPONSE.setBase(None) return data @@ -776,6 +780,10 @@ 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. ' +'Unicode objects are expressly forbidden.') + if size is None: size=len(data) self.size=size Modified: Zope/branches/2.10/lib/python/OFS/tests/testFileAndImage.py === --- Zope/branches/2.10/lib/python/OFS/tests/testFileAndImage.py 2006-06-28 11:40:37 UTC (rev 68878) +++ Zope/branches/2.10/lib/python/OFS/tests/testFileAndImage.py 2006-06-28 12:43:34 UTC (rev 68879) @@ -252,15 +252,12 @@ verifyClass(HTTPRangeInterface, File) verifyClass(WriteLockInterface, File) -def testUnicodeWithIndexHtml(self): -# Introduced to help test the fact that Image.py has been -# changed to be lenient towards any basestring type, not just str - +def testUnicode(self): val = u'some unicode string here' -self.file.manage_edit('foobar', 'text/plain', filedata=val) -s = self.file.index_html(self.app.REQUEST, self.app.REQUEST.RESPONSE) -self.assertEquals(s, val) +self.assertRaises(TypeError, self.file.manage_edit, + 'foobar', 'text/plain', filedata=val) +
[Zope-Checkins] SVN: Zope/trunk/ OFS Image: Image and File updated to use isinstance(data, str) and raises TypeError upon encountering unicode objects.
Log message for revision 68880: OFS Image: Image and File updated to use isinstance(data, str) and raises TypeError upon encountering unicode objects. Changed: U Zope/trunk/doc/CHANGES.txt U Zope/trunk/lib/python/OFS/Image.py U Zope/trunk/lib/python/OFS/tests/testFileAndImage.py -=- Modified: Zope/trunk/doc/CHANGES.txt === --- Zope/trunk/doc/CHANGES.txt 2006-06-28 12:43:34 UTC (rev 68879) +++ Zope/trunk/doc/CHANGES.txt 2006-06-28 12:50:34 UTC (rev 68880) @@ -27,8 +27,8 @@ Bugs Fixed - - OFS Image: Image and File now both support simple unicode objects -for data (they function the same as strings for data). + - OFS Image: Image and File updated to use isinstance(data, str) +and raises TypeError upon encountering unicode objects. - Collector #2122: fixed missing is_proxying_match definition in ZServer/HTTPServer Modified: Zope/trunk/lib/python/OFS/Image.py === --- Zope/trunk/lib/python/OFS/Image.py 2006-06-28 12:43:34 UTC (rev 68879) +++ Zope/trunk/lib/python/OFS/Image.py 2006-06-28 12:50:34 UTC (rev 68880) @@ -230,7 +230,7 @@ RESPONSE.setStatus(206) # Partial content data = self.data -if isinstance(data, basestring): +if isinstance(data, str): RESPONSE.write(data[start:end]) return True @@ -301,7 +301,7 @@ 'Content-Range: bytes %d-%d/%d\r\n\r\n' % ( start, end - 1, self.size)) -if isinstance(data, basestring): +if isinstance(data, str): RESPONSE.write(data[start:end]) else: @@ -400,7 +400,7 @@ self.ZCacheable_set(None) data=self.data -if isinstance(data, basestring): +if isinstance(data, str): RESPONSE.setBase(None) return data @@ -427,6 +427,10 @@ 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. ' +'Unicode objects are expressly forbidden.') + if content_type is not None: self.content_type=content_type if size is None: size=len(data) self.size=size @@ -480,7 +484,7 @@ if headers and headers.has_key('content-type'): content_type=headers['content-type'] else: -if not isinstance(body, basestring): body=body.data +if not isinstance(body, str): body=body.data content_type, enc=guess_content_type( getattr(file, 'filename',id), body, content_type) return content_type @@ -489,7 +493,7 @@ n=1 16 -if isinstance(file, basestring): +if isinstance(file, str): size=len(file) if size n: return file, size # Big string: cut it into smaller chunks @@ -616,7 +620,7 @@ return result data = self.data -if isinstance(data, basestring): +if isinstance(data, str): RESPONSE.setBase(None) return data @@ -776,6 +780,10 @@ 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. ' +'Unicode objects are expressly forbidden.') + if size is None: size=len(data) self.size=size Modified: Zope/trunk/lib/python/OFS/tests/testFileAndImage.py === --- Zope/trunk/lib/python/OFS/tests/testFileAndImage.py 2006-06-28 12:43:34 UTC (rev 68879) +++ Zope/trunk/lib/python/OFS/tests/testFileAndImage.py 2006-06-28 12:50:34 UTC (rev 68880) @@ -252,15 +252,12 @@ verifyClass(HTTPRangeInterface, File) verifyClass(WriteLockInterface, File) -def testUnicodeWithIndexHtml(self): -# Introduced to help test the fact that Image.py has been -# changed to be lenient towards any basestring type, not just str - +def testUnicode(self): val = u'some unicode string here' -self.file.manage_edit('foobar', 'text/plain', filedata=val) -s = self.file.index_html(self.app.REQUEST, self.app.REQUEST.RESPONSE) -self.assertEquals(s, val) +self.assertRaises(TypeError, self.file.manage_edit, + 'foobar', 'text/plain', filedata=val) + class ImageTests(FileTests): data = open(filedata, 'rb').read() content_type = 'image/gif'