Author: cito
Date: Wed Dec 30 16:01:53 2015
New Revision: 678

Log:
More elegant code using decorators and dict comprehension

Modified:
   trunk/module/pgdb.py

Modified: trunk/module/pgdb.py
==============================================================================
--- trunk/module/pgdb.py        Wed Dec 30 15:55:07 2015        (r677)
+++ trunk/module/pgdb.py        Wed Dec 30 16:01:53 2015        (r678)
@@ -103,7 +103,7 @@
 
 # shortcut methods are not supported by default
 # since they have been excluded from DB API 2
-# and are not recommended by the DB SIG;
+# and are not recommended by the DB SIG.
 
 shortcutmethods = 0
 
@@ -286,23 +286,23 @@
             params = tuple(map(self._quote, params))
         return string % params
 
+    @staticmethod
     def row_factory(row):
         """Process rows before they are returned.
 
         You can overwrite this with a custom row factory,
         e.g. a dict factory:
 
-        class myCursor(pgdb.pgdbCursor):
-            def cursor.row_factory(self, row):
-                d = {}
-                for idx, col in enumerate(self.description):
-                    d[col[0]] = row[idx]
-                return d
-        cursor = myCursor(cnx)
+            class DictCursor(pgdb.pgdbCursor):
+
+                def row_factory(self, row):
+                    return {desc[0]:value
+                        for desc, value in zip(self.description, row)}
+
+            cur = DictCursor(con)
 
         """
         return row
-    row_factory = staticmethod(row_factory)
 
     def close(self):
         """Close the cursor object."""
@@ -428,15 +428,15 @@
         """Not supported."""
         raise NotSupportedError("nextset() is not supported")
 
+    @staticmethod
     def setinputsizes(sizes):
         """Not supported."""
         pass  # unsupported, but silently passed
-    setinputsizes = staticmethod(setinputsizes)
 
+    @staticmethod
     def setoutputsize(size, column=0):
         """Not supported."""
         pass  # unsupported, but silently passed
-    setoutputsize = staticmethod(setoutputsize)
 
 
 ### Connection Objects
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql

Reply via email to