diff options
author | Theo Chatzimichos <tampakrap@gentoo.org> | 2013-07-09 12:26:56 +0200 |
---|---|---|
committer | Theo Chatzimichos <tampakrap@gentoo.org> | 2013-07-09 12:26:56 +0200 |
commit | 0025e12f1f9376c10217605540ef1b0f6c876235 (patch) | |
tree | 0bed7ee3cc9793ee63c83956f01475216166d3d4 | |
parent | Merge pull request #21 from tampakrap/pep8_v3 (diff) | |
download | identity.gentoo.org-0025e12f1f9376c10217605540ef1b0f6c876235.tar.gz identity.gentoo.org-0025e12f1f9376c10217605540ef1b0f6c876235.tar.bz2 identity.gentoo.org-0025e12f1f9376c10217605540ef1b0f6c876235.zip |
Fix all pep8 issues apart from:
1) tests/*
2) settings/*
3) urls.py
./okupy/urls.py:7:5: E128 continuation line under-indented for visual indent
./okupy/accounts/urls.py:9:5: E128 continuation line under-indented for visual indent
4) setup.py
./setup.py:14:80: E501 line too long (85 characters)
./setup.py:23:80: E501 line too long (93 characters)
./setup.py:32:80: E501 line too long (81 characters)
-rw-r--r-- | okupy/__init__.py | 2 | ||||
-rw-r--r-- | okupy/accounts/forms.py | 21 | ||||
-rw-r--r-- | okupy/accounts/models.py | 25 | ||||
-rw-r--r-- | okupy/accounts/openid_store.py | 51 | ||||
-rw-r--r-- | okupy/accounts/urls.py | 5 | ||||
-rw-r--r-- | okupy/common/exceptions.py | 1 | ||||
-rw-r--r-- | okupy/common/log.py | 7 | ||||
-rw-r--r-- | okupy/common/testcase.py | 18 | ||||
-rw-r--r-- | okupy/tests/__init__.py | 2 | ||||
-rw-r--r-- | okupy/tests/tests.py | 6 |
10 files changed, 80 insertions, 58 deletions
diff --git a/okupy/__init__.py b/okupy/__init__.py index 52234b5..7e9bacb 100644 --- a/okupy/__init__.py +++ b/okupy/__init__.py @@ -1,4 +1,6 @@ # vim:fileencoding=utf8:et:ts=4:sts=4:sw=4:ft=python + + def get_package_version(): return '0.0.1-dev' diff --git a/okupy/accounts/forms.py b/okupy/accounts/forms.py index 2d66246..8ca2ea9 100644 --- a/okupy/accounts/forms.py +++ b/okupy/accounts/forms.py @@ -2,14 +2,19 @@ from django import forms + class LoginForm(forms.Form): - username = forms.CharField(max_length = 100, label = 'Username:') - password = forms.CharField(max_length = 30, widget = forms.PasswordInput(), label = 'Password:') + username = forms.CharField(max_length=100, label='Username:') + password = forms.CharField(max_length=30, widget=forms.PasswordInput(), + label='Password:') + class SignupForm(forms.Form): - first_name = forms.CharField(max_length = 100, label = 'First Name:') - last_name = forms.CharField(max_length = 100, label = 'Last Name:') - email = forms.EmailField(max_length = 254, label = 'Email: ') - username = forms.CharField(max_length = 100, label = 'Username:') - password_origin = forms.CharField(max_length = 30, widget = forms.PasswordInput(), label = 'Password:') - password_verify = forms.CharField(max_length = 30, widget = forms.PasswordInput(), label = 'Verify Password:') + first_name = forms.CharField(max_length=100, label='First Name:') + last_name = forms.CharField(max_length=100, label='Last Name:') + email = forms.EmailField(max_length=254, label='Email: ') + username = forms.CharField(max_length=100, label='Username:') + password_origin = forms.CharField( + max_length=30, widget=forms.PasswordInput(), label='Password:') + password_verify = forms.CharField( + max_length=30, widget=forms.PasswordInput(), label='Verify Password:') diff --git a/okupy/accounts/models.py b/okupy/accounts/models.py index 859fe73..190137a 100644 --- a/okupy/accounts/models.py +++ b/okupy/accounts/models.py @@ -2,6 +2,7 @@ from django.db import models + class Queue(models.Model): username = models.CharField(max_length=100, unique=True) password = models.CharField(max_length=30) @@ -12,22 +13,24 @@ class Queue(models.Model): # Models for OpenID data store + class OpenID_Nonce(models.Model): + server_uri = models.URLField(max_length=2048) + ts = models.DateTimeField() + salt = models.CharField(max_length=40) + class Meta: unique_together = ('server_uri', 'ts', 'salt') - server_uri = models.URLField(max_length = 2048) - ts = models.DateTimeField() - salt = models.CharField(max_length = 40) class OpenID_Association(models.Model): - class Meta: - unique_together = ('server_uri', 'handle') - - server_uri = models.URLField(max_length = 2048) - handle = models.CharField(max_length = 255) - # XXX: BinaryField in newer versions of django - secret = models.CharField(max_length = 128) + server_uri = models.URLField(max_length=2048) + handle = models.CharField(max_length=255) + # TODO: BinaryField in newer versions of django + secret = models.CharField(max_length=128) issued = models.DateTimeField() expires = models.DateTimeField() - assoc_type = models.CharField(max_length = 64) + assoc_type = models.CharField(max_length=64) + + class Meta: + unique_together = ('server_uri', 'handle') diff --git a/okupy/accounts/openid_store.py b/okupy/accounts/openid_store.py index d2c1446..45cd715 100644 --- a/okupy/accounts/openid_store.py +++ b/okupy/accounts/openid_store.py @@ -1,6 +1,9 @@ # vim:fileencoding=utf8:et:ts=4:sts=4:sw=4:ft=python -import base64, calendar, datetime, time +import base64 +import calendar +import datetime +import time from django.utils import timezone @@ -10,30 +13,32 @@ from openid.store import nonce from . import models as db_models + class DjangoDBOpenIDStore(OpenIDStore): + def storeAssociation(self, server_uri, assoc): issued_dt = datetime.datetime.utcfromtimestamp(assoc.issued) issued_dt = timezone.make_aware(issued_dt, timezone.utc) - expire_delta = datetime.timedelta(seconds = assoc.lifetime) + expire_delta = datetime.timedelta(seconds=assoc.lifetime) a = db_models.OpenID_Association( - server_uri = server_uri, - handle = assoc.handle, - secret = base64.b64encode(assoc.secret), - issued = issued_dt, - expires = issued_dt + expire_delta, - assoc_type = assoc.assoc_type) + server_uri=server_uri, + handle=assoc.handle, + secret=base64.b64encode(assoc.secret), + issued=issued_dt, + expires=issued_dt + expire_delta, + assoc_type=assoc.assoc_type) a.save() - def _db_getAssocs(self, server_uri, handle = None): + def _db_getAssocs(self, server_uri, handle=None): objs = db_models.OpenID_Association.objects - objs = objs.filter(server_uri = server_uri) + objs = objs.filter(server_uri=server_uri) if handle is not None: - objs = objs.filter(handle = handle) + objs = objs.filter(handle=handle) return objs - def getAssociation(self, server_uri, handle = None): + def getAssociation(self, server_uri, handle=None): assert(server_uri is not None) objs = self._db_getAssocs(server_uri, handle) @@ -50,11 +55,11 @@ class DjangoDBOpenIDStore(OpenIDStore): return None return Association( - a.handle, - base64.b64decode(a.secret), - calendar.timegm(a.issued.utctimetuple()), - int((a.expires - a.issued).total_seconds()), - a.assoc_type) + a.handle, + base64.b64decode(a.secret), + calendar.timegm(a.issued.utctimetuple()), + int((a.expires - a.issued).total_seconds()), + a.assoc_type) def removeAssociation(self, server_uri, handle): assert(server_uri is not None) @@ -75,22 +80,22 @@ class DjangoDBOpenIDStore(OpenIDStore): objs = db_models.OpenID_Nonce.objects n, created = objs.get_or_create( - server_uri = server_uri, - ts = nonce_dt, - salt = salt) + server_uri=server_uri, + ts=nonce_dt, + salt=salt) # if it was created, it is unique and everything's fine. # if we found one existing, it is duplicate and we return False. return created def cleanupNonces(self): - skew_td = datetime.timedelta(seconds = nonce.SKEW) + skew_td = datetime.timedelta(seconds=nonce.SKEW) expire_dt = timezone.now() - skew_td - db_models.OpenID_Nonce.objects.filter(ts__lt = expire_dt).delete() + db_models.OpenID_Nonce.objects.filter(ts__lt=expire_dt).delete() return 0 def cleanupAssociations(self): db_models.OpenID_Association.objects.filter( - expires__lt = timezone.now()).delete() + expires__lt=timezone.now()).delete() return 0 diff --git a/okupy/accounts/urls.py b/okupy/accounts/urls.py index ad275d3..f9eb2dd 100644 --- a/okupy/accounts/urls.py +++ b/okupy/accounts/urls.py @@ -1,8 +1,9 @@ # vim:fileencoding=utf8:et:ts=4:sts=4:sw=4:ft=python from django.conf.urls import patterns, url -from .views import (login, logout, index, signup, activate, devlist, formerdevlist, - foundationlist, openid_endpoint, user_page, openid_auth_site) +from .views import (login, logout, index, signup, activate, devlist, + formerdevlist, foundationlist, openid_endpoint, user_page, + openid_auth_site) accounts_urlpatterns = patterns('', url(r'^$', index), diff --git a/okupy/common/exceptions.py b/okupy/common/exceptions.py index fc04ea3..a979503 100644 --- a/okupy/common/exceptions.py +++ b/okupy/common/exceptions.py @@ -1,4 +1,5 @@ # vim:fileencoding=utf8:et:ts=4:sts=4:sw=4:ft=python + class OkupyError(Exception): pass diff --git a/okupy/common/log.py b/okupy/common/log.py index 4f016c8..c8994cc 100644 --- a/okupy/common/log.py +++ b/okupy/common/log.py @@ -2,11 +2,12 @@ from django.conf import settings -def log_extra_data(additional = None): + +def log_extra_data(additional=None): ''' Extra data needed by the custom formatter - * If the additional argument is a string or unicode, then its value is printed - in the log. + * If the additional argument is a string or unicode, then its value is + printed in the log. * If the additional argument is the request, then from the request it prints the client IP and username if applicable. ''' diff --git a/okupy/common/testcase.py b/okupy/common/testcase.py index 3dd7d40..251b361 100644 --- a/okupy/common/testcase.py +++ b/okupy/common/testcase.py @@ -3,7 +3,9 @@ from django.test import TestCase from django.contrib.messages.storage.cookie import CookieStorage + class OkupyTestCase(TestCase): + def _get_matches(self, response, text): """ Get messages that match the given text """ messages = self._get_messages(response) @@ -19,7 +21,8 @@ class OkupyTestCase(TestCase): messages = response.context['messages'] except (TypeError, KeyError): try: - messages = CookieStorage(response)._decode(response.cookies['messages'].value) + messages = CookieStorage(response)._decode( + response.cookies['messages'].value) except KeyError: return return messages @@ -35,7 +38,7 @@ class OkupyTestCase(TestCase): actual_num = 0 if actual_num != expect_num: self.fail('Message count was %d, expected %d' % - (actual_num, expect_num)) + (actual_num, expect_num)) def assertMessage(self, response, text, level=None): """ @@ -46,18 +49,19 @@ class OkupyTestCase(TestCase): msg = matches[0] if level is not None and msg.level != level: self.fail('There was one matching message but with different ' - 'level: %s != %s' % (msg.level, level)) + 'level: %s != %s' % (msg.level, level)) elif len(matches) == 0: - messages_str = ", ".join('"%s"' % m for m in self._get_messages(response)) + messages_str = ", ".join( + '"%s"' % m for m in self._get_messages(response)) self.fail('No message contained text "%s", messages were: %s' % - (text, messages_str)) + (text, messages_str)) else: self.fail('Multiple messages contained text "%s": %s' % - (text, ", ".join(('"%s"' % m) for m in matches))) + (text, ", ".join(('"%s"' % m) for m in matches))) def assertNotMessage(self, response, text): """ Assert that no message contains the given text. """ matches = self._get_matches(response, text) if len(matches) > 0: self.fail('Message(s) contained text "%s": %s' % - (text, ", ".join(('"%s"' % m) for m in matches))) + (text, ", ".join(('"%s"' % m) for m in matches))) diff --git a/okupy/tests/__init__.py b/okupy/tests/__init__.py index f52534a..e69de29 100644 --- a/okupy/tests/__init__.py +++ b/okupy/tests/__init__.py @@ -1,2 +0,0 @@ -# vim:fileencoding=utf8:et:ts=4:sts=4:sw=4:ft=python - diff --git a/okupy/tests/tests.py b/okupy/tests/tests.py index ff900bf..bb10ca6 100644 --- a/okupy/tests/tests.py +++ b/okupy/tests/tests.py @@ -4,7 +4,8 @@ example_directory = { "uid=alice,ou=people,o=test": { "uid": ["alice"], "userPassword": ['{CRYPT}$1$lO/RU6zz$2fJCOwurxBtCqdImkoLQo1'], - "objectClass": ["person", "organizationalPerson", "inetOrgPerson", "posixAccount"], + "objectClass": ["person", "organizationalPerson", "inetOrgPerson", + "posixAccount"], "uidNumber": ["1000"], "gidNumber": ["1000"], "givenName": ["Alice"], @@ -13,7 +14,8 @@ example_directory = { }, "uid=bob,ou=people,o=test": { "uid": ["bob"], - "objectClass": ["person", "organizationalPerson", "inetOrgPerson", "posixAccount"], + "objectClass": ["person", "organizationalPerson", "inetOrgPerson", + "posixAccount"], "userPassword": ['{CRYPT}$1$eFSQMJY6$8y.WUL/ONeEarVXqeCIbH.'], "uidNumber": ["1001"], "gidNumber": ["50"], |