Commit 9879ab6b authored by Michal Čihař's avatar Michal Čihař

PEP-8 fixes

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent c8bc55b3
......@@ -129,8 +129,8 @@ def performance(request):
checks.append((
_('Email addresses'),
(
settings.SERVER_EMAIL not in default_mails
and settings.DEFAULT_FROM_EMAIL not in default_mails
settings.SERVER_EMAIL not in default_mails and
settings.DEFAULT_FROM_EMAIL not in default_mails
),
'production-email',
))
......
......@@ -90,8 +90,8 @@ class Check(object):
except IndexError:
return False
return (
(src in chars and tgt not in chars)
or (src not in chars and tgt in chars)
(src in chars and tgt not in chars) or
(src not in chars and tgt in chars)
)
def is_language(self, unit, vals):
......
......@@ -1026,9 +1026,9 @@ class SameCheck(TargetCheck):
lower_source = source.lower()
# Check special things like 1:4 1/2 or copyright
if (len(source.strip('0123456789:/,.')) <= 1
or '(c) copyright' in lower_source
or u'©' in source):
if (len(source.strip('0123456789:/,.')) <= 1 or
'(c) copyright' in lower_source or
u'©' in source):
result = True
else:
# Strip format strings
......
......@@ -34,14 +34,14 @@ class WeblateExceptionReporterFilter(SafeExceptionReporterFilter):
request
)
if (hasattr(request, 'session')
and 'django_language' in request.session):
if (hasattr(request, 'session') and
'django_language' in request.session):
lang = request.session['django_language']
else:
lang = None
if (hasattr(request, 'user')
and request.user.is_authenticated()):
if (hasattr(request, 'user') and
request.user.is_authenticated()):
user = repr(request.user.username)
else:
user = None
......
......@@ -100,10 +100,10 @@ class FileUnit(object):
'''
# XLIFF and PHP are special in ttkit - it uses locations for what
# is context in other formats
if (isinstance(self.mainunit, xliffunit)
or isinstance(self.mainunit, javafile)
or isinstance(self.mainunit, javautf8file)
or isinstance(self.mainunit, phpunit)):
if (isinstance(self.mainunit, xliffunit) or
isinstance(self.mainunit, javafile) or
isinstance(self.mainunit, javautf8file) or
isinstance(self.mainunit, phpunit)):
return ''
result = ', '.join(self.mainunit.getlocations())
# Do not try to handle relative locations in Qt TS, see
......@@ -165,18 +165,18 @@ class FileUnit(object):
reason do not correctly set source/target attributes.
'''
return (
hasattr(self.mainunit, 'name')
and hasattr(self.mainunit, 'value')
and hasattr(self.mainunit, 'translation')
hasattr(self.mainunit, 'name') and
hasattr(self.mainunit, 'value') and
hasattr(self.mainunit, 'translation')
)
def get_source(self):
'''
Returns source string from a ttkit unit.
'''
if (isinstance(self.mainunit, tsunit)
and self.template is None
and self.mainunit.hasplural()):
if (isinstance(self.mainunit, tsunit) and
self.template is None and
self.mainunit.hasplural()):
# Need to apply special magic for plurals here
# as there is no singlular/plural in the source string
return join_plural([
......@@ -208,9 +208,9 @@ class FileUnit(object):
'''
if self.unit is None:
return ''
if (isinstance(self.unit, tsunit)
and not self.unit.isreview()
and not self.unit.istranslated()):
if (isinstance(self.unit, tsunit) and
not self.unit.isreview() and
not self.unit.istranslated()):
# For Qt ts, empty translated string means source should be used
return self.get_source()
if self.is_unit_key_value():
......@@ -239,8 +239,8 @@ class FileUnit(object):
return ''
else:
return context[0]
elif (isinstance(self.mainunit, (pounit, JsonUnit))
and self.template is not None):
elif (isinstance(self.mainunit, (pounit, JsonUnit)) and
self.template is not None):
# Monolingual JSON files
return self.template.getid()
else:
......@@ -370,8 +370,8 @@ class FileFormat(object):
'''
# Workaround for _ created by interactive interpreter and
# later used instead of gettext by ttkit
if ('_' in __builtin__.__dict__
and not callable(__builtin__.__dict__['_'])):
if ('_' in __builtin__.__dict__ and
not callable(__builtin__.__dict__['_'])):
del __builtin__.__dict__['_']
# Add missing mode attribute to Django file wrapper
......@@ -421,8 +421,8 @@ class FileFormat(object):
# Remember template
self.template_store = template_store
# Set language (needed for some which do not include this)
if (language_code is not None
and self.store.gettargetlanguage() is None):
if (language_code is not None and
self.store.gettargetlanguage() is None):
self.store.settargetlanguage(language_code)
@property
......@@ -431,8 +431,8 @@ class FileFormat(object):
Checks whether class is using template.
'''
return (
(self.monolingual or self.monolingual is None)
and self.template_store is not None
(self.monolingual or self.monolingual is None) and
self.template_store is not None
)
def _find_unit_template(self, context):
......@@ -518,9 +518,9 @@ class FileFormat(object):
# Adjust Content-Type header if needed
header = self.store.parseheader()
if ('Content-Type' not in header
or 'charset=CHARSET' in header['Content-Type']
or 'charset=ASCII' in header['Content-Type']):
if ('Content-Type' not in header or
'charset=CHARSET' in header['Content-Type'] or
'charset=ASCII' in header['Content-Type']):
kwargs['Content_Type'] = 'text/plain; charset=UTF-8'
self.store.updateheader(**kwargs)
......
......@@ -462,11 +462,11 @@ class SearchForm(forms.Form):
cleaned_data['type'] = 'all'
# Default to source and target search
if (not cleaned_data['source']
and not cleaned_data['target']
and not cleaned_data['location']
and not cleaned_data['comment']
and not cleaned_data['context']):
if (not cleaned_data['source'] and
not cleaned_data['target'] and
not cleaned_data['location'] and
not cleaned_data['comment'] and
not cleaned_data['context']):
cleaned_data['source'] = True
cleaned_data['target'] = True
......
......@@ -35,8 +35,8 @@ def microsoft_translation_supported():
Checks whether service is supported.
'''
return (
appsettings.MT_MICROSOFT_ID is not None
and appsettings.MT_MICROSOFT_SECRET is not None
appsettings.MT_MICROSOFT_ID is not None and
appsettings.MT_MICROSOFT_SECRET is not None
)
......
......@@ -629,10 +629,10 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
self.create_translations(request=request)
# Push after possible merge
if (self.git_needs_push()
and ret
and self.project.push_on_commit
and self.can_push()):
if (self.git_needs_push() and
ret and
self.project.push_on_commit and
self.can_push()):
self.do_push(request, force_commit=False, do_update=False)
return ret
......@@ -874,8 +874,8 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
if len(parts) == 1:
return 'INVALID'
# Assume English language for template if we can not parse it
if ((not path.startswith(parts[0]) or not path.endswith(parts[1]))
and path == self.template):
if ((not path.startswith(parts[0]) or not path.endswith(parts[1])) and
path == self.template):
return 'en'
# Get part matching to first wildcard
if len(parts[1]) == 0:
......@@ -1151,13 +1151,13 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
if self.id:
old = SubProject.objects.get(pk=self.id)
changed_git = (
(old.repo != self.repo)
or (old.branch != self.branch)
or (old.filemask != self.filemask)
(old.repo != self.repo) or
(old.branch != self.branch) or
(old.filemask != self.filemask)
)
changed_setup = (
(old.file_format != self.file_format)
or (old.template != self.template)
(old.file_format != self.file_format) or
(old.template != self.template)
)
# Detect slug changes and rename git repo
self.check_rename(old)
......@@ -1219,8 +1219,8 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
'''
Returns file format object.
'''
if (self._file_format is None
or self._file_format.name != self.file_format):
if (self._file_format is None or
self._file_format.name != self.file_format):
self._file_format = FILE_FORMATS[self.file_format]
return self._file_format
......@@ -1230,9 +1230,9 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
'''
monolingual = self.file_format_cls.monolingual
return (
(monolingual or monolingual is None)
and len(self.template) > 0
and not self.template.endswith('.pot')
(monolingual or monolingual is None) and
len(self.template) > 0 and
not self.template.endswith('.pot')
)
def load_template_store(self):
......@@ -1277,8 +1277,8 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
'''
if self._all_flags is None:
self._all_flags = (
self.check_flags.split(',')
+ list(self.file_format_cls.check_flags)
self.check_flags.split(',') +
list(self.file_format_cls.check_flags)
)
return self._all_flags
......
......@@ -495,13 +495,13 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
# Check if unit is new and untranslated
was_new = (
was_new
or (is_new and not newunit.translated)
or (
not newunit.translated
and newunit.translated != newunit.old_translated
)
or (newunit.fuzzy and newunit.fuzzy != newunit.old_fuzzy)
was_new or
(is_new and not newunit.translated) or
(
not newunit.translated and
newunit.translated != newunit.old_translated
) or
(newunit.fuzzy and newunit.fuzzy != newunit.old_fuzzy)
)
# Update position
......@@ -831,9 +831,9 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
self.__git_commit(author, timestamp, sync)
# Push if we should
if (self.subproject.project.push_on_commit
and not skip_push
and self.can_push()):
if (self.subproject.project.push_on_commit and
not skip_push and
self.can_push()):
self.subproject.do_push(request, force_commit=False)
return True
......@@ -857,9 +857,9 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return False, None
# Check for changes
if (not add
and unit.target == pounit.get_target()
and unit.fuzzy == pounit.is_fuzzy()):
if (not add and
unit.target == pounit.get_target() and
unit.fuzzy == pounit.is_fuzzy()):
return False, pounit
# Store translations
......@@ -880,8 +880,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
# Update po file header
po_revision_date = (
datetime.now().strftime('%Y-%m-%d %H:%M')
+ poheader.tzstring()
datetime.now().strftime('%Y-%m-%d %H:%M') + poheader.tzstring()
)
# Prepare headers to update
......
......@@ -385,13 +385,12 @@ class Unit(models.Model):
# Update checks on fuzzy update or on content change
same_content = (
target == self.target
and source == self.source
target == self.target and source == self.source
)
same_state = (
fuzzy == self.fuzzy
and translated == self.translated
and not created
fuzzy == self.fuzzy and
translated == self.translated and
not created
)
# Check if we actually need to change anything
......@@ -542,9 +541,9 @@ class Unit(models.Model):
# Return if there was no change
# We have to explicitly check for fuzzy flag change on monolingual
# files, where we handle it ourselves without storing to backend
if (not saved
and oldunit.fuzzy == self.fuzzy
and oldunit.target == self.target):
if (not saved and
oldunit.fuzzy == self.fuzzy and
oldunit.target == self.target):
# Propagate if we should
if propagate:
self.propagate(request, change_action)
......@@ -576,8 +575,8 @@ class Unit(models.Model):
self.generate_change(request, user, oldunit, change_action)
# Force commiting on completing translation
if (old_translated < self.translation.translated
and self.translation.translated == self.translation.total):
if (old_translated < self.translation.translated and
self.translation.translated == self.translation.total):
self.translation.commit_pending(request)
Change.objects.create(
translation=self.translation,
......@@ -962,8 +961,8 @@ class Unit(models.Model):
Whether we can vote for suggestions.
"""
return (
self.translation.subproject.suggestion_voting
and self.translation.subproject.suggestion_autoaccept > 0
self.translation.subproject.suggestion_voting and
self.translation.subproject.suggestion_autoaccept > 0
)
def translate(self, request, new_target, new_fuzzy):
......@@ -984,9 +983,9 @@ class Unit(models.Model):
"""
if self._all_flags is None:
self._all_flags = set(
self.flags.split(',')
+ self.source_info.check_flags.split(',')
+ self.translation.subproject.all_flags
self.flags.split(',') +
self.source_info.check_flags.split(',') +
self.translation.subproject.all_flags
)
self._all_flags.discard('')
return self._all_flags
......
......@@ -71,9 +71,9 @@ def is_key_line(key):
if key[0] == '#':
return False
return (
' ssh-rsa ' in key
or ' ecdsa-sha2-nistp256 ' in key
or ' ssh-ed25519 ' in key
' ssh-rsa ' in key or
' ecdsa-sha2-nistp256 ' in key or
' ssh-ed25519 ' in key
)
......
......@@ -55,8 +55,8 @@ class SeleniumTests(LiveServerTestCase, RegistrationTestMixin):
if DO_SELENIUM:
self.set_test_status(
errors == len(result.errors)
and failures == len(result.failures)
errors == len(result.errors) and
failures == len(result.failures)
)
@classmethod
......
......@@ -360,8 +360,8 @@ class GitRepository(Repository):
Checks whether this is a valid repository.
'''
return (
os.path.exists(os.path.join(self.path, '.git', 'config'))
or os.path.exists(os.path.join(self.path, 'config'))
os.path.exists(os.path.join(self.path, '.git', 'config')) or
os.path.exists(os.path.join(self.path, 'config'))
)
def init(self):
......@@ -677,8 +677,8 @@ class HgRepository(Repository):
config.read(filename)
if not config.has_section(section):
config.add_section(section)
if (config.has_option(section, key)
and config.get(section, key) == value):
if (config.has_option(section, key) and
config.get(section, key) == value):
return
config.set(section, key, value)
with open(filename, 'wb') as handle:
......
......@@ -285,8 +285,8 @@ def show_dictionary(request, project, lang):
prj = get_project(request, project)
lang = get_object_or_404(Language, code=lang)
if (request.method == 'POST'
and request.user.has_perm('trans.add_dictionary')):
if (request.method == 'POST' and
request.user.has_perm('trans.add_dictionary')):
form = WordForm(request.POST)
if form.is_valid():
Dictionary.objects.create(
......
......@@ -164,8 +164,8 @@ class Widget(object):
(
self.progress['x'],
self.progress['y'],
self.progress['x']
+ self.progress['width'] / 100.0 * self.percent,
self.progress['x'] +
self.progress['width'] / 100.0 * self.percent,
self.progress['y'] + self.progress['height']
),
fill=COLOR_DATA[self.color]['bar'],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment