Skip to content

Commit dd30ac0

Browse files
committed
Global PEP8 fixes.
1 parent 0c05d5a commit dd30ac0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+644
-525
lines changed

benchmarks/models.py

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class TestModel(models.Model):
77
name = models.CharField(max_length=128)
88

99

10-
1110
class DirectUser(UserObjectPermissionBase):
1211
content_object = models.ForeignKey('TestDirectModel')
1312

@@ -18,4 +17,3 @@ class DirectGroup(GroupObjectPermissionBase):
1817

1918
class TestDirectModel(models.Model):
2019
name = models.CharField(max_length=128)
21-

benchmarks/run_benchmarks.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
OBJECTS_WIHT_PERMS_COUNT = 100
4040

4141

42-
def random_string(length=25, chars=string.ascii_letters+string.digits):
42+
def random_string(length=25, chars=string.ascii_letters + string.digits):
4343
return ''.join(random.choice(chars) for i in range(length))
4444

4545

@@ -53,6 +53,7 @@ def get_model_name(model):
5353

5454

5555
class Call(object):
56+
5657
def __init__(self, args, kwargs, start=None, finish=None):
5758
self.args = args
5859
self.kwargs = kwargs
@@ -85,14 +86,14 @@ def wrapper(*args, **kwargs):
8586
func.calls.append(call)
8687
if self.action:
8788
print(" -> [%s] Done (Total time: %s)" % (self.action,
88-
call.delta()))
89+
call.delta()))
8990
return wrapper
9091

9192

9293
class Benchmark(object):
9394

9495
def __init__(self, name, users_count, objects_count,
95-
objects_with_perms_count, model, subquery):
96+
objects_with_perms_count, model, subquery):
9697
self.name = name
9798
self.users_count = users_count
9899
self.objects_count = objects_count
@@ -114,13 +115,13 @@ def prepare_db(self):
114115
@Timed("Creating users")
115116
def create_users(self):
116117
User.objects.bulk_create(User(id=x, username=random_string().capitalize())
117-
for x in range(self.users_count))
118+
for x in range(self.users_count))
118119

119120
@Timed("Creating objects")
120121
def create_objects(self):
121122
Model = self.Model
122123
Model.objects.bulk_create(Model(id=x, name=random_string(20))
123-
for x in range(self.objects_count))
124+
for x in range(self.objects_count))
124125

125126
@Timed("Grant permissions")
126127
def grant_perms(self):
@@ -187,6 +188,3 @@ def main():
187188

188189
if __name__ == '__main__':
189190
main()
190-
191-
192-

docs/conf.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@
1111
# All configuration values have a default; values that are commented out
1212
# serve to show the default.
1313

14-
import sys, os
14+
import sys
15+
import os
1516

1617
# If extensions (or modules to document with autodoc) are in another directory,
1718
# add these directories to sys.path here. If the directory is relative to the
1819
# documentation root, use os.path.abspath to make it absolute, like shown here.
1920
sys.path.insert(0, os.path.abspath('..'))
2021
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__))))
2122
os.environ['DJANGO_SETTINGS_MODULE'] = 'guardian.testapp.testsettings'
22-
ANONYMOUS_USER_ID = -1 # Required by guardian
23+
ANONYMOUS_USER_ID = -1 # Required by guardian
2324
guardian = __import__('guardian')
2425

2526
import django
2627
django.setup()
2728

28-
# -- General configuration -----------------------------------------------------
29+
# -- General configuration -----------------------------------------------
2930

3031
# Add any Sphinx extension module names here, as strings. They can be extensions
3132
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
@@ -104,7 +105,7 @@
104105
#modindex_common_prefix = []
105106

106107

107-
# -- Options for HTML output ---------------------------------------------------
108+
# -- Options for HTML output ---------------------------------------------
108109

109110
# The theme to use for HTML and HTML Help pages. Major themes that come with
110111
# Sphinx are currently 'default' and 'sphinxdoc'.
@@ -181,7 +182,7 @@
181182
htmlhelp_basename = 'guardiandoc'
182183

183184

184-
# -- Options for LaTeX output --------------------------------------------------
185+
# -- Options for LaTeX output --------------------------------------------
185186

