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'],
}
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'
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
"""
def process_request(self, request):
def process_request(self, request): # pylint: disable=no-self-use
"""
Rewrites the proxy headers so that forwarded server is
used if available.

View File

@@ -2,32 +2,18 @@
Test our views in ivatar.ivataraccount.views and ivatar.views
'''
# pylint: disable=too-many-lines
from urllib.parse import urlsplit
from io import BytesIO
import io
import os
import django
from django.test import TestCase
from django.test import Client
from django.urls import reverse
from django.contrib.auth.models import User
from django.contrib.auth import authenticate
import hashlib
from libravatar import libravatar_url
from PIL import Image
from ivatar.utils import random_string
os.environ['DJANGO_SETTINGS_MODULE'] = 'ivatar.settings'
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
'''
@@ -77,4 +63,3 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods
"""
response = self.client.get(reverse('security'))
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
'''
# pylint: disable=too-many-lines
from urllib.parse import urlsplit
from io import BytesIO
import io
import os
import django
from django.test import TestCase
from django.test import Client
from django.urls import reverse
from django.contrib.auth.models import User
from django.contrib.auth import authenticate
import hashlib
from libravatar import libravatar_url
from PIL import Image
from ivatar.utils import random_string
os.environ['DJANGO_SETTINGS_MODULE'] = 'ivatar.settings'
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
'''

View File

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

View File

@@ -29,7 +29,8 @@ urlpatterns = [ # pylint: disable=invalid-name
GravatarProxyView.as_view(), name='gravatarproxy'),
url('description/', TemplateView.as_view(template_name='description.html'), name='description'),
# 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('security/', TemplateView.as_view(template_name='security.html'), name='security'),
url('privacy/', TemplateView.as_view(template_name='privacy.html'), name='privacy'),
@@ -39,10 +40,10 @@ urlpatterns = [ # pylint: disable=invalid-name
MAINTENANCE = False
try:
if settings.MAINTENANCE:
MAINTENANCE = True
except:
pass
if settings.MAINTENANCE:
MAINTENANCE = True
except: # pylint: disable=bare-except
pass
if MAINTENANCE:
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):
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:
caches['filesystem'].set(uri, {
'content': content,
@@ -66,7 +69,7 @@ class CachingHttpResponse(HttpResponse):
'reason': reason,
'charset': charset
})
return super().__init__(content, content_type, status, reason, charset)
super().__init__(content, content_type, status, reason, charset)
class AvatarImageView(TemplateView):
'''
@@ -74,7 +77,7 @@ class AvatarImageView(TemplateView):
'''
# 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['Allow'] = "404 mm mp retro pagan wavatar monsterid robohash identicon"
return response
@@ -137,7 +140,7 @@ class AvatarImageView(TemplateView):
except ObjectDoesNotExist:
model = ConfirmedOpenId
try:
d = kwargs['digest']
d = kwargs['digest'] # pylint: disable=invalid-name
# OpenID is tricky. http vs. https, versus trailing slash or not
# However, some users eventually have added their variations already
# and therfore we need to use filter() and first()
@@ -146,7 +149,7 @@ class AvatarImageView(TemplateView):
Q(alt_digest1=d) |
Q(alt_digest2=d) |
Q(alt_digest3=d)).first()
except:
except: # pylint: disable=bare-except
pass
@@ -212,7 +215,7 @@ class AvatarImageView(TemplateView):
img = img.resize((size, size), Image.ANTIALIAS)
img.save(data, 'PNG', quality=JPEG_QUALITY)
data.seek(0)
response = CachingHttpResponse(
response = CachingHttpResponse(
uri,
data,
content_type='image/png')
@@ -233,7 +236,7 @@ class AvatarImageView(TemplateView):
return response
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.
newdigest = hashlib.md5(bytes(kwargs['digest'], 'utf-8')).hexdigest()
img = p.draw(newdigest, size, 0)
@@ -306,7 +309,7 @@ class GravatarProxyView(View):
'''
# 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
'''
@@ -314,7 +317,7 @@ class GravatarProxyView(View):
url = reverse_lazy(
'avatar_view',
args=[kwargs['digest']]) + '?s=%i' % size + '&forcedefault=y'
if default != None:
if default is not None:
url += '&default=%s' % default
return HttpResponseRedirect(url)
@@ -325,7 +328,7 @@ class GravatarProxyView(View):
try:
if str(request.GET['default']) != 'None':
default = request.GET['default']
except:
except: # pylint: disable=bare-except
pass
if str(default) != 'wavatar':
@@ -344,7 +347,7 @@ class GravatarProxyView(View):
if hashlib.md5(data.read()).hexdigest() == '71bc262d627971d13fe6f3180b93062a':
cache.set(gravatar_test_url, 'default', 60)
return redir_default(default)
except Exception as exc:
except Exception as exc: # pylint: disable=broad-except
print('Gravatar test url fetch failed: %s' % exc)
gravatar_url = 'https://secure.gravatar.com/avatar/' + kwargs['digest'] \