mirror of
https://github.com/django/django.git
synced 2025-10-26 15:16:09 +00:00
Fixed #21298 -- Fixed E301 pep8 warnings
This commit is contained in:
@@ -222,6 +222,7 @@ class TestUtilsHashPass(unittest.TestCase):
|
||||
for algo in ('sha1', 'md5'):
|
||||
encoded = make_password('lètmein', hasher=algo)
|
||||
state = {'upgraded': False}
|
||||
|
||||
def setter(password):
|
||||
state['upgraded'] = True
|
||||
self.assertTrue(check_password('lètmein', encoded, setter))
|
||||
@@ -230,6 +231,7 @@ class TestUtilsHashPass(unittest.TestCase):
|
||||
def test_no_upgrade(self):
|
||||
encoded = make_password('lètmein')
|
||||
state = {'upgraded': False}
|
||||
|
||||
def setter():
|
||||
state['upgraded'] = True
|
||||
self.assertFalse(check_password('WRONG', encoded, setter))
|
||||
@@ -240,6 +242,7 @@ class TestUtilsHashPass(unittest.TestCase):
|
||||
for algo in ('sha1', 'md5'):
|
||||
encoded = make_password('lètmein', hasher=algo)
|
||||
state = {'upgraded': False}
|
||||
|
||||
def setter():
|
||||
state['upgraded'] = True
|
||||
self.assertFalse(check_password('WRONG', encoded, setter))
|
||||
@@ -259,6 +262,7 @@ class TestUtilsHashPass(unittest.TestCase):
|
||||
self.assertEqual(iterations, '1')
|
||||
|
||||
state = {'upgraded': False}
|
||||
|
||||
def setter(password):
|
||||
state['upgraded'] = True
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ class TokenGeneratorTest(TestCase):
|
||||
class Mocked(PasswordResetTokenGenerator):
|
||||
def __init__(self, today):
|
||||
self._today_val = today
|
||||
|
||||
def _today(self):
|
||||
return self._today_val
|
||||
|
||||
|
||||
@@ -418,8 +418,10 @@ class WizardInlineFormSetTests(TestCase):
|
||||
def test_set_instance(self):
|
||||
# Regression test for #21259
|
||||
poet = self.poet
|
||||
|
||||
class InlineFormSetWizard(CookieWizardView):
|
||||
instance = None
|
||||
|
||||
def get_form_instance(self, step):
|
||||
if self.instance is None:
|
||||
self.instance = poet
|
||||
|
||||
@@ -87,6 +87,7 @@ class OpenLayersWidget(Textarea):
|
||||
# JavaScript construction utilities for the Bounds and Projection.
|
||||
def ol_bounds(extent):
|
||||
return 'new OpenLayers.Bounds(%s)' % str(extent)
|
||||
|
||||
def ol_projection(srid):
|
||||
return 'new OpenLayers.Projection("EPSG:%s")' % srid
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ class GeometryColumns(models.Model):
|
||||
column_name = models.CharField(max_length=1024)
|
||||
srid = models.IntegerField(primary_key=True)
|
||||
# TODO: Add support for `diminfo` column (type MDSYS.SDO_DIM_ARRAY).
|
||||
|
||||
class Meta:
|
||||
db_table = 'USER_SDO_GEOM_METADATA'
|
||||
managed = False
|
||||
|
||||
@@ -44,6 +44,7 @@ class PostGISSpheroidDistance(PostGISFunction):
|
||||
"For PostGIS spherical distance operations (using the spheroid)."
|
||||
dist_func = 'distance_spheroid'
|
||||
sql_template = '%(function)s(%(geo_col)s, %(geometry)s, %%s) %(operator)s %%s'
|
||||
|
||||
def __init__(self, prefix, operator):
|
||||
# An extra parameter in `end_subst` is needed for the spheroid string.
|
||||
super(PostGISSpheroidDistance, self).__init__(prefix, self.dist_func,
|
||||
@@ -137,6 +138,7 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
|
||||
|
||||
# Valid distance types and substitutions
|
||||
dtypes = (Decimal, Distance, float) + six.integer_types
|
||||
|
||||
def get_dist_ops(operator):
|
||||
"Returns operations for both regular and spherical distances."
|
||||
return {'cartesian' : PostGISDistance(prefix, operator),
|
||||
@@ -455,6 +457,7 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
|
||||
"""
|
||||
def exactly_two(np):
|
||||
return np == 2
|
||||
|
||||
def two_to_three(np):
|
||||
return np >= 2 and np <= 3
|
||||
if (lookup_type in self.distance_functions and
|
||||
|
||||
@@ -40,6 +40,7 @@ class SpatiaLiteDistance(SpatiaLiteFunction):
|
||||
class SpatiaLiteRelate(SpatiaLiteFunctionParam):
|
||||
"For SpatiaLite Relate(<geom>, <pattern>) calls."
|
||||
pattern_regex = re.compile(r'^[012TF\*]{9}$')
|
||||
|
||||
def __init__(self, pattern):
|
||||
if not self.pattern_regex.match(pattern):
|
||||
raise ValueError('Invalid intersection matrix pattern "%s".' % pattern)
|
||||
|
||||
@@ -5,6 +5,7 @@ to convert geospatial values from the database.
|
||||
|
||||
class BaseField(object):
|
||||
empty_strings_allowed = True
|
||||
|
||||
def get_internal_type(self):
|
||||
"Overloaded method so OracleQuery.convert_values doesn't balk."
|
||||
return None
|
||||
|
||||
@@ -79,6 +79,7 @@ class BaseGeometryWidget(Widget):
|
||||
|
||||
class OpenLayersWidget(BaseGeometryWidget):
|
||||
template_name = 'gis/openlayers.html'
|
||||
|
||||
class Media:
|
||||
js = (
|
||||
'http://openlayers.org/api/2.13/OpenLayers.js',
|
||||
|
||||
@@ -36,6 +36,7 @@ def geom_output(func, argtypes, offset=None):
|
||||
else:
|
||||
# Error code returned, geometry is returned by-reference.
|
||||
func.restype = c_int
|
||||
|
||||
def geomerrcheck(result, func, cargs):
|
||||
return check_geom_offset(result, func, cargs, offset)
|
||||
func.errcheck = geomerrcheck
|
||||
|
||||
@@ -291,6 +291,7 @@ class ListMixin(object):
|
||||
# we're not changing the length of the sequence
|
||||
newLen = len(self)
|
||||
newVals = dict(zip(indexList, valueList))
|
||||
|
||||
def newItems():
|
||||
for i in xrange(newLen):
|
||||
if i in newVals:
|
||||
@@ -317,6 +318,7 @@ class ListMixin(object):
|
||||
origLen = len(self)
|
||||
stop = max(start, stop)
|
||||
newLen = origLen - stop + start + len(valueList)
|
||||
|
||||
def newItems():
|
||||
for i in xrange(origLen + 1):
|
||||
if i == start:
|
||||
|
||||
@@ -51,6 +51,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
|
||||
|
||||
# This one only accepts pointers to floats
|
||||
c_float_p = ctypes.POINTER(ctypes.c_float)
|
||||
|
||||
class FakeGeom2(GEOSBase):
|
||||
ptr_type = c_float_p
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from django.utils import six
|
||||
|
||||
class UserListA(ListMixin):
|
||||
_mytype = tuple
|
||||
|
||||
def __init__(self, i_list, *args, **kwargs):
|
||||
self._list = self._mytype(i_list)
|
||||
super(UserListA, self).__init__(*args, **kwargs)
|
||||
@@ -211,8 +212,10 @@ class ListMixinTest(unittest.TestCase):
|
||||
'Out of range exceptions'
|
||||
def setfcn(x, i):
|
||||
x[i] = 20
|
||||
|
||||
def getfcn(x, i):
|
||||
return x[i]
|
||||
|
||||
def delfcn(x, i):
|
||||
del x[i]
|
||||
pl, ul = self.lists_of_len()
|
||||
@@ -252,6 +255,7 @@ class ListMixinTest(unittest.TestCase):
|
||||
self.assertEqual(pl[:], ul[:], 'after pop')
|
||||
|
||||
pl, ul = self.lists_of_len()
|
||||
|
||||
def popfcn(x, i):
|
||||
x.pop(i)
|
||||
self.assertRaises(IndexError, popfcn, ul, self.limit)
|
||||
@@ -272,6 +276,7 @@ class ListMixinTest(unittest.TestCase):
|
||||
|
||||
def indexfcn(x, v):
|
||||
return x.index(v)
|
||||
|
||||
def removefcn(x, v):
|
||||
return x.remove(v)
|
||||
self.assertRaises(ValueError, indexfcn, ul, 40)
|
||||
@@ -283,6 +288,7 @@ class ListMixinTest(unittest.TestCase):
|
||||
ul._allowed = six.integer_types
|
||||
ul[1] = 50
|
||||
ul[:2] = [60, 70, 80]
|
||||
|
||||
def setfcn(x, i, v):
|
||||
x[i] = v
|
||||
self.assertRaises(TypeError, setfcn, ul, 2, 'hello')
|
||||
@@ -292,8 +298,10 @@ class ListMixinTest(unittest.TestCase):
|
||||
'Length limits'
|
||||
pl, ul = self.lists_of_len()
|
||||
ul._minlength = 1
|
||||
|
||||
def delfcn(x,i):
|
||||
del x[:i]
|
||||
|
||||
def setfcn(x,i):
|
||||
x[:i] = []
|
||||
for i in range(self.limit - ul._minlength + 1, self.limit + 1):
|
||||
@@ -309,6 +317,7 @@ class ListMixinTest(unittest.TestCase):
|
||||
def test09_iterable_check(self):
|
||||
'Error on assigning non-iterable to slice'
|
||||
pl, ul = self.lists_of_len(self.limit + 1)
|
||||
|
||||
def setfcn(x, i, v):
|
||||
x[i] = v
|
||||
self.assertRaises(TypeError, setfcn, ul, slice(0,3,2), 2)
|
||||
|
||||
@@ -148,6 +148,7 @@ def get_ogr_db_string():
|
||||
|
||||
# Build the params of the OGR database connection string
|
||||
params = [db_str % {'db_name': db['NAME']}]
|
||||
|
||||
def add(key, template):
|
||||
value = db.get(key, None)
|
||||
# Don't add the parameter if it is not in django's settings
|
||||
|
||||
@@ -263,6 +263,7 @@ class CustomGeometryWidgetTest(SimpleTestCase):
|
||||
class CustomGeometryWidget(forms.BaseGeometryWidget):
|
||||
template_name = 'gis/openlayers.html'
|
||||
deserialize_called = 0
|
||||
|
||||
def serialize(self, value):
|
||||
return value.json if value else ''
|
||||
|
||||
|
||||
@@ -101,6 +101,7 @@ class CookieStorage(BaseStorage):
|
||||
# data is going to be stored eventually by SimpleCookie, which
|
||||
# adds it's own overhead, which we must account for.
|
||||
cookie = SimpleCookie() # create outside the loop
|
||||
|
||||
def stored_length(val):
|
||||
return len(cookie.value_encode(val)[1])
|
||||
|
||||
|
||||
@@ -142,6 +142,7 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||
Sitemap.get_url() url result.
|
||||
"""
|
||||
test_sitemap = GenericSitemap({'queryset': TestModel.objects.all()})
|
||||
|
||||
def is_testmodel(url):
|
||||
return isinstance(url['item'], TestModel)
|
||||
item_in_url_info = all(map(is_testmodel, test_sitemap.get_urls()))
|
||||
|
||||
@@ -12,6 +12,7 @@ try:
|
||||
from shutil import copystat
|
||||
except ImportError:
|
||||
import stat
|
||||
|
||||
def copystat(src, dst):
|
||||
"""Copy all stat info (mode bits, atime and mtime) from src to dst"""
|
||||
st = os.stat(src)
|
||||
|
||||
@@ -93,6 +93,7 @@ class MigrationGraph(object):
|
||||
Dynamic programming based depth first search, for finding dependencies.
|
||||
"""
|
||||
cache = {}
|
||||
|
||||
def _dfs(start, get_children, path):
|
||||
# If we already computed this, use that (dynamic programming)
|
||||
if (start, get_children) in cache:
|
||||
|
||||
@@ -20,6 +20,7 @@ class MigrationRecorder(object):
|
||||
app = models.CharField(max_length=255)
|
||||
name = models.CharField(max_length=255)
|
||||
applied = models.DateTimeField(default=now)
|
||||
|
||||
class Meta:
|
||||
app_cache = BaseAppCache()
|
||||
app_label = "migrations"
|
||||
|
||||
@@ -241,6 +241,7 @@ class BaseFormSet(object):
|
||||
# None should be sorted below anything else. Allowing None as
|
||||
# a comparison value makes it so we can leave ordering fields
|
||||
# blank.
|
||||
|
||||
def compare_ordering_key(k):
|
||||
if k[1] is None:
|
||||
return (1, 0) # +infinity, larger than any number
|
||||
|
||||
@@ -602,6 +602,7 @@ class BaseModelFormSet(BaseFormSet):
|
||||
"""
|
||||
if not commit:
|
||||
self.saved_forms = []
|
||||
|
||||
def save_m2m():
|
||||
for form in self.saved_forms:
|
||||
form.save_m2m()
|
||||
@@ -754,6 +755,7 @@ class BaseModelFormSet(BaseFormSet):
|
||||
# data back. Generally, pk.editable should be false, but for some
|
||||
# reason, auto_created pk fields and AutoField's editable attribute is
|
||||
# True, so check for that as well.
|
||||
|
||||
def pk_is_not_editable(pk):
|
||||
return ((not pk.editable) or (pk.auto_created or isinstance(pk, AutoField))
|
||||
or (pk.rel and pk.rel.parent_link and pk_is_not_editable(pk.rel.to._meta.pk)))
|
||||
|
||||
@@ -406,6 +406,7 @@ class Textarea(Widget):
|
||||
|
||||
class DateTimeBaseInput(TextInput):
|
||||
format_key = ''
|
||||
|
||||
def __init__(self, attrs=None, format=None):
|
||||
super(DateTimeBaseInput, self).__init__(attrs)
|
||||
self.format = format if format else None
|
||||
|
||||
@@ -591,6 +591,7 @@ def unordered_list(value, autoescape=None):
|
||||
escaper = conditional_escape
|
||||
else:
|
||||
escaper = lambda x: x
|
||||
|
||||
def convert_old_style_list(list_):
|
||||
"""
|
||||
Converts old style lists to the new easier to understand format.
|
||||
@@ -621,6 +622,7 @@ def unordered_list(value, autoescape=None):
|
||||
if old_style_list:
|
||||
second_item = new_second_item
|
||||
return [first_item, second_item], old_style_list
|
||||
|
||||
def _helper(list_, tabs=1):
|
||||
indent = '\t' * tabs
|
||||
output = []
|
||||
|
||||
@@ -245,6 +245,7 @@ def compare_xml(want, got):
|
||||
Based on http://codespeak.net/svn/lxml/trunk/src/lxml/doctestcompare.py
|
||||
"""
|
||||
_norm_whitespace_re = re.compile(r'[ \t\n][ \t\n]+')
|
||||
|
||||
def norm_whitespace(v):
|
||||
return _norm_whitespace_re.sub(' ', v)
|
||||
|
||||
@@ -405,6 +406,7 @@ def patch_logger(logger_name, log_level):
|
||||
and provides a simple mock-like list of messages received
|
||||
"""
|
||||
calls = []
|
||||
|
||||
def replacement(msg):
|
||||
calls.append(msg)
|
||||
logger = logging.getLogger(logger_name)
|
||||
|
||||
@@ -30,6 +30,7 @@ def method_decorator(decorator):
|
||||
# In case 'decorator' adds attributes to the function it decorates, we
|
||||
# want to copy those. We don't have access to bound_func in this scope,
|
||||
# but we can cheat by using it on a dummy function.
|
||||
|
||||
@decorator
|
||||
def dummy(*args, **kwargs):
|
||||
pass
|
||||
@@ -84,6 +85,7 @@ def available_attrs(fn):
|
||||
def make_middleware_decorator(middleware_class):
|
||||
def _make_decorator(*m_args, **m_kwargs):
|
||||
middleware = middleware_class(*m_args, **m_kwargs)
|
||||
|
||||
def _decorator(view_func):
|
||||
@wraps(view_func, assigned=available_attrs(view_func))
|
||||
def _wrapped_view(request, *args, **kwargs):
|
||||
|
||||
@@ -213,6 +213,7 @@ class Enclosure(object):
|
||||
|
||||
class RssFeed(SyndicationFeed):
|
||||
mime_type = 'application/rss+xml; charset=utf-8'
|
||||
|
||||
def write(self, outfile, encoding):
|
||||
handler = SimplerXMLGenerator(outfile, encoding)
|
||||
handler.startDocument()
|
||||
@@ -255,6 +256,7 @@ class RssFeed(SyndicationFeed):
|
||||
|
||||
class RssUserland091Feed(RssFeed):
|
||||
_version = "0.91"
|
||||
|
||||
def add_item_elements(self, handler, item):
|
||||
handler.addQuickElement("title", item['title'])
|
||||
handler.addQuickElement("link", item['link'])
|
||||
@@ -264,6 +266,7 @@ class RssUserland091Feed(RssFeed):
|
||||
class Rss201rev2Feed(RssFeed):
|
||||
# Spec: http://blogs.law.harvard.edu/tech/rss
|
||||
_version = "2.0"
|
||||
|
||||
def add_item_elements(self, handler, item):
|
||||
handler.addQuickElement("title", item['title'])
|
||||
handler.addQuickElement("link", item['link'])
|
||||
|
||||
@@ -118,12 +118,16 @@ class MLStripper(HTMLParser):
|
||||
HTMLParser.__init__(self)
|
||||
self.reset()
|
||||
self.fed = []
|
||||
|
||||
def handle_data(self, d):
|
||||
self.fed.append(d)
|
||||
|
||||
def handle_entityref(self, name):
|
||||
self.fed.append('&%s;' % name)
|
||||
|
||||
def handle_charref(self, name):
|
||||
self.fed.append('&#%s;' % name)
|
||||
|
||||
def get_data(self):
|
||||
return ''.join(self.fed)
|
||||
|
||||
@@ -285,6 +289,7 @@ def clean_html(text):
|
||||
# Trim stupid HTML such as <br clear="all">.
|
||||
text = html_gunk_re.sub('', text)
|
||||
# Convert hard-coded bullets into HTML unordered lists.
|
||||
|
||||
def replace_p_tags(match):
|
||||
s = match.group().replace('</p>', '</li>')
|
||||
for d in DOTS:
|
||||
|
||||
@@ -444,6 +444,7 @@ def iterlists(d, **kw):
|
||||
if PY3:
|
||||
def b(s):
|
||||
return s.encode("latin-1")
|
||||
|
||||
def u(s):
|
||||
return s
|
||||
unichr = chr
|
||||
@@ -462,14 +463,18 @@ if PY3:
|
||||
else:
|
||||
def b(s):
|
||||
return s
|
||||
|
||||
def u(s):
|
||||
return unicode(s, "unicode_escape")
|
||||
unichr = unichr
|
||||
int2byte = chr
|
||||
|
||||
def byte2int(bs):
|
||||
return ord(bs[0])
|
||||
|
||||
def indexbytes(buf, i):
|
||||
return ord(buf[i])
|
||||
|
||||
def iterbytes(buf):
|
||||
return (ord(byte) for byte in buf)
|
||||
import StringIO
|
||||
@@ -512,6 +517,7 @@ else:
|
||||
fp = kwargs.pop("file", sys.stdout)
|
||||
if fp is None:
|
||||
return
|
||||
|
||||
def write(data):
|
||||
if not isinstance(data, basestring):
|
||||
data = str(data)
|
||||
|
||||
@@ -32,6 +32,7 @@ def wrap(text, width):
|
||||
the text. Expects that existing line breaks are posix newlines.
|
||||
"""
|
||||
text = force_text(text)
|
||||
|
||||
def _generator():
|
||||
it = iter(text.split(' '))
|
||||
word = next(it)
|
||||
|
||||
Reference in New Issue
Block a user