186187
# The paper size ('letter' or 'a4').
187188
#latex_paper_size = 'letter'
@@ -192,8 +193,8 @@
192193
# Grouping the document tree into LaTeX files. List of tuples
193194
# (source start file, target name, title, author, documentclass [howto/manual]).
194195
latex_documents = [
195-
('index', 'guardian.tex', u'guardian Documentation',
196-
u'Lukasz Balcerzak', 'manual'),
196+
('index', 'guardian.tex', u'guardian Documentation',
197+
u'Lukasz Balcerzak', 'manual'),
197198
]
198199

199200
# The name of an image file (relative to this directory) to place at the top of
@@ -217,8 +218,7 @@
217218
('index', u'django-guardian', u'Documentation for django-guardian',
218219
u'Lukasz Balcerzak'),
219220
]
220-
pdf_stylesheets = ['sphinx','kerning','a4']
221+
pdf_stylesheets = ['sphinx', 'kerning', 'a4']
221222
pdf_break_level = 2
222223
pdf_inline_footnotes = True
223224
#pdf_extensions = ['vectorpdf', 'dotted_toc']
224-

docs/exts.py

+24-25
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
11

22
def setup(app):
33
app.add_crossref_type(
4-
directivename = "admin",
5-
rolename = "admin",
6-
indextemplate = "pair: %s; admin",
4+
directivename="admin",
5+
rolename="admin",
6+
indextemplate="pair: %s; admin",
77
)
88
app.add_crossref_type(
9-
directivename = "command",
10-
rolename = "command",
11-
indextemplate = "pair: %s; command",
9+
directivename="command",
10+
rolename="command",
11+
indextemplate="pair: %s; command",
1212
)
1313
app.add_crossref_type(
14-
directivename = "form",
15-
rolename = "form",
16-
indextemplate = "pair: %s; form",
14+
directivename="form",
15+
rolename="form",
16+
indextemplate="pair: %s; form",
1717
)
1818
app.add_crossref_type(
19-
directivename = "manager",
20-
rolename = "manager",
21-
indextemplate = "pair: %s; manager",
19+
directivename="manager",
20+
rolename="manager",
21+
indextemplate="pair: %s; manager",
2222
)
2323
app.add_crossref_type(
24-
directivename = "mixin",
25-
rolename = "mixin",
26-
indextemplate = "pair: %s; mixin",
24+
directivename="mixin",
25+
rolename="mixin",
26+
indextemplate="pair: %s; mixin",
2727
)
2828
app.add_crossref_type(
29-
directivename = "model",
30-
rolename = "model",
31-
indextemplate = "pair: %s; model",
29+
directivename="model",
30+
rolename="model",
31+
indextemplate="pair: %s; model",
3232
)
3333
app.add_crossref_type(
34-
directivename = "setting",
35-
rolename = "setting",
36-
indextemplate = "pair: %s; setting",
34+
directivename="setting",
35+
rolename="setting",
36+
indextemplate="pair: %s; setting",
3737
)
3838
app.add_crossref_type(
39-
directivename = "shortcut",
40-
rolename = "shortcut",
41-
indextemplate = "pair: %s; shortcut",
39+
directivename="shortcut",
40+
rolename="shortcut",
41+
indextemplate="pair: %s; shortcut",
4242
)
43-

example_project/core/migrations/0001_initial.py

