Changeset 622 for trunk


Ignore:
Timestamp:
Nov 25, 2015, 7:25:24 AM (4 years ago)
Author:
cito
Message:

Use the ternary operator in modern Python

Since we require Python 2.6, we can and should use modern syntax
that makes the code a little easier to read.

Location:
trunk/module
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/module/pg.py

    r621 r622  
    197197            db = self.db
    198198        if self.listening:
    199             q = 'notify "%s"' % (stop and self.stop_event or self.event)
     199            q = 'notify "%s"' % (self.stop_event if stop else self.event)
    200200            if payload:
    201201                q += ", '%s'" % payload
     
    561561            # make sure that all classes have a namespace
    562562            self._pkeys = dict([
    563                 ('.' in cl and cl or 'public.' + cl, pkey)
     563                (cl if '.' in cl else 'public.' + cl, pkey)
    564564                for cl, pkey in newpkey.items()])
    565565            return self._pkeys
     
    596596            # (only) for composite primary keys, the values will be frozensets
    597597            for cl, pkey in self._pkeys.items():
    598                 self._pkeys[cl] = len(pkey) > 1 and frozenset(pkey) or pkey[0]
     598                self._pkeys[cl] = frozenset(pkey) if len(pkey) > 1 else pkey[0]
    599599            self._do_debug(self._pkeys)
    600600
     
    774774            raise _db_error('No such record in %s where %s' % (qcl, where))
    775775        for att, value in res[0].items():
    776             arg[att == 'oid' and qoid or att] = value
     776            arg[qoid if att == 'oid' else att] = value
    777777        return arg
    778778
     
    805805        selectable = self.has_table_privilege(qcl)
    806806        if selectable and self.server_version >= 80200:
    807             ret = ' RETURNING %s*' % ('oid' in attnames and 'oid, ' or '')
     807            ret = ' RETURNING %s*' % ('oid, ' if 'oid' in attnames else '')
    808808        else:
    809809            ret = ''
     
    814814            res = res.dictresult()
    815815            for att, value in res[0].items():
    816                 d[att == 'oid' and qoid or att] = value
     816                d[qoid if att == 'oid' else att] = value
    817817        elif isinstance(res, int):
    818818            d[qoid] = res
     
    875875        selectable = self.has_table_privilege(qcl)
    876876        if selectable and self.server_version >= 880200:
    877             ret = ' RETURNING %s*' % ('oid' in attnames and 'oid, ' or '')
     877            ret = ' RETURNING %s*' % ('oid, ' if 'oid' in attnames else '')
    878878        else:
    879879            ret = ''
     
    884884            res = res.dictresult()[0]
    885885            for att, value in res.items():
    886                 d[att == 'oid' and qoid or att] = value
     886                d[qoid if att == 'oid' else att] = value
    887887        else:
    888888            if selectable:
  • trunk/module/pgdb.py

    r601 r622  
    251251        elif isinstance(val, float):
    252252            if isinf(val):
    253                 return val < 0 and "'-Infinity'" or "'Infinity'"
     253                return "'-Infinity'" if val < 0 else "'Infinity'"
    254254            elif isnan(val):
    255255                return "'NaN'"
Note: See TracChangeset for help on using the changeset viewer.