Changeset 678


Ignore:
Timestamp:
Dec 30, 2015, 4:01:53 PM (4 years ago)
Author:
cito
Message:

More elegant code using decorators and dict comprehension

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/module/pgdb.py

    r629 r678  
    104104# shortcut methods are not supported by default
    105105# since they have been excluded from DB API 2
    106 # and are not recommended by the DB SIG;
     106# and are not recommended by the DB SIG.
    107107
    108108shortcutmethods = 0
     
    287287        return string % params
    288288
     289    @staticmethod
    289290    def row_factory(row):
    290291        """Process rows before they are returned.
     
    293294        e.g. a dict factory:
    294295
    295         class myCursor(pgdb.pgdbCursor):
    296             def cursor.row_factory(self, row):
    297                 d = {}
    298                 for idx, col in enumerate(self.description):
    299                     d[col[0]] = row[idx]
    300                 return d
    301         cursor = myCursor(cnx)
     296            class DictCursor(pgdb.pgdbCursor):
     297
     298                def row_factory(self, row):
     299                    return {desc[0]:value
     300                        for desc, value in zip(self.description, row)}
     301
     302            cur = DictCursor(con)
    302303
    303304        """
    304305        return row
    305     row_factory = staticmethod(row_factory)
    306306
    307307    def close(self):
     
    429429        raise NotSupportedError("nextset() is not supported")
    430430
     431    @staticmethod
    431432    def setinputsizes(sizes):
    432433        """Not supported."""
    433434        pass  # unsupported, but silently passed
    434     setinputsizes = staticmethod(setinputsizes)
    435 
     435
     436    @staticmethod
    436437    def setoutputsize(size, column=0):
    437438        """Not supported."""
    438439        pass  # unsupported, but silently passed
    439     setoutputsize = staticmethod(setoutputsize)
    440440
    441441
Note: See TracChangeset for help on using the changeset viewer.