+26-13
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,33 @@ class Migration(migrations.Migration):
1717
migrations.CreateModel(
1818
name='CustomUser',
1919
fields=[
20-
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
21-
('password', models.CharField(max_length=128, verbose_name='password')),
22-
('last_login', models.DateTimeField(null=True, verbose_name='last login', blank=True)),
23-
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
24-
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, max_length=30, validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username. This value may contain only letters, numbers and @/./+/-/_ characters.', 'invalid')], help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', unique=True, verbose_name='username')),
25-
('first_name', models.CharField(max_length=30, verbose_name='first name', blank=True)),
26-
('last_name', models.CharField(max_length=30, verbose_name='last name', blank=True)),
27-
('email', models.EmailField(max_length=254, verbose_name='email address', blank=True)),
28-
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
29-
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
30-
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
20+
('id', models.AutoField(verbose_name='ID',
21+
serialize=False, auto_created=True, primary_key=True)),
22+
('password', models.CharField(
23+
max_length=128, verbose_name='password')),
24+
('last_login', models.DateTimeField(
25+
null=True, verbose_name='last login', blank=True)),
26+
('is_superuser', models.BooleanField(default=False,
27+
help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
28+
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, max_length=30, validators=[django.core.validators.RegexValidator(
29+
'^[\\w.@+-]+$', 'Enter a valid username. This value may contain only letters, numbers and @/./+/-/_ characters.', 'invalid')], help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', unique=True, verbose_name='username')),
30+
('first_name', models.CharField(max_length=30,
31+
verbose_name='first name', blank=True)),
32+
('last_name', models.CharField(max_length=30,
33+
verbose_name='last name', blank=True)),
34+
('email', models.EmailField(max_length=254,
35+
verbose_name='email address', blank=True)),
36+
('is_staff', models.BooleanField(default=False,
37+
help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
38+
('is_active', models.BooleanField(
39+
default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
40+
('date_joined', models.DateTimeField(
41+
default=django.utils.timezone.now, verbose_name='date joined')),
3142
('birth_date', models.DateField(null=True, blank=True)),
32-
('groups', models.ManyToManyField(related_query_name='user', related_name='user_set', to='auth.Group', blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', verbose_name='groups')),
33-
('user_permissions', models.ManyToManyField(related_query_name='user', related_name='user_set', to='auth.Permission', blank=True, help_text='Specific permissions for this user.', verbose_name='user permissions')),
43+
('groups', models.ManyToManyField(related_query_name='user', related_name='user_set', to='auth.Group', blank=True,
44+
help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', verbose_name='groups')),
45+
('user_permissions', models.ManyToManyField(related_query_name='user', related_name='user_set', to='auth.Permission',
46+
blank=True, help_text='Specific permissions for this user.', verbose_name='user permissions')),
3447
],
3548
options={
3649
'abstract': False,

example_project/posts/migrations/0001_initial.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ class Migration(migrations.Migration):
1313
migrations.CreateModel(
1414
name='Post',
1515
fields=[
16-
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
16+
('id', models.AutoField(verbose_name='ID',
17+
serialize=False, auto_created=True, primary_key=True)),
1718
('title', models.CharField(max_length=64, verbose_name=b'title')),
1819
('slug', models.SlugField(max_length=64)),
1920
('content', models.TextField(verbose_name=b'content')),
20-
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
21+
('created_at', models.DateTimeField(
22+
auto_now_add=True, db_index=True)),
2123
],
2224
options={
2325
'get_latest_by': 'created_at',

extras.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def check(filename):
4747
reporter.flake(m)
4848
return len(real_messages)
4949

50+
5051
class RunFlakesCommand(Command):
5152
"""
5253
Runs pyflakes against guardian codebase.
@@ -62,7 +63,7 @@ def finalize_options(self):
6263

6364
def run(self):
6465
try:
65-
import pyflakes # pyflakes:ignore
66+
import pyflakes # pyflakes:ignore
6667
except ImportError:
6768
sys.stderr.write("No pyflakes installed!\n")
6869
sys.exit(-1)
@@ -71,16 +72,17 @@ def run(self):
7172
warns = 0
7273
# Define top-level directories
7374
for topdir, dirnames, filenames in os.walk(guardiandir):
74-
paths = (os.path.join(topdir, f) for f in filenames if f .endswith('.py'))
75+
paths = (os.path.join(topdir, f)
76+
for f in filenames if f .endswith('.py'))
7577
for path in paths:
7678
if path.endswith('tests/__init__.py'):
77-
# ignore that module (it should only gather test cases with *)
79+
# ignore that module (it should only gather test cases with
80+
# *)
7881
continue
7982
warns += check(path)
8083
if warns > 0:
81-
sys.stderr.write("ERROR: Finished with total %d warnings.\n" % warns)
84+
sys.stderr.write(
85+
"ERROR: Finished with total %d warnings.\n" % warns)
8286
sys.exit(1)
8387
else:
8488
print("No problems found in source codes.")
85-
86-

guardian/admin.py

+26-16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class AdminUserObjectPermissionsForm(UserObjectPermissionsForm):
2727
``get_obj_perms_field_widget`` method so it return
2828
``django.contrib.admin.widgets.FilteredSelectMultiple`` widget.
2929
"""
30+
3031
def get_obj_perms_field_widget(self):
3132
return FilteredSelectMultiple(_("Permissions"), False)
3233

@@ -37,6 +38,7 @@ class AdminGroupObjectPermissionsForm(GroupObjectPermissionsForm):
3738
``get_obj_perms_field_widget`` method so it return
3839
``django.contrib.admin.widgets.FilteredSelectMultiple`` widget.
3940
"""
41+
4042
def get_obj_perms_field_widget(self):
4143
return FilteredSelectMultiple(_("Permissions"), False)
4244

@@ -98,16 +100,19 @@ def get_urls(self):
98100
if self.include_object_permissions_urls:
99101
info = self.model._meta.app_label, get_model_name(self.model)
100102
myurls = [
101-
url(r'^(?P<object_pk>.+)/permissions/$',
102-
view=self.admin_site.admin_view(self.obj_perms_manage_view),
103-
name='%s_%s_permissions' % info),
104-
url(r'^(?P<object_pk>.+)/permissions/user-manage/(?P<user_id>\-?\d+)/$',
105-
view=self.admin_site.admin_view(self.obj_perms_manage_user_view),
106-
name='%s_%s_permissions_manage_user' % info),
107-
url(r'^(?P<object_pk>.+)/permissions/group-manage/(?P<group_id>\-?\d+)/$',
108-
view=self.admin_site.admin_view(self.obj_perms_manage_group_view),
109-
name='%s_%s_permissions_manage_group' % info),
110-
]
103+
url(r'^(?P<object_pk>.+)/permissions/$',
104+
view=self.admin_site.admin_view(
105+
self.obj_perms_manage_view),
106+
name='%s_%s_permissions' % info),
107+
url(r'^(?P<object_pk>.+)/permissions/user-manage/(?P<user_id>\-?\d+)/$',
108+
view=self.admin_site.admin_view(
109+
self.obj_perms_manage_user_view),
110+
name='%s_%s_permissions_manage_user' % info),
111+
url(r'^(?P<object_pk>.+)/permissions/group-manage/(?P<group_id>\-?\d+)/$',
112+
view=self.admin_site.admin_view(
113+
self.obj_perms_manage_group_view),
114+
name='%s_%s_permissions_manage_group' % info),
115+
]
111116
urls = myurls + urls
112117
return urls
113118

@@ -147,11 +152,14 @@ def obj_perms_manage_view(self, request, object_pk):
147152
except ImportError:
148153
# django < 1.7
149154
from django.contrib.admin.util import unquote
150-
obj = get_object_or_404(self.get_queryset(request), pk=unquote(object_pk))
155+
obj = get_object_or_404(self.get_queryset(
156+
request), pk=unquote(object_pk))
151157
users_perms = OrderedDict(
152158
sorted(
153-
get_users_with_perms(obj, attach_perms=True, with_group_users=False).items(),
154-
key=lambda user: getattr(user[0], get_user_model().USERNAME_FIELD)
159+
get_users_with_perms(obj, attach_perms=True,
160+
with_group_users=False).items(),
161+
key=lambda user: getattr(
162+
user[0], get_user_model().USERNAME_FIELD)
155163
)
156164
)
157165

@@ -421,8 +429,10 @@ class AuthorAdmin(GuardedModelAdmin):
421429
class UserManage(forms.Form):
422430
user = forms.CharField(label=_("User identification"),
423431
max_length=200,
424-
error_messages={'does_not_exist': _("This user does not exist")},
425-
help_text=_('Enter a value compatible with User.USERNAME_FIELD')
432+
error_messages={'does_not_exist': _(
433+
"This user does not exist")},
434+
help_text=_(
435+
'Enter a value compatible with User.USERNAME_FIELD')
426436
)
427437

428438
def clean_user(self):
@@ -445,7 +455,7 @@ def clean_user(self):
445455

446456
class GroupManage(forms.Form):
447457
group = forms.CharField(max_length=80, error_messages={'does_not_exist':
448-
_("This group does not exist")})
458+
_("This group does not exist")})
449459

450460
def clean_group(self):
451461
"""

0 commit comments

Comments
 (0)