Skip to content

Commit

Permalink
Separate Ring & Wire - Ring is now based on WireRope
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed Jun 12, 2018
1 parent c7e0269 commit ab2519e
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 246 deletions.
10 changes: 5 additions & 5 deletions ring/callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class Callable(object):
"""A wrapper of :class:`inspect.Signature` including more information of callable."""
"""A wrapper object including more information of callables."""

def __init__(self, f):
self.wrapped_object = f
Expand Down Expand Up @@ -72,8 +72,8 @@ def is_method(self):
:param ring.callable.Callable c: A callable object.
:rtype: bool
:note: The test is not based on python state but based on parameter name
`self`. The test result might be wrong.
:note: The test is not based on python state but based on parameter
name `self`. The test result might be wrong.
"""
if six.PY34:
if self.is_barefunction:
Expand Down Expand Up @@ -193,8 +193,8 @@ def kwargify(self, args, kwargs, bound_args=()):

@cached_property
def identifier(self):
return '.'.join(
(self.wrapped_callable.__module__, qualname(self.wrapped_callable)))
return '.'.join((
self.wrapped_callable.__module__, qualname(self.wrapped_callable)))

@cached_property
def first_parameter(self):
Expand Down
16 changes: 9 additions & 7 deletions ring/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def get(self, wire, request, *args, **kwargs):
return result
# no 'precess_view' in CacheMiddleware
# if hasattr(middleware, 'process_view'):
# result = middleware.process_view(request, view_func, args, kwargs)
# if result is not None:
# return result
# result = middleware.process_view(request, view_func, args, kwargs)
# if result is not None:
# return result
return self.ring.miss_value

@fbase.interface_attrs(
Expand Down Expand Up @@ -204,7 +204,7 @@ def cache(
.. _`Django's cache framework: Setting up the cache`: https://docs.djangoproject.com/en/2.0/topics/cache/#setting-up-the-cache
.. _`Django's cache framework: The low-level cache API`: https://docs.djangoproject.com/en/2.0/topics/cache/#the-low-level-cache-api
"""
""" # noqa
backend = promote_backend(backend)
return fbase.factory(
backend, key_prefix=key_prefix, on_manufactured=None,
Expand All @@ -216,10 +216,12 @@ def cache(

def cache_page(
timeout, cache=None, key_prefix=None, # original parameters
user_interface=CachePageUserInterface, storage_class=fbase.BaseStorage):
user_interface=CachePageUserInterface,
storage_class=fbase.BaseStorage):
"""The drop-in-replacement of Django's per-view cache.
Use this decorator instead of :func:`django.views.decorators.cache.cache_page`.
Use this decorator instead of
:func:`django.views.decorators.cache.cache_page`.
The decorated view function itself is compatible. Ring decorated function
additionally have ring-styled sub-functions. In the common cases, `delete`
and `update` are helpful.
Expand Down Expand Up @@ -267,7 +269,7 @@ def article_post_django(request):
:see: `Django's cache framework: The per-view cache <https://docs.djangoproject.com/en/2.0/topics/cache/#the-per-view-cache>`_
:see: :func:`django.views.decorators.cache.cache_page`.
"""
""" # noqa
middleware_class = CacheMiddleware
middleware = middleware_class(
cache_timeout=timeout, cache_alias=cache, key_prefix=key_prefix)
Expand Down
23 changes: 12 additions & 11 deletions ring/func_asyncio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""":mod:`ring.func_asyncio` --- a collection of :mod:`asyncio` factory functions.
""":mod:`ring.func_asyncio` --- collection of :mod:`asyncio` factory functions.
This module includes building blocks and storage implementations of **Ring**
factories for :mod:`asyncio`.
Expand All @@ -18,8 +18,8 @@
type_dict = dict


def factory_doctor(wire_frame, ring) -> None:
callable = ring.callable
def factory_doctor(wire_rope) -> None:
callable = wire_rope.callable
if not callable.is_coroutine:
raise TypeError(
"The function for cache '{}' must be an async function.".format(
Expand Down Expand Up @@ -206,7 +206,7 @@ def get_many(self, keys, miss_value):
"""Get and return values for the given key."""
values = yield from self.get_many_values(keys)
results = [
self.ring.coder.decode(v) if v is not fbase.NotFound else miss_value
self.ring.coder.decode(v) if v is not fbase.NotFound else miss_value # noqa
for v in values]
return results

Expand Down Expand Up @@ -315,7 +315,8 @@ def delete_many_values(self, keys):
raise NotImplementedError("aiomcache doesn't support delete_multi.")


class AioredisStorage(CommonMixinStorage, fbase.StorageMixin, BulkStorageMixin):
class AioredisStorage(
CommonMixinStorage, fbase.StorageMixin, BulkStorageMixin):
"""Storage implementation for :class:`aioredis.Redis`."""

@asyncio.coroutine
Expand Down Expand Up @@ -403,12 +404,12 @@ def aiomcache(
Expected client package is aiomcache_.
aiomcache expect `Memcached` client or dev package is installed on your
machine. If you are new to Memcached, check how to install it and the python
package on your platform.
machine. If you are new to Memcached, check how to install it and the
python package on your platform.
:param aiomcache.Client client: aiomcache client object.
:param object key_refactor: The default key refactor may hash the cache key
when it doesn't meet memcached key restriction.
:param object key_refactor: The default key refactor may hash the cache
key when it doesn't meet memcached key restriction.
:see: :func:`ring.func_asyncio.CacheUserInterface` for single access
sub-functions.
Expand Down Expand Up @@ -442,8 +443,8 @@ def aioredis(
Expected client package is aioredis_.
aioredis expect `Redis` client or dev package is installed on your
machine. If you are new to Memcached, check how to install it and the python
package on your platform.
machine. If you are new to Memcached, check how to install it and the
python package on your platform.
Note that aioredis>=1.0.0 only supported.
Expand Down
Loading

0 comments on commit ab2519e

Please sign in to comment.