Replace ternary statements with condition and 'then' or 'else'

This commit is contained in:
Daniel Neuhäuser 2011-01-08 19:55:47 +01:00
parent a2919aab47
commit 87ceced3b6
3 changed files with 5 additions and 5 deletions

View File

@ -104,9 +104,9 @@ class BaseSearch(object):
return ''
context_start = max(res.start() - length/2, 0)
context_end = context_start + length
context = ''.join(['...' if context_start > 0 else '',
context = ''.join([context_start > 0 and '...' or '',
text[context_start:context_end],
'...' if context_end < len(text) else ''])
context_end < len(text) and '...' or ''])
try:
return unicode(context, errors='ignore')

View File

@ -62,9 +62,9 @@ class CombinedHtmlDiff(object):
return ''
if next is not None and next[0] == '?':
tag = 'ins' if prefix == '+' else 'del'
tag = prefix == '+' and 'ins' or 'del'
text = self._highlight_text(text, next, tag)
css_class = 'prop-added' if prefix == '+' else 'prop-removed'
css_class = prefix == '+' and 'prop-added' or 'prop-removed'
return '<span class="%s">%s</span>\n' % (css_class, text.rstrip())

View File

@ -45,7 +45,7 @@ class SQLAlchemyStorage(StorageBackend):
session = Session()
node = session.query(Node).filter(Node.id == id).first()
session.close()
return True if node else False
return bool(node)
def add_node(self, id, document, source):
node = Node(id, document, source)