Skip to content

Commit

Permalink
Format code for PEP8 compliance.
Browse files Browse the repository at this point in the history
These changes format code by using:
```
$ black -l79
$ zimports
```

and some manual changes to format the code as PEP8 compliance

Closes: #146
Pull-request: #146
Pull-request-sha: 6920c1c

Change-Id: I6532b61d3163695e89c97e744b6a2061cd83a97e
  • Loading branch information
4383 authored and zzzeek committed Mar 4, 2019
1 parent 7c5b645 commit f88e9d3
Show file tree
Hide file tree
Showing 39 changed files with 1,250 additions and 1,046 deletions.
2 changes: 1 addition & 1 deletion dogpile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.7.2'
__version__ = "0.7.2"

from .lock import Lock # noqa
from .lock import NeedRegenerationException # noqa
6 changes: 4 additions & 2 deletions dogpile/cache/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from .region import CacheRegion, register_backend, make_region # noqa
from .region import CacheRegion # noqa
from .region import make_region # noqa
from .region import register_backend # noqa
from .. import __version__ # noqa

# backwards compat
from .. import __version__ # noqa
8 changes: 7 additions & 1 deletion dogpile/cache/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import operator

from ..util.compat import py3k


Expand All @@ -9,6 +10,7 @@ class NoValue(object):
should be used.
"""

@property
def payload(self):
return self
Expand All @@ -18,12 +20,15 @@ def __repr__(self):
fill another cache key.
"""
return '<dogpile.cache.api.NoValue object>'
return "<dogpile.cache.api.NoValue object>"

if py3k:

def __bool__(self): # pragma NO COVERAGE
return False

else:

def __nonzero__(self): # pragma NO COVERAGE
return False

Expand All @@ -44,6 +49,7 @@ class CachedValue(tuple):
the backend requires serialization.
"""

payload = property(operator.itemgetter(0))
"""Named accessor for the payload."""

Expand Down
36 changes: 24 additions & 12 deletions dogpile/cache/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,34 @@
register_backend = _backend_loader.register

register_backend(
"dogpile.cache.null", "dogpile.cache.backends.null", "NullBackend")
"dogpile.cache.null", "dogpile.cache.backends.null", "NullBackend"
)
register_backend(
"dogpile.cache.dbm", "dogpile.cache.backends.file", "DBMBackend")
"dogpile.cache.dbm", "dogpile.cache.backends.file", "DBMBackend"
)
register_backend(
"dogpile.cache.pylibmc", "dogpile.cache.backends.memcached",
"PylibmcBackend")
"dogpile.cache.pylibmc",
"dogpile.cache.backends.memcached",
"PylibmcBackend",
)
register_backend(
"dogpile.cache.bmemcached", "dogpile.cache.backends.memcached",
"BMemcachedBackend")
"dogpile.cache.bmemcached",
"dogpile.cache.backends.memcached",
"BMemcachedBackend",
)
register_backend(
"dogpile.cache.memcached", "dogpile.cache.backends.memcached",
"MemcachedBackend")
"dogpile.cache.memcached",
"dogpile.cache.backends.memcached",
"MemcachedBackend",
)
register_backend(
"dogpile.cache.memory", "dogpile.cache.backends.memory", "MemoryBackend")
"dogpile.cache.memory", "dogpile.cache.backends.memory", "MemoryBackend"
)
register_backend(
"dogpile.cache.memory_pickle", "dogpile.cache.backends.memory",
"MemoryPickleBackend")
"dogpile.cache.memory_pickle",
"dogpile.cache.backends.memory",
"MemoryPickleBackend",
)
register_backend(
"dogpile.cache.redis", "dogpile.cache.backends.redis", "RedisBackend")
"dogpile.cache.redis", "dogpile.cache.backends.redis", "RedisBackend"
)
54 changes: 30 additions & 24 deletions dogpile/cache/backends/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
"""

from __future__ import with_statement
from ..api import CacheBackend, NO_VALUE

from contextlib import contextmanager
from ...util import compat
from ... import util
import os

__all__ = 'DBMBackend', 'FileLock', 'AbstractFileLock'
from ..api import CacheBackend
from ..api import NO_VALUE
from ... import util
from ...util import compat

__all__ = ["DBMBackend", "FileLock", "AbstractFileLock"]


class DBMBackend(CacheBackend):
Expand Down Expand Up @@ -134,21 +137,24 @@ def release_write_lock(self):
"""

def __init__(self, arguments):
self.filename = os.path.abspath(
os.path.normpath(arguments['filename'])
os.path.normpath(arguments["filename"])
)
dir_, filename = os.path.split(self.filename)

self.lock_factory = arguments.get("lock_factory", FileLock)
self._rw_lock = self._init_lock(
arguments.get('rw_lockfile'),
".rw.lock", dir_, filename)
arguments.get("rw_lockfile"), ".rw.lock", dir_, filename
)
self._dogpile_lock = self._init_lock(
arguments.get('dogpile_lockfile'),
arguments.get("dogpile_lockfile"),
".dogpile.lock",
dir_, filename,
util.KeyReentrantMutex.factory)
dir_,
filename,
util.KeyReentrantMutex.factory,
)

# TODO: make this configurable
if compat.py3k:
Expand All @@ -163,9 +169,8 @@ def _init_lock(self, argument, suffix, basedir, basefile, wrapper=None):
lock = self.lock_factory(os.path.join(basedir, basefile + suffix))
elif argument is not False:
lock = self.lock_factory(
os.path.abspath(
os.path.normpath(argument)
))
os.path.abspath(os.path.normpath(argument))
)
else:
return None
if wrapper:
Expand All @@ -175,12 +180,12 @@ def _init_lock(self, argument, suffix, basedir, basefile, wrapper=None):
def _init_dbm_file(self):
exists = os.access(self.filename, os.F_OK)
if not exists:
for ext in ('db', 'dat', 'pag', 'dir'):
for ext in ("db", "dat", "pag", "dir"):
if os.access(self.filename + os.extsep + ext, os.F_OK):
exists = True
break
if not exists:
fh = self.dbmmodule.open(self.filename, 'c')
fh = self.dbmmodule.open(self.filename, "c")
fh.close()

def get_mutex(self, key):
Expand Down Expand Up @@ -210,15 +215,13 @@ def _use_rw_lock(self, write):
@contextmanager
def _dbm_file(self, write):
with self._use_rw_lock(write):
dbm = self.dbmmodule.open(
self.filename,
"w" if write else "r")
dbm = self.dbmmodule.open(self.filename, "w" if write else "r")
yield dbm
dbm.close()

def get(self, key):
with self._dbm_file(False) as dbm:
if hasattr(dbm, 'get'):
if hasattr(dbm, "get"):
value = dbm.get(key, NO_VALUE)
else:
# gdbm objects lack a .get method
Expand All @@ -235,14 +238,16 @@ def get_multi(self, keys):

def set(self, key, value):
with self._dbm_file(True) as dbm:
dbm[key] = compat.pickle.dumps(value,
compat.pickle.HIGHEST_PROTOCOL)
dbm[key] = compat.pickle.dumps(
value, compat.pickle.HIGHEST_PROTOCOL
)

def set_multi(self, mapping):
with self._dbm_file(True) as dbm:
for key, value in mapping.items():
dbm[key] = compat.pickle.dumps(value,
compat.pickle.HIGHEST_PROTOCOL)
dbm[key] = compat.pickle.dumps(
value, compat.pickle.HIGHEST_PROTOCOL
)

def delete(self, key):
with self._dbm_file(True) as dbm:
Expand Down Expand Up @@ -398,11 +403,12 @@ def __init__(self, filename):
@util.memoized_property
def _module(self):
import fcntl

return fcntl

@property
def is_open(self):
return hasattr(self._filedescriptor, 'fileno')
return hasattr(self._filedescriptor, "fileno")

def acquire_read_lock(self, wait):
return self._acquire(wait, os.O_RDONLY, self._module.LOCK_SH)
Expand Down
Loading

0 comments on commit f88e9d3

Please sign in to comment.