[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Image - Image.py:1.1.2.3 ImageData.py:1.1.2.4

Martijn Pieters mj@zope.com
Wed, 13 Feb 2002 00:03:36 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Image
In directory cvs.zope.org:/tmp/cvs-serv14206/App/OFS/Image

Modified Files:
      Tag: Zope-3x-branch
	Image.py ImageData.py 
Log Message:
Optimizations and code style updates:

  - Use isinstance on type checks

  - Test UnicodeType and StringType through StringTypes

  - Remove use of the string module

  - Use startswith and endswith instead of slices.

  - Fix weird tests where isinstance suffices.


=== Zope3/lib/python/Zope/App/OFS/Image/Image.py 1.1.2.2 => 1.1.2.3 ===
     # Bytes 0-7 are below, 4-byte chunk length, then 'IHDR'
     # and finally the 4-byte width, height
-    elif ((size >= 24) and (data[:8] == '\211PNG\r\n\032\n')
+    elif ((size >= 24) and data.startswith('\211PNG\r\n\032\n')
           and (data[12:16] == 'IHDR')):
         content_type = 'image/png'
         w, h = struct.unpack(">LL", data[16:24])
@@ -89,7 +89,7 @@
         height = int(h)
             
     # Maybe this is for an older PNG version.
-    elif (size >= 16) and (data[:8] == '\211PNG\r\n\032\n'):
+    elif (size >= 16) and data.startswith('\211PNG\r\n\032\n'):
         # Check to see if we have the right content type
         content_type = 'image/png'
         w, h = struct.unpack(">LL", data[8:16])
@@ -97,7 +97,7 @@
         height = int(h)
 
     # handle JPEGs
-    elif (size >= 2) and (data[:2] == '\377\330'):
+    elif (size >= 2) and data.startswith('\377\330'):
         content_type = 'image/jpeg'
         jpeg = StringIO(data)
         jpeg.read(2)


=== Zope3/lib/python/Zope/App/OFS/Image/ImageData.py 1.1.2.3 => 1.1.2.4 ===
 """
 
-import string
 from Zope.Publisher.Browser.AttributePublisher import AttributePublisher
 from Zope.PageTemplate.PageTemplateFile import PageTemplateFile
 
@@ -77,7 +76,7 @@
         if width is not None:
             result = '%s width="%s"' % (result, width)
 
-        if not 'border' in map(string.lower, args.keys()):
+        if not 'border' in [a.lower() for a in args.keys()]:
             result = '%s border="0"' % result
 
         if css_class is not None: