Skip to content

Commit

Permalink
flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed Aug 13, 2016
1 parent ae2c1d3 commit 006ee05
Show file tree
Hide file tree
Showing 26 changed files with 307 additions and 322 deletions.
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
ignore = N801,N802,N803,N805,N806,N812,E301
exclude = bootstrap.py
33 changes: 17 additions & 16 deletions src/App/CacheManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from App.special_dtml import DTMLFile
from DateTime.DateTime import DateTime

class CacheManager:

class CacheManager(object):
"""Cache management mix-in
"""
_cache_age = 60
Expand Down Expand Up @@ -47,46 +48,46 @@ def database_size(self):
def cache_age(self):
return self._cache_age

def manage_cache_age(self,value,REQUEST):
def manage_cache_age(self, value, REQUEST):
"set cache age"
db = self._getDB()
self._cache_age = value
db.setCacheDeactivateAfter(value)

if REQUEST is not None:
response=REQUEST['RESPONSE']
response.redirect(REQUEST['URL1']+'/manage_cacheParameters')
response = REQUEST['RESPONSE']
response.redirect(REQUEST['URL1'] + '/manage_cacheParameters')

def cache_size(self):
db = self._getDB()
return db.getCacheSize()

def manage_cache_size(self,value,REQUEST):
def manage_cache_size(self, value, REQUEST):
"set cache size"
db = self._getDB()
db.setCacheSize(value)

if REQUEST is not None:
response=REQUEST['RESPONSE']
response.redirect(REQUEST['URL1']+'/manage_cacheParameters')
response = REQUEST['RESPONSE']
response.redirect(REQUEST['URL1'] + '/manage_cacheParameters')

def manage_full_sweep(self,value,REQUEST):
def manage_full_sweep(self, value, REQUEST):
"Perform a full sweep through the cache"
db = self._getDB()
db.cacheFullSweep(value)

if REQUEST is not None:
response=REQUEST['RESPONSE']
response.redirect(REQUEST['URL1']+'/manage_cacheGC')
response = REQUEST['RESPONSE']
response.redirect(REQUEST['URL1'] + '/manage_cacheGC')

def manage_minimize(self,value=1,REQUEST=None):
def manage_minimize(self, value=1, REQUEST=None):
"Perform a full sweep through the cache"
# XXX Add a deprecation warning about value?
self._getDB().cacheMinimize()

if REQUEST is not None:
response=REQUEST['RESPONSE']
response.redirect(REQUEST['URL1']+'/manage_cacheGC')
response = REQUEST['RESPONSE']
response.redirect(REQUEST['URL1'] + '/manage_cacheGC')

def cache_detail(self, REQUEST=None):
"""
Expand Down Expand Up @@ -129,7 +130,7 @@ def cache_extreme_detail(self, REQUEST=None):
else:
state = 'G' # ghost
res.append('%d %-34s %6d %s %s%s' % (
dict['conn_no'], `dict['oid']`, dict['rc'],
dict['conn_no'], repr(dict['oid']), dict['rc'],
state, dict['klass'], idinfo))
REQUEST.RESPONSE.setHeader('Content-Type', 'text/plain')
return '\n'.join(res)
Expand Down Expand Up @@ -158,7 +159,7 @@ def manage_setHistoryLength(self, length, REQUEST=None):
am = self._getActivityMonitor()
length = int(length)
if length < 0:
raise ValueError, 'length can not be negative'
raise ValueError('length can not be negative')
if am is not None:
am.setHistoryLength(length)
self._history_length = length # Restore on startup
Expand Down Expand Up @@ -235,7 +236,7 @@ def getActivityChartData(self, segment_height, REQUEST=None):
'start': div['start'],
'end': div['end'],
'time_offset': time_offset,
})
})

if analysis:
start_time = DateTime(divs[0]['start']).aCommonZ()
Expand Down
64 changes: 34 additions & 30 deletions src/App/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,57 @@
import sys
import time

# Legacy API for this module; 3rd party code may use this.
from os.path import realpath
from Acquisition import aq_base

# BBB
from os.path import realpath # NOQA
attrget = getattr

# These are needed because the various date formats below must
# be in english per the RFCs. That means we can't use strftime,
# which is affected by different locale settings.
weekday_abbr = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
weekday_full = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
'Friday', 'Saturday', 'Sunday']
monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']


def iso8601_date(ts=None):
# Return an ISO 8601 formatted date string, required
# for certain DAV properties.
# '2000-11-10T16:21:09-08:00
if ts is None: ts=time.time()
if ts is None:
ts = time.time()
return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(ts))


def rfc850_date(ts=None):
# Return an HTTP-date formatted date string.
# 'Friday, 10-Nov-00 16:21:09 GMT'
if ts is None: ts=time.time()
if ts is None:
ts = time.time()
year, month, day, hh, mm, ss, wd, y, z = time.gmtime(ts)
return "%s, %02d-%3s-%2s %02d:%02d:%02d GMT" % (
weekday_full[wd],
day, monthname[month],
str(year)[2:],
hh, mm, ss)
weekday_full[wd],
day, monthname[month],
str(year)[2:],
hh, mm, ss)


def rfc1123_date(ts=None):
# Return an RFC 1123 format date string, required for
# use in HTTP Date headers per the HTTP 1.1 spec.
# 'Fri, 10 Nov 2000 16:21:09 GMT'
if ts is None: ts=time.time()
if ts is None:
ts = time.time()
year, month, day, hh, mm, ss, wd, y, z = time.gmtime(ts)
return "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (weekday_abbr[wd],
day, monthname[month],
year,
hh, mm, ss)
return "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (
weekday_abbr[wd],
day, monthname[month],
year,
hh, mm, ss)


def absattr(attr, callable=callable):
# Return the absolute value of an attribute,
Expand All @@ -66,9 +75,6 @@ def absattr(attr, callable=callable):
return attr()
return attr

def aq_base(ob, getattr=getattr):
# Return the aq_base of an object.
return getattr(ob, 'aq_base', ob)

def is_acquired(ob, hasattr=hasattr, aq_base=aq_base, absattr=absattr):
# Return true if this object is not considered to be
Expand All @@ -82,7 +88,7 @@ def is_acquired(ob, hasattr=hasattr, aq_base=aq_base, absattr=absattr):
return 0

parent = aq_base(ob.aq_parent)
absId = absattr(ob.id)
absId = absattr(ob.id)

if hasattr(parent, absId):
# Consider direct attributes not acquired
Expand All @@ -104,22 +110,20 @@ def is_acquired(ob, hasattr=hasattr, aq_base=aq_base, absattr=absattr):
ob.isTopLevelPrincipiaApplicationObject:
# This object the top level
return 0
return 1 # This object is acquired by our measure
return 1 # This object is acquired by our measure


def package_home(globals_dict):
__name__=globals_dict['__name__']
m=sys.modules[__name__]
if hasattr(m,'__path__'):
r=m.__path__[0]
__name__ = globals_dict['__name__']
m = sys.modules[__name__]
if hasattr(m, '__path__'):
r = m.__path__[0]
elif "." in __name__:
r=sys.modules[__name__[:__name__.rfind('.')]].__path__[0]
r = sys.modules[__name__[:__name__.rfind('.')]].__path__[0]
else:
r=__name__
r = __name__
return os.path.abspath(r)


# We really only want the 3-argument version of getattr:
attrget = getattr

def Dictionary(**kw): return kw # Sorry Guido
def Dictionary(**kw):
return kw # Sorry Guido
35 changes: 18 additions & 17 deletions src/App/Extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def _getPath(home, prefix, name, suffixes):
fn = os.path.join(dir, name)
if fn == name:
# Paranoia
raise ValueError('The file name, %s, should be a simple file name'
% name)
raise ValueError(
'The file name, %s, should be a simple file name' % name)

for suffix in suffixes:
if suffix:
Expand Down Expand Up @@ -87,8 +87,8 @@ def getPath(prefix, name, checkProduct=1, suffixes=('',), cfg=None):
"""
dir, ignored = os.path.split(name)
if dir:
raise ValueError('The file name, %s, should be a simple file name'
% name)
raise ValueError(
'The file name, %s, should be a simple file name' % name)

if checkProduct:
dot = name.find('.')
Expand Down Expand Up @@ -120,27 +120,28 @@ def getPath(prefix, name, checkProduct=1, suffixes=('',), cfg=None):
try:
dot = name.rfind('.')
if dot > 0:
realName = name[dot+1:]
realName = name[dot + 1:]
toplevel = name[:dot]

rdot = toplevel.rfind('.')
if rdot > -1:
module = __import__(toplevel, globals(), {}, toplevel[rdot+1:])
module = __import__(
toplevel, globals(), {}, toplevel[rdot + 1:])
else:
module = __import__(toplevel)

prefix = os.path.join(module.__path__[0], prefix, realName)

for suffix in suffixes:
if suffix:
fn = "%s.%s" % (prefix, suffix)
else:
fn = prefix
if os.path.exists(fn):
if os.path.exists(fn):
return fn
except:
except Exception:
pass


def getObject(module, name, reload=0,
# The use of a mutable default is intentional here,
Expand All @@ -163,15 +164,15 @@ def getObject(module, name, reload=0,
else:
prefix = module

path = getPath('Extensions', prefix, suffixes=('','py','pyc'))
path = getPath('Extensions', prefix, suffixes=('', 'py', 'pyc'))
if path is None:
raise NotFound("The specified module, '%s', couldn't be found."
% module)
raise NotFound(
"The specified module, '%s', couldn't be found." % module)

__traceback_info__= path, module
__traceback_info__ = path, module

base, ext = os.path.splitext(path)
if ext=='.pyc':
if ext == '.pyc':
file = open(path, 'rb')
binmod = imp.load_compiled('Extension', path, file)
file.close()
Expand Down
Loading

0 comments on commit 006ee05

Please sign in to comment.