Skip to content

Commit

Permalink
flake8 --ignore=E501,E225,E702
Browse files Browse the repository at this point in the history
Altough they have an issue with `lambda : None` and I am
not happy with 78 characters per line, it makes Python code
really ugly.
  • Loading branch information
posativ committed Jun 2, 2012
1 parent dabd0a7 commit 6ea4981
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 69 deletions.
4 changes: 1 addition & 3 deletions acrylamid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ def __init__(self, conf=None):
"""Sets configuration and environment and creates the Request
object"""

global sys

usage = "usage: %prog <subcommand> [options] [args]"
epilog = None

Expand Down Expand Up @@ -295,4 +293,4 @@ def format_epilog(self, formatter):
log.critical('No such command!')
sys.exit(2)

sys.exit(0)
sys.exit(0)
2 changes: 1 addition & 1 deletion acrylamid/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def date(self):
# https://github.com/ametaireau/pelican/blob/master/pelican/utils.py
formats = ['%Y-%m-%d %H:%M', '%Y/%m/%d %H:%M',
'%Y-%m-%d', '%Y/%m/%d',
'%d-%m-%Y', '%Y-%d-%m', # Weird ones
'%d-%m-%Y', '%Y-%d-%m', # Weird ones
'%d/%m/%Y', '%d.%m.%Y',
'%d.%m.%Y %H:%M', '%Y-%m-%d %H:%M:%S']

Expand Down
18 changes: 6 additions & 12 deletions acrylamid/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,9 @@ def __radd__(self, other):
return other + unicode(self)


normal = lambda obj: ANSIString(obj, style=0)
bold = lambda obj: ANSIString(obj, style=1)
underline = lambda obj: ANSIString(obj, style=2)

black = lambda obj: ANSIString(obj, color=30)
red = lambda obj: ANSIString(obj, color=31)
green = lambda obj: ANSIString(obj, color=32)
yellow = lambda obj: ANSIString(obj, color=33)
blue = lambda obj: ANSIString(obj, color=34)
magenta= lambda obj: ANSIString(obj, color=35)
cyan = lambda obj: ANSIString(obj, color=36)
white = lambda obj: ANSIString(obj, color=37)
notmal, bold, underline = [lambda obj, x=x: ANSIString(obj, style=x)
for x in range(0, 3)]

black, red, green, yellow, blue, \
magenta, cyan, white = [lambda obj, y=y: ANSIString(obj, color=y)
for y in range(30, 38)]
1 change: 0 additions & 1 deletion acrylamid/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def initialize(conf, env):
log.warn('no `www_root` specified, using localhost:8000')
conf['www_root'] = 'http://localhost:8000/'


env['protocol'], env['netloc'], env['path'], x, y = urlsplit(conf['www_root'])

# take off the trailing slash for www_root and path
Expand Down
2 changes: 1 addition & 1 deletion acrylamid/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
try:
import cPickle as pickle
except ImportError:
import pickle
import pickle # NOQA

__all__ = ['ExtendedFileSystemLoader', 'Memory', 'cache']

Expand Down
2 changes: 1 addition & 1 deletion acrylamid/defaults/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def create(directory, path):

# restore a given file from defaults
# XXX restore folders, too
if filter(lambda p: basename(p) == basename(root) , files):
if filter(lambda p: basename(p) == basename(root), files):

for path in files:
if basename(path) == basename(root):
Expand Down
3 changes: 1 addition & 2 deletions acrylamid/filters/pytextile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
# License: BSD Style, 2 clauses. see acrylamid/__init__.py

from acrylamid.filters import Filter
from acrylamid.errors import AcrylamidException

try:
from textile import textile
except ImportError:
textile = None
textile = None # NOQA


class PyTextile(Filter):
Expand Down
2 changes: 1 addition & 1 deletion acrylamid/filters/python-discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
try:
from discount import Markdown
except ImportError:
Markdown = None
Markdown = None # NOQA


class Discount(Filter):
Expand Down
4 changes: 2 additions & 2 deletions acrylamid/filters/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from docutils.core import publish_parts
from docutils.parsers.rst import directives
except ImportError:
publish_parts = None
directives = None
publish_parts = None # NOQA
directives = None # NOQA

class Restructuredtext(Filter):

Expand Down
2 changes: 1 addition & 1 deletion acrylamid/filters/rstx_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ def run(self):


def makeExtension():
return Code
return Code
5 changes: 3 additions & 2 deletions acrylamid/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
try:
import translitcodec
except ImportError:
translitcodec = None
translitcodec = None # NOQA

__all__ = ['memoize', 'union', 'mkfile', 'md5', 'expand', 'joinurl',
'safeslug', 'paginate', 'escape', 'system', 'event']
Expand Down Expand Up @@ -86,7 +86,7 @@ def mkfile(content, path, ctime=0.0, force=False, dryrun=False, **kw):
event.create(path=path, ctime=ctime)


