Skip to content

Commit

Permalink
Fixed E127 pep8 warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
loic authored and timgraham committed Dec 14, 2013
1 parent d599b59 commit 6685713
Show file tree
Hide file tree
Showing 55 changed files with 362 additions and 338 deletions.
12 changes: 6 additions & 6 deletions django/contrib/admin/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ def __init__(self, field, request, params, model, model_admin, field_path):
self.title = self.lookup_title

def has_output(self):
if (isinstance(self.field, models.related.RelatedObject)
and self.field.field.null or hasattr(self.field, 'rel')
and self.field.null):
if (isinstance(self.field, models.related.RelatedObject) and
self.field.field.null or hasattr(self.field, 'rel') and
self.field.null):
extra = 1
else:
extra = 0
Expand All @@ -206,9 +206,9 @@ def choices(self, cl):
}, [self.lookup_kwarg_isnull]),
'display': val,
}
if (isinstance(self.field, models.related.RelatedObject)
and self.field.field.null or hasattr(self.field, 'rel')
and self.field.null):
if (isinstance(self.field, models.related.RelatedObject) and
self.field.field.null or hasattr(self.field, 'rel') and
self.field.null):
yield {
'selected': bool(self.lookup_val_isnull),
'query_string': cl.get_query_string({
Expand Down
3 changes: 1 addition & 2 deletions django/contrib/admin/templatetags/admin_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def submit_row(context):
save_as = context['save_as']
ctx = {
'opts': opts,
'show_delete_link': (not is_popup and context['has_delete_permission']
and change and context.get('show_delete', True)),
'show_delete_link': not is_popup and context['has_delete_permission'] and change and context.get('show_delete', True),
'show_save_as_new': not is_popup and change and save_as,
'show_save_and_add_another': context['has_add_permission'] and not is_popup and (not save_as or context['add']),
'show_save_and_continue': not is_popup and context['has_change_permission'],
Expand Down
19 changes: 11 additions & 8 deletions django/contrib/admin/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,13 @@ def render(self, name, value, attrs=None):
extra = []
if rel_to in self.admin_site._registry:
# The related object is registered with the same AdminSite
related_url = reverse('admin:%s_%s_changelist' %
(rel_to._meta.app_label,
rel_to._meta.model_name),
current_app=self.admin_site.name)
related_url = reverse(
'admin:%s_%s_changelist' % (
rel_to._meta.app_label,
rel_to._meta.model_name,
),
current_app=self.admin_site.name,
)

params = self.url_parameters()
if params:
Expand All @@ -167,10 +170,10 @@ def render(self, name, value, attrs=None):
attrs['class'] = 'vForeignKeyRawIdAdminField' # The JavaScript code looks for this hook.
# TODO: "lookup_id_" is hard-coded here. This should instead use
# the correct API to determine the ID dynamically.
extra.append('<a href="%s%s" class="related-lookup" id="lookup_id_%s" onclick="return showRelatedObjectLookupPopup(this);"> '
% (related_url, url, name))
extra.append('<img src="%s" width="16" height="16" alt="%s" /></a>'
% (static('admin/img/selector-search.gif'), _('Lookup')))
extra.append('<a href="%s%s" class="related-lookup" id="lookup_id_%s" onclick="return showRelatedObjectLookupPopup(this);"> ' %
(related_url, url, name))
extra.append('<img src="%s" width="16" height="16" alt="%s" /></a>' %
(static('admin/img/selector-search.gif'), _('Lookup')))
output = [super(ForeignKeyRawIdWidget, self).render(name, value, attrs)] + extra
if value:
output.append(self.label_for_value(value))
Expand Down
4 changes: 2 additions & 2 deletions django/contrib/auth/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class UserCreationForm(forms.ModelForm):
username = forms.RegexField(label=_("Username"), max_length=30,
regex=r'^[\w.@+-]+$',
help_text=_("Required. 30 characters or fewer. Letters, digits and "
"@/./+/-/_ only."),
"@/./+/-/_ only."),
error_messages={
'invalid': _("This value may contain only letters, numbers and "
"@/./+/-/_ characters.")})
Expand Down Expand Up @@ -124,7 +124,7 @@ class UserChangeForm(forms.ModelForm):
username = forms.RegexField(
label=_("Username"), max_length=30, regex=r"^[\w.@+-]+$",
help_text=_("Required. 30 characters or fewer. Letters, digits and "
"@/./+/-/_ only."),
"@/./+/-/_ only."),
error_messages={
'invalid': _("This value may contain only letters, numbers and "
"@/./+/-/_ characters.")})
Expand Down
8 changes: 5 additions & 3 deletions django/contrib/auth/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ def test_create_user_email_domain_normalize_with_whitespace(self):
self.assertEqual(returned, 'email\ [email protected]')

def test_empty_username(self):
self.assertRaisesMessage(ValueError,
'The given username must be set',
User.objects.create_user, username='')
self.assertRaisesMessage(
ValueError,
'The given username must be set',
User.objects.create_user, username=''
)


class AbstractUserTestCase(TestCase):
Expand Down
4 changes: 2 additions & 2 deletions django/contrib/flatpages/templatetags/flatpages.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def get_flatpages(parser, token):
"""
bits = token.split_contents()
syntax_message = ("%(tag_name)s expects a syntax of %(tag_name)s "
"['url_starts_with'] [for user] as context_name" %
dict(tag_name=bits[0]))
"['url_starts_with'] [for user] as context_name" %
dict(tag_name=bits[0]))
# Must have at 3-6 bits in the tag
if len(bits) >= 3 and len(bits) <= 6:

Expand Down
2 changes: 1 addition & 1 deletion django/contrib/gis/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GeometryField(forms.Field):
'invalid_geom': _('Invalid geometry value.'),
'invalid_geom_type': _('Invalid geometry type.'),
'transform_error': _('An error occurred when transforming the geometry '
'to the SRID of the geometry form field.'),
'to the SRID of the geometry form field.'),
}

def __init__(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/gis/gdal/prototypes/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def string_output(func, argtypes, offset=-1, str_result=False, decoding=None):
# given offset.
def _check_str(result, func, cargs):
res = check_string(result, func, cargs,
offset=offset, str_result=str_result)
offset=offset, str_result=str_result)
if res and decoding:
res = res.decode(decoding)
return res
Expand Down
8 changes: 5 additions & 3 deletions django/contrib/gis/geos/libgeos.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@

# No GEOS library could be found.
if lib_path is None:
raise ImportError('Could not find the GEOS library (tried "%s"). '
'Try setting GEOS_LIBRARY_PATH in your settings.' %
'", "'.join(lib_names))
raise ImportError(
'Could not find the GEOS library (tried "%s"). '
'Try setting GEOS_LIBRARY_PATH in your settings.' %
'", "'.join(lib_names)
)

# Getting the GEOS C library. The C interface (CDLL) is used for
# both *NIX and Windows.
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/gis/geos/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,5 @@ def tuple(self):
def kml(self):
"Returns the KML representation of this Polygon."
inner_kml = ''.join("<innerBoundaryIs>%s</innerBoundaryIs>" % self[i + 1].kml
for i in xrange(self.num_interior_rings))
for i in xrange(self.num_interior_rings))
return "<Polygon><outerBoundaryIs>%s</outerBoundaryIs>%s</Polygon>" % (self[0].kml, inner_kml)
16 changes: 8 additions & 8 deletions django/contrib/gis/geos/tests/test_geos_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test03_PointApi(self):
def test04_LineStringMutations(self):
'Testing LineString mutations'
for ls in (LineString((1, 0), (4, 1), (6, -1)),
fromstr('LINESTRING (1 0,4 1,6 -1)')):
fromstr('LINESTRING (1 0,4 1,6 -1)')):
self.assertEqual(ls._get_single_external(1), (4.0, 1.0), 'LineString _get_single_external')

# _set_single
Expand All @@ -135,14 +135,14 @@ def test04_LineStringMutations(self):
def test05_Polygon(self):
'Testing Polygon mutations'
for pg in (Polygon(((1, 0), (4, 1), (6, -1), (8, 10), (1, 0)),
((5, 4), (6, 4), (6, 3), (5, 4))),
fromstr('POLYGON ((1 0,4 1,6 -1,8 10,1 0),(5 4,6 4,6 3,5 4))')):
((5, 4), (6, 4), (6, 3), (5, 4))),
fromstr('POLYGON ((1 0,4 1,6 -1,8 10,1 0),(5 4,6 4,6 3,5 4))')):
self.assertEqual(pg._get_single_external(0),
LinearRing((1, 0), (4, 1), (6, -1), (8, 10), (1, 0)),
'Polygon _get_single_external(0)')
LinearRing((1, 0), (4, 1), (6, -1), (8, 10), (1, 0)),
'Polygon _get_single_external(0)')
self.assertEqual(pg._get_single_external(1),
LinearRing((5, 4), (6, 4), (6, 3), (5, 4)),
'Polygon _get_single_external(1)')
LinearRing((5, 4), (6, 4), (6, 3), (5, 4)),
'Polygon _get_single_external(1)')

# _set_list
pg._set_list(2, (((1, 2), (10, 0), (12, 9), (-1, 15), (1, 2)),
Expand All @@ -160,7 +160,7 @@ def test05_Polygon(self):
def test06_Collection(self):
'Testing Collection mutations'
for mp in (MultiPoint(*map(Point, ((3, 4), (-1, 2), (5, -4), (2, 8)))),
fromstr('MULTIPOINT (3 4,-1 2,5 -4,2 8)')):
fromstr('MULTIPOINT (3 4,-1 2,5 -4,2 8)')):
self.assertEqual(mp._get_single_external(2), Point(5, -4), 'Collection _get_single_external')

mp._set_list(3, map(Point, ((5, 5), (3, -2), (8, 1))))
Expand Down
6 changes: 3 additions & 3 deletions django/contrib/gis/tests/geo3d/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
('I-45',
'LINESTRING(-95.3708481 29.7765870 11.339,-95.3694580 29.7787980 4.536,-95.3690305 29.7797359 9.762,-95.3691886 29.7812450 12.448,-95.3696447 29.7850144 10.457,-95.3702511 29.7868518 9.418,-95.3706724 29.7881286 14.858,-95.3711632 29.7896157 15.386,-95.3714525 29.7936267 13.168,-95.3717848 29.7955007 15.104,-95.3717719 29.7969804 16.516,-95.3717305 29.7982117 13.923,-95.3717254 29.8000778 14.385,-95.3719875 29.8013539 15.160,-95.3720575 29.8026785 15.544,-95.3721321 29.8040912 14.975,-95.3722074 29.8050998 15.688,-95.3722779 29.8060430 16.099,-95.3733818 29.8076750 15.197,-95.3741563 29.8103686 17.268,-95.3749458 29.8129927 19.857,-95.3763564 29.8144557 15.435)',
(11.339, 4.536, 9.762, 12.448, 10.457, 9.418, 14.858,
15.386, 13.168, 15.104, 16.516, 13.923, 14.385, 15.16,
15.544, 14.975, 15.688, 16.099, 15.197, 17.268, 19.857,
15.435),
15.386, 13.168, 15.104, 16.516, 13.923, 14.385, 15.16,
15.544, 14.975, 15.688, 16.099, 15.197, 17.268, 19.857,
15.435),
),
)

Expand Down
4 changes: 2 additions & 2 deletions django/contrib/gis/tests/test_spatialrefsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
'auth_srid': 32140,
'srtext': 'PROJCS["NAD83 / Texas South Central",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980"',
'proj4_re': r'\+proj=lcc \+lat_1=30.28333333333333 \+lat_2=28.38333333333333 \+lat_0=27.83333333333333 '
r'\+lon_0=-99 \+x_0=600000 \+y_0=4000000 (\+ellps=GRS80 )?'
r'(\+datum=NAD83 |\+towgs84=0,0,0,0,0,0,0 )?\+units=m \+no_defs ',
r'\+lon_0=-99 \+x_0=600000 \+y_0=4000000 (\+ellps=GRS80 )?'
r'(\+datum=NAD83 |\+towgs84=0,0,0,0,0,0,0 )?\+units=m \+no_defs ',
'spheroid': 'GRS 1980', 'name': 'NAD83 / Texas South Central',
'geographic': False, 'projected': True, 'spatialite': False,
'ellipsoid': (6378137.0, 6356752.31414, 298.257222101), # From proj's "cs2cs -le" and Wikipedia (semi-minor only)
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/messages/storage/cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def process_messages(self, obj):
return [self.process_messages(item) for item in obj]
if isinstance(obj, dict):
return dict((key, self.process_messages(value))
for key, value in six.iteritems(obj))
for key, value in six.iteritems(obj))
return obj

def decode(self, s, **kwargs):
Expand Down
10 changes: 4 additions & 6 deletions django/contrib/messages/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def setUp(self):
TEMPLATE_CONTEXT_PROCESSORS=global_settings.TEMPLATE_CONTEXT_PROCESSORS,
MESSAGE_TAGS='',
MESSAGE_STORAGE='%s.%s' % (self.storage_class.__module__,
self.storage_class.__name__),
self.storage_class.__name__),
SESSION_SERIALIZER='django.contrib.sessions.serializers.JSONSerializer',
)
self.settings_override.enable()
Expand Down Expand Up @@ -164,8 +164,7 @@ def test_full_request_response_cycle(self):
response = self.client.post(add_url, data, follow=True)
self.assertRedirects(response, show_url)
self.assertTrue('messages' in response.context)
messages = [Message(self.levels[level], msg) for msg in
data['messages']]
messages = [Message(self.levels[level], msg) for msg in data['messages']]
self.assertEqual(list(response.context['messages']), messages)
for msg in data['messages']:
self.assertContains(response, msg)
Expand Down Expand Up @@ -209,8 +208,7 @@ def test_multiple_posts(self):
show_url = reverse('django.contrib.messages.tests.urls.show')
messages = []
for level in ('debug', 'info', 'success', 'warning', 'error'):
messages.extend([Message(self.levels[level], msg) for msg in
data['messages']])
messages.extend([Message(self.levels[level], msg) for msg in data['messages']])
add_url = reverse('django.contrib.messages.tests.urls.add',
args=(level,))
self.client.post(add_url, data)
Expand Down Expand Up @@ -285,7 +283,7 @@ def test_get(self):
def get_existing_storage(self):
return self.get_storage([Message(constants.INFO, 'Test message 1'),
Message(constants.INFO, 'Test message 2',
extra_tags='tag')])
extra_tags='tag')])

def test_existing_read(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/sessions/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def test_clearsessions_command(self):

def count_sessions():
return len([session_file for session_file in os.listdir(storage_path)
if session_file.startswith(file_prefix)])
if session_file.startswith(file_prefix)])

self.assertEqual(0, count_sessions())

Expand Down
4 changes: 2 additions & 2 deletions django/core/files/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def file_move_safe(old_file_name, new_file_name, chunk_size=1024 * 64, allow_ove
# first open the old file, so that it won't go away
with open(old_file_name, 'rb') as old_file:
# now open the new file, not forgetting allow_overwrite
fd = os.open(new_file_name, os.O_WRONLY | os.O_CREAT | getattr(os, 'O_BINARY', 0) |
(os.O_EXCL if not allow_overwrite else 0))
fd = os.open(new_file_name, (os.O_WRONLY | os.O_CREAT | getattr(os, 'O_BINARY', 0) |
(os.O_EXCL if not allow_overwrite else 0)))
try:
locks.lock(fd, locks.LOCK_EX)
current_chunk = None
Expand Down
3 changes: 1 addition & 2 deletions django/core/management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ def get_commands():
for app_name in apps:
try:
path = find_management_module(app_name)
_commands.update(dict((name, app_name)
for name in find_commands(path)))
_commands.update(dict((name, app_name) for name in find_commands(path)))
except ImportError:
pass # No management module - ignore this app

Expand Down
4 changes: 2 additions & 2 deletions django/core/management/commands/compilemessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def has_bom(fn):
with open(fn, 'rb') as f:
sample = f.read(4)
return sample[:3] == b'\xef\xbb\xbf' or \
sample.startswith(codecs.BOM_UTF16_LE) or \
sample.startswith(codecs.BOM_UTF16_BE)
sample.startswith(codecs.BOM_UTF16_LE) or \
sample.startswith(codecs.BOM_UTF16_BE)


def compile_messages(stdout, locale=None):
Expand Down
3 changes: 1 addition & 2 deletions django/core/urlresolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ def get_ns_resolver(ns_pattern, resolver):
# Build a namespaced resolver for the given parent urlconf pattern.
# This makes it possible to have captured parameters in the parent
# urlconf pattern.
ns_resolver = RegexURLResolver(ns_pattern,
resolver.url_patterns)
ns_resolver = RegexURLResolver(ns_pattern, resolver.url_patterns)
return RegexURLResolver(r'^/', [ns_resolver])


Expand Down
14 changes: 7 additions & 7 deletions django/db/backends/oracle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,11 @@ def sequence_reset_by_name_sql(self, style, sequences):
sequence_name = self._get_sequence_name(sequence_info['table'])
table_name = self.quote_name(sequence_info['table'])
column_name = self.quote_name(sequence_info['column'] or 'id')
query = _get_sequence_reset_sql() % {'sequence': sequence_name,
'table': table_name,
'column': column_name}
query = _get_sequence_reset_sql() % {
'sequence': sequence_name,
'table': table_name,
'column': column_name,
}
sql.append(query)
return sql

Expand Down Expand Up @@ -880,12 +882,10 @@ def fetchone(self):
def fetchmany(self, size=None):
if size is None:
size = self.arraysize
return tuple(_rowfactory(r, self.cursor)
for r in self.cursor.fetchmany(size))
return tuple(_rowfactory(r, self.cursor) for r in self.cursor.fetchmany(size))

def fetchall(self):
return tuple(_rowfactory(r, self.cursor)
for r in self.cursor.fetchall())
return tuple(_rowfactory(r, self.cursor) for r in self.cursor.fetchall())

def var(self, *args):
return VariableWrapper(self.cursor.var(*args))
Expand Down
Loading

0 comments on commit 6685713

Please sign in to comment.