[Zope-CMF] FSPropertiesObject

Chris Withers chrisw@nipltd.com
Sat, 07 Jul 2001 01:49:22 +0100


This is a multi-part message in MIME format.
--------------042841E0318C4CD0F1DA28BE
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

The attached patch to FSPropertiesobject.py does two things:

1. It tells you which line the file reading method barfed on, if it barfs.

2. It allows you to put blank lines in the .props file so you can split up
groups of properties.

If anyoen finds this useful, stick this in the Tracker 'cos you'll get around to
it before I do ;-)

cheers,

Chris
--------------042841E0318C4CD0F1DA28BE
Content-Type: text/plain; charset=us-ascii;
 name="FSPropertiesObject.py.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="FSPropertiesObject.py.patch"

--- FSPropertiesObject.py.original	Thu May 17 14:57:52 2001
+++ FSPropertiesObject.py	Thu Jul 05 08:19:12 2001
@@ -165,23 +165,30 @@
         try: lines = file.readlines()
         finally: file.close()
         map = []
+        lino=0
         for line in lines:
-            propname, proptv = split( line, ':' )
-            #XXX multi-line properties?
-            proptype, propvstr = split( proptv, '=' )
-            propname = strip(propname)
-            proptv = strip(proptv)
-            propvstr = strip(propvstr)
-            converter = get_converter( proptype, lambda x: x )
-            propvalue = converter( strip( propvstr ) )
-            # Should be safe since we're loading from
-            # the filesystem.
-            setattr(self, propname, propvalue)
-            map.append({'id':propname,
-                        'type':proptype,
-                        'mode':'',
-                        'default_value':propvalue,
-                        })
+            lino = lino + 1
+            if not strip(line):
+                continue
+            try:
+                propname, proptv = split( line, ':' )
+                #XXX multi-line properties?
+                proptype, propvstr = split( proptv, '=' )
+                propname = strip(propname)
+                proptv = strip(proptv)
+                propvstr = strip(propvstr)
+                converter = get_converter( proptype, lambda x: x )
+                propvalue = converter( strip( propvstr ) )
+                # Should be safe since we're loading from
+                # the filesystem.
+                setattr(self, propname, propvalue)
+                map.append({'id':propname,
+                            'type':proptype,
+                            'mode':'',
+                            'default_value':propvalue,
+                            })
+            except:
+                raise ValueError,'Error processing line %s of %s:\n%s' % (lino,fp,line)
         self._properties = tuple(map)            
 
     if Globals.DevelopmentMode:

--------------042841E0318C4CD0F1DA28BE--