def md5(*objs, **kw):
def md5(*objs, **kw):
"""A multifunctional hash function that can take one or more objects
and a getter from which you want calculate the MD5 sum.
Expand Down Expand Up @@ -263,6 +263,7 @@ def metavent(cls, parents, attrs):
def intercept(func):
"""decorator which calls callback registered to this method."""
name, doc = func.func_name, func.__doc__

def dec(cls, path, *args, **kwargs):
for callback in cls.callbacks[name]:
callback(path, *args, **kwargs)
Expand Down
8 changes: 6 additions & 2 deletions acrylamid/lib/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class Worker(Thread):
"""Thread executing tasks from a given tasks queue"""

def __init__(self, tasks):
Thread.__init__(self)
self.tasks = tasks
Expand All @@ -16,17 +17,20 @@ def __init__(self, tasks):
def run(self):
while True:
func, args, kargs = self.tasks.get()
try: func(*args, **kargs)
try:
func(*args, **kargs)
except Exception, e:
print e.__class__.__name__, e
self.tasks.task_done()


class ThreadPool:
"""Pool of threads consuming tasks from a queue"""

def __init__(self, num_threads):
self.tasks = Queue(num_threads)
for _ in range(num_threads): Worker(self.tasks)
for _ in range(num_threads):
Worker(self.tasks)

def add_task(self, func, *args, **kargs):
"""Add a task to the queue"""
Expand Down
10 changes: 6 additions & 4 deletions acrylamid/lib/httpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import os
import SimpleHTTPServer
import SocketServer
import posixpath, urllib
import posixpath
import urllib


class ReuseAddressServer(SocketServer.TCPServer):
Expand All @@ -31,16 +32,17 @@ def translate_path(self, path):
"""
# abandon query parameters
path = path.split('?',1)[0]
path = path.split('#',1)[0]
path = path.split('?', 1)[0]
path = path.split('#', 1)[0]
path = posixpath.normpath(urllib.unquote(path))
words = path.split('/')
words = filter(None, words)
path = os.path.join(os.getcwd(), self.www_root)
for word in words:
drive, word = os.path.splitdrive(word)
head, word = os.path.split(word)
if word in (os.curdir, os.pardir): continue
if word in (os.curdir, os.pardir):
continue
path = os.path.join(path, word)
return path

Expand Down
5 changes: 2 additions & 3 deletions acrylamid/lib/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def parse_date_time(stamp):
except ElementTree.ParseError:
raise InvalidSource('no well-formed XML')


if not tree.tag.endswith('/2005/Atom}feed'):
raise InvalidSource('no Atom feed')

Expand Down Expand Up @@ -259,8 +258,8 @@ def parse(content):
failed = []
for method in (wp, rss20, atom):
try:
res = method(content)
return res.next(), res
res = method(content)
return next(res), res
except ImportError:
log.info('notice BeautifulSoup is required for WordPress import')
except InvalidSource as e:
Expand Down
11 changes: 10 additions & 1 deletion acrylamid/lib/lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import __builtin__
_origimport = __import__


class _demandmod(object):
"""module demand-loader and proxy"""

def __init__(self, name, globals, locals):
if '.' in name:
head, rest = name.split('.', 1)
Expand All @@ -38,13 +40,16 @@ def __init__(self, name, globals, locals):
after = []
object.__setattr__(self, "_data", (head, globals, locals, after))
object.__setattr__(self, "_module", None)

def _extend(self, name):
"""add to the list of submodules to load"""
self._data[3].append(name)

def _load(self):
if not self._module:
head, globals, locals, after = self._data
mod = _origimport(head, globals, locals)

# load submodules
def subload(mod, p):
h, t = p, None
Expand All @@ -67,24 +72,28 @@ def __repr__(self):
if self._module:
return "<proxied module '%s'>" % self._data[0]
return "<unloaded module '%s'>" % self._data[0]

def __call__(self, *args, **kwargs):
raise TypeError("%s object is not callable" % repr(self))

def __getattribute__(self, attr):
if attr in ('_data', '_extend', '_load', '_module'):
return object.__getattribute__(self, attr)
self._load()
return getattr(self._module, attr)

def __setattr__(self, attr, val):
self._load()
setattr(self._module, attr, val)


def _demandimport(name, globals=None, locals=None, fromlist=None, level=None):
if not locals or fromlist == ('*',):
# these cases we can't really delay
return _origimport(name, globals, locals, fromlist)
elif not fromlist:
# import a [as b]
if '.' in name: # a.b
if '.' in name: # a.b
base, rest = name.split('.', 1)
# email.__init__ loading email.mime
if globals and globals.get('__name__', None) == base:
Expand Down
7 changes: 4 additions & 3 deletions acrylamid/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import warnings
from logging import INFO, WARN, DEBUG
from acrylamid.errors import AcrylamidException
from acrylamid.colors import bold, red, green, yellow, white, black
from acrylamid.colors import bold, red, green, yellow, black

SKIP = 15
STORE = []
Expand All @@ -24,7 +24,8 @@ def currentframe():
except:
return sys.exc_info()[2].tb_frame.f_back

if hasattr(sys, '_getframe'): currentframe = lambda: sys._getframe(3)
if hasattr(sys, '_getframe'):
currentframe = lambda: sys._getframe(3)
# done filching


Expand All @@ -34,7 +35,7 @@ class TerminalHandler(logging.StreamHandler):

def __init__(self):
logging.StreamHandler.__init__(self)
self.stream = None # reset it; we are not going to use it anyway
self.stream = None # reset it; we are not going to use it anyway

def emit(self, record):
if record.levelno >= logging.WARN:
Expand Down
2 changes: 1 addition & 1 deletion acrylamid/tasks/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def head(url, path, method='HEAD', redirected=False):

try:
pool.wait_completion()
except KeyboardInterrupt: # I believe, this will not work properly, but it's a try
except KeyboardInterrupt:
sys.exit(1)


Expand Down
2 changes: 2 additions & 0 deletions acrylamid/tasks/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
aliases = ('info', )
usage = "%prog " + sys.argv[1]


def count(option, opt, value, parser, result=[]):
result.append(str(opt).strip('-'))
parser.values.max = result


option = lambda i: make_option('-%i' % (i), action="callback", callback=count, help=SUPPRESS_HELP)
options = [option(i) for i in range(10)]

Expand Down
Loading

0 comments on commit 6ea4981

Please sign in to comment.