Remove <cond> and <val1> or <val2> systax

Use <val1> if <cond> else <val2> instead.
There're more talks:
[0] http://stackoverflow.com/questions/394809/ternary-conditional-operator-in-python
[1] http://www.python.org/dev/peps/pep-0308/

Fixes bug 1188111

Change-Id: I485e674317faf319a26ab30c2c193d8464a7e46e
This commit is contained in:
Kun Huang 2013-06-06 17:59:31 +08:00
parent 63a5a93734
commit 157f61651e
3 changed files with 4 additions and 4 deletions

View File

@ -86,7 +86,7 @@ class GreenDBConnection(sqlite3.Connection):
def __init__(self, *args, **kwargs):
self.timeout = kwargs.get('timeout', BROKER_TIMEOUT)
kwargs['timeout'] = 0
self.db_file = args and args[0] or '-'
self.db_file = args[0] if args else'-'
sqlite3.Connection.__init__(self, *args, **kwargs)
def _timeout(self, call):
@ -591,7 +591,7 @@ class DatabaseBroker(object):
try:
md = conn.execute('SELECT metadata FROM %s_stat' %
self.db_type).fetchone()[0]
md = md and json.loads(md) or {}
md = json.loads(md) if md else {}
utf8encodekeys(md)
except sqlite3.OperationalError, err:
if 'no such column: metadata' not in str(err):

View File

@ -110,7 +110,7 @@ def clean_acl(name, value):
raise ValueError('No host/domain value after referrer '
'designation in ACL: %s' %
repr(raw_value))
values.append('.r:%s%s' % (negate and '-' or '', second))
values.append('.r:%s%s' % ('-' if negate else '', second))
else:
raise ValueError('Unknown designator %s in ACL: %s' %
(repr(first), repr(raw_value)))

View File

@ -979,7 +979,7 @@ class ObjectController(Controller):
self.app.logger.error(
_('Object servers returned %s mismatched etags'), len(etags))
return HTTPServerError(request=req)
etag = len(etags) and etags.pop() or None
etag = etags.pop() if len(etags) else None
while len(statuses) < len(nodes):
statuses.append(HTTP_SERVICE_UNAVAILABLE)
reasons.append('')