Make pylint happier

This commit is contained in:
Oliver Falk
2020-09-29 13:58:39 +02:00
parent b4b81499ca
commit 92035d7e15
7 changed files with 25 additions and 51 deletions

View File

@@ -108,7 +108,7 @@ else:
'MAILGUN_SENDER_DOMAIN': os.environ['IVATAR_MAILGUN_SENDER_DOMAIN'], 'MAILGUN_SENDER_DOMAIN': os.environ['IVATAR_MAILGUN_SENDER_DOMAIN'],
} }
EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend' # pragma: no cover EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend' # pragma: no cover
except Exception as exc: except Exception as exc: # pragma: nocover
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
SERVER_EMAIL = os.environ.get('SERVER_EMAIL', 'ivatar@mg.linux-kernel.at') SERVER_EMAIL = os.environ.get('SERVER_EMAIL', 'ivatar@mg.linux-kernel.at')

View File

@@ -9,7 +9,7 @@ class MultipleProxyMiddleware(MiddlewareMixin): # pylint: disable=too-few-publi
with multiple proxies with multiple proxies
""" """
def process_request(self, request): def process_request(self, request): # pylint: disable=no-self-use
""" """
Rewrites the proxy headers so that forwarded server is Rewrites the proxy headers so that forwarded server is
used if available. used if available.

View File

@@ -2,32 +2,18 @@
Test our views in ivatar.ivataraccount.views and ivatar.views Test our views in ivatar.ivataraccount.views and ivatar.views
''' '''
# pylint: disable=too-many-lines # pylint: disable=too-many-lines
from urllib.parse import urlsplit
from io import BytesIO
import io
import os import os
import django import django
from django.test import TestCase from django.test import TestCase
from django.test import Client from django.test import Client
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.auth import authenticate
import hashlib
from libravatar import libravatar_url from ivatar.utils import random_string
from PIL import Image
os.environ['DJANGO_SETTINGS_MODULE'] = 'ivatar.settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'ivatar.settings'
django.setup() django.setup()
# pylint: disable=wrong-import-position
from ivatar import settings
from ivatar.ivataraccount.forms import MAX_NUM_UNCONFIRMED_EMAILS_DEFAULT
from ivatar.ivataraccount.models import Photo, ConfirmedOpenId
from ivatar.utils import random_string
# pylint: enable=wrong-import-position
class Tester(TestCase): # pylint: disable=too-many-public-methods class Tester(TestCase): # pylint: disable=too-many-public-methods
''' '''
@@ -77,4 +63,3 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods
""" """
response = self.client.get(reverse('security')) response = self.client.get(reverse('security'))
self.assertEqual(response.status_code, 200, 'no 200 ok?') self.assertEqual(response.status_code, 200, 'no 200 ok?')

View File

@@ -2,32 +2,17 @@
Test our views in ivatar.ivataraccount.views and ivatar.views Test our views in ivatar.ivataraccount.views and ivatar.views
''' '''
# pylint: disable=too-many-lines # pylint: disable=too-many-lines
from urllib.parse import urlsplit
from io import BytesIO
import io
import os import os
import django import django
from django.test import TestCase from django.test import TestCase
from django.test import Client from django.test import Client
from django.urls import reverse
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.auth import authenticate
import hashlib
from libravatar import libravatar_url from ivatar.utils import random_string
from PIL import Image
os.environ['DJANGO_SETTINGS_MODULE'] = 'ivatar.settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'ivatar.settings'
django.setup() django.setup()
# pylint: disable=wrong-import-position
from ivatar import settings
from ivatar.ivataraccount.forms import MAX_NUM_UNCONFIRMED_EMAILS_DEFAULT
from ivatar.ivataraccount.models import Photo, ConfirmedOpenId
from ivatar.utils import random_string
# pylint: enable=wrong-import-position
class Tester(TestCase): # pylint: disable=too-many-public-methods class Tester(TestCase): # pylint: disable=too-many-public-methods
''' '''

View File

@@ -17,6 +17,6 @@ class TestCase(unittest.TestCase):
''' '''
Run wsgi import Run wsgi import
''' '''
import ivatar.wsgi import ivatar.wsgi # pylint: disable=import-outside-toplevel
self.assertEqual(ivatar.wsgi.application.__class__, self.assertEqual(ivatar.wsgi.application.__class__,
django.core.handlers.wsgi.WSGIHandler) django.core.handlers.wsgi.WSGIHandler)

View File

@@ -29,7 +29,8 @@ urlpatterns = [ # pylint: disable=invalid-name
GravatarProxyView.as_view(), name='gravatarproxy'), GravatarProxyView.as_view(), name='gravatarproxy'),
url('description/', TemplateView.as_view(template_name='description.html'), name='description'), url('description/', TemplateView.as_view(template_name='description.html'), name='description'),
# The following two are TODO TODO TODO TODO TODO # The following two are TODO TODO TODO TODO TODO
url('run_your_own/', TemplateView.as_view(template_name='run_your_own.html'), name='run_your_own'), url('run_your_own/',
TemplateView.as_view(template_name='run_your_own.html'), name='run_your_own'),
url('features/', TemplateView.as_view(template_name='features.html'), name='features'), url('features/', TemplateView.as_view(template_name='features.html'), name='features'),
url('security/', TemplateView.as_view(template_name='security.html'), name='security'), url('security/', TemplateView.as_view(template_name='security.html'), name='security'),
url('privacy/', TemplateView.as_view(template_name='privacy.html'), name='privacy'), url('privacy/', TemplateView.as_view(template_name='privacy.html'), name='privacy'),
@@ -39,10 +40,10 @@ urlpatterns = [ # pylint: disable=invalid-name
MAINTENANCE = False MAINTENANCE = False
try: try:
if settings.MAINTENANCE: if settings.MAINTENANCE:
MAINTENANCE = True MAINTENANCE = True
except: except: # pylint: disable=bare-except
pass pass
if MAINTENANCE: if MAINTENANCE:
urlpatterns.append(url('', TemplateView.as_view(template_name='maintenance.html'), name='home')) urlpatterns.append(url('', TemplateView.as_view(template_name='maintenance.html'), name='home'))

View File

@@ -57,7 +57,10 @@ def get_size(request, size=DEFAULT_AVATAR_SIZE):
class CachingHttpResponse(HttpResponse): class CachingHttpResponse(HttpResponse):
def __init__(self, uri, content=b'', content_type=None, status=200, reason=None, charset=None): '''
Handle caching of response
'''
def __init__(self, uri, content=b'', content_type=None, status=200, reason=None, charset=None): # pylint: disable=too-many-arguments
if CACHE_RESPONSE: if CACHE_RESPONSE:
caches['filesystem'].set(uri, { caches['filesystem'].set(uri, {
'content': content, 'content': content,
@@ -66,7 +69,7 @@ class CachingHttpResponse(HttpResponse):
'reason': reason, 'reason': reason,
'charset': charset 'charset': charset
}) })
return super().__init__(content, content_type, status, reason, charset) super().__init__(content, content_type, status, reason, charset)
class AvatarImageView(TemplateView): class AvatarImageView(TemplateView):
''' '''
@@ -74,7 +77,7 @@ class AvatarImageView(TemplateView):
''' '''
# TODO: Do cache resize images!! Memcached? # TODO: Do cache resize images!! Memcached?
def options(self, request, *args, **kwargs): # pylint: disable=too-many-branches,too-many-statements,too-many-locals,too-many-return-statements def options(self, request, *args, **kwargs):
response = HttpResponse("", content_type='text/plain') response = HttpResponse("", content_type='text/plain')
response['Allow'] = "404 mm mp retro pagan wavatar monsterid robohash identicon" response['Allow'] = "404 mm mp retro pagan wavatar monsterid robohash identicon"
return response return response
@@ -137,7 +140,7 @@ class AvatarImageView(TemplateView):
except ObjectDoesNotExist: except ObjectDoesNotExist:
model = ConfirmedOpenId model = ConfirmedOpenId
try: try:
d = kwargs['digest'] d = kwargs['digest'] # pylint: disable=invalid-name
# OpenID is tricky. http vs. https, versus trailing slash or not # OpenID is tricky. http vs. https, versus trailing slash or not
# However, some users eventually have added their variations already # However, some users eventually have added their variations already
# and therfore we need to use filter() and first() # and therfore we need to use filter() and first()
@@ -146,7 +149,7 @@ class AvatarImageView(TemplateView):
Q(alt_digest1=d) | Q(alt_digest1=d) |
Q(alt_digest2=d) | Q(alt_digest2=d) |
Q(alt_digest3=d)).first() Q(alt_digest3=d)).first()
except: except: # pylint: disable=bare-except
pass pass
@@ -212,7 +215,7 @@ class AvatarImageView(TemplateView):
img = img.resize((size, size), Image.ANTIALIAS) img = img.resize((size, size), Image.ANTIALIAS)
img.save(data, 'PNG', quality=JPEG_QUALITY) img.save(data, 'PNG', quality=JPEG_QUALITY)
data.seek(0) data.seek(0)
response = CachingHttpResponse( response = CachingHttpResponse(
uri, uri,
data, data,
content_type='image/png') content_type='image/png')
@@ -233,7 +236,7 @@ class AvatarImageView(TemplateView):
return response return response
if str(default) == 'identicon': if str(default) == 'identicon':
p = Pydenticon5() p = Pydenticon5() # pylint: disable=invalid-name
# In order to make use of the whole 32 bytes digest, we need to redigest them. # In order to make use of the whole 32 bytes digest, we need to redigest them.
newdigest = hashlib.md5(bytes(kwargs['digest'], 'utf-8')).hexdigest() newdigest = hashlib.md5(bytes(kwargs['digest'], 'utf-8')).hexdigest()
img = p.draw(newdigest, size, 0) img = p.draw(newdigest, size, 0)
@@ -306,7 +309,7 @@ class GravatarProxyView(View):
''' '''
# TODO: Do cache images!! Memcached? # TODO: Do cache images!! Memcached?
def get(self, request, *args, **kwargs): # pylint: disable=too-many-branches,too-many-statements,too-many-locals,no-self-use,unused-argument def get(self, request, *args, **kwargs): # pylint: disable=too-many-branches,too-many-statements,too-many-locals,no-self-use,unused-argument,too-many-return-statements
''' '''
Override get from parent class Override get from parent class
''' '''
@@ -314,7 +317,7 @@ class GravatarProxyView(View):
url = reverse_lazy( url = reverse_lazy(
'avatar_view', 'avatar_view',
args=[kwargs['digest']]) + '?s=%i' % size + '&forcedefault=y' args=[kwargs['digest']]) + '?s=%i' % size + '&forcedefault=y'
if default != None: if default is not None:
url += '&default=%s' % default url += '&default=%s' % default
return HttpResponseRedirect(url) return HttpResponseRedirect(url)
@@ -325,7 +328,7 @@ class GravatarProxyView(View):
try: try:
if str(request.GET['default']) != 'None': if str(request.GET['default']) != 'None':
default = request.GET['default'] default = request.GET['default']
except: except: # pylint: disable=bare-except
pass pass
if str(default) != 'wavatar': if str(default) != 'wavatar':
@@ -344,7 +347,7 @@ class GravatarProxyView(View):
if hashlib.md5(data.read()).hexdigest() == '71bc262d627971d13fe6f3180b93062a': if hashlib.md5(data.read()).hexdigest() == '71bc262d627971d13fe6f3180b93062a':
cache.set(gravatar_test_url, 'default', 60) cache.set(gravatar_test_url, 'default', 60)
return redir_default(default) return redir_default(default)
except Exception as exc: except Exception as exc: # pylint: disable=broad-except
print('Gravatar test url fetch failed: %s' % exc) print('Gravatar test url fetch failed: %s' % exc)
gravatar_url = 'https://secure.gravatar.com/avatar/' + kwargs['digest'] \ gravatar_url = 'https://secure.gravatar.com/avatar/' + kwargs['digest'] \