Correct flake8 E302 violations

This commit is contained in:
Ray Ashman Jr 2013-11-02 19:53:29 -04:00
parent 3bc0d46a84
commit e2ae8b048e
30 changed files with 260 additions and 1 deletions

View file

@ -209,6 +209,7 @@ class Truncator(SimpleLazyObject):
# Return string
return out
def get_valid_filename(s):
"""
Returns the given string converted to a string that can be used for a clean
@ -222,6 +223,7 @@ def get_valid_filename(s):
return re.sub(r'(?u)[^-\w.]', '', s)
get_valid_filename = allow_lazy(get_valid_filename, six.text_type)
def get_text_list(list_, last_word=ugettext_lazy('or')):
"""
>>> get_text_list(['a', 'b', 'c', 'd'])
@ -245,10 +247,12 @@ def get_text_list(list_, last_word=ugettext_lazy('or')):
force_text(last_word), force_text(list_[-1]))
get_text_list = allow_lazy(get_text_list, six.text_type)
def normalize_newlines(text):
return force_text(re.sub(r'\r\n|\r|\n', '\n', text))
normalize_newlines = allow_lazy(normalize_newlines, six.text_type)
def recapitalize(text):
"Recapitalizes text, placing caps after end-of-sentence punctuation."
text = force_text(text).lower()
@ -257,6 +261,7 @@ def recapitalize(text):
return text
recapitalize = allow_lazy(recapitalize)
def phone2numeric(phone):
"Converts a phone number with letters into its numeric equivalent."
char2number = {'a': '2', 'b': '2', 'c': '2', 'd': '3', 'e': '3', 'f': '3',
@ -267,6 +272,7 @@ def phone2numeric(phone):
return ''.join(char2number.get(c, c) for c in phone.lower())
phone2numeric = allow_lazy(phone2numeric)
# From http://www.xhaus.com/alan/python/httpcomp.html#gzip
# Used with permission.
def compress_string(s):
@ -276,6 +282,7 @@ def compress_string(s):
zfile.close()
return zbuf.getvalue()
class StreamingBuffer(object):
def __init__(self):
self.vals = []
@ -294,6 +301,7 @@ class StreamingBuffer(object):
def close(self):
return
# Like compress_string, but for iterators of strings.
def compress_sequence(sequence):
buf = StreamingBuffer()
@ -309,6 +317,7 @@ def compress_sequence(sequence):
ustring_re = re.compile("([\u0080-\uffff])")
def javascript_quote(s, quote_double_quotes=False):
def fix(match):
@ -340,6 +349,7 @@ smart_split_re = re.compile(r"""
) | \S+)
""", re.VERBOSE)
def smart_split(text):
r"""
Generator that splits a string by spaces, leaving quoted phrases together.
@ -359,6 +369,7 @@ def smart_split(text):
for bit in smart_split_re.finditer(text):
yield bit.group(0)
def _replace_entity(match):
text = match.group(1)
if text[0] == '#':
@ -379,10 +390,12 @@ def _replace_entity(match):
_entity_re = re.compile(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));")
def unescape_entities(text):
return _entity_re.sub(_replace_entity, text)
unescape_entities = allow_lazy(unescape_entities, six.text_type)
def unescape_string_literal(s):
r"""
Convert quoted string literals to unquoted strings with escaped quotes and
@ -403,6 +416,7 @@ def unescape_string_literal(s):
return s[1:-1].replace(r'\%s' % quote, quote).replace(r'\\', '\\')
unescape_string_literal = allow_lazy(unescape_string_literal)
def slugify(value):
"""
Converts to lowercase, removes non-word characters (alphanumerics and