diff --git a/rhodecode/lib/rc_cache/backends.py b/rhodecode/lib/rc_cache/backends.py --- a/rhodecode/lib/rc_cache/backends.py +++ b/rhodecode/lib/rc_cache/backends.py @@ -23,20 +23,20 @@ import errno import logging import msgpack +import redis import gevent -import redis from dogpile.cache.api import CachedValue from dogpile.cache.backends import memory as memory_backend from dogpile.cache.backends import file as file_backend from dogpile.cache.backends import redis as redis_backend -from dogpile.cache.backends.file import NO_VALUE, compat, FileLock +from dogpile.cache.backends.file import NO_VALUE, FileLock from dogpile.cache.util import memoized_property from pyramid.settings import asbool from rhodecode.lib.memory_lru_dict import LRUDict, LRUDictDebug -from rhodecode.lib.utils import safe_str, safe_unicode +from rhodecode.lib.utils import safe_str _default_max_size = 1024 @@ -74,7 +74,7 @@ class PickleSerializer(object): def _dumps(self, value, safe=False): try: - return compat.pickle.dumps(value) + return pickle.dumps(value) except Exception: if safe: return NO_VALUE @@ -83,7 +83,7 @@ class PickleSerializer(object): def _loads(self, value, safe=True): try: - return compat.pickle.loads(value) + return pickle.loads(value) except Exception: if safe: return NO_VALUE @@ -187,7 +187,7 @@ class FileNamespaceBackend(PickleSeriali with self._dbm_file(True) as dbm: try: - return filter(cond, dbm.keys()) + return list(filter(cond, list(dbm.keys()))) except Exception: log.error('Failed to fetch DBM keys from DB: %s', self.get_store()) raise @@ -300,7 +300,7 @@ class BaseRedisBackend(redis_backend.Red def get_mutex(self, key): if self.distributed_lock: - lock_key = u'_lock_{0}'.format(safe_unicode(key)) + lock_key = '_lock_{0}'.format(safe_str(key)) return get_mutex_lock(self.client, lock_key, self._lock_timeout, auto_renewal=self._lock_auto_renewal) else: diff --git a/rhodecode/lib/rc_cache/utils.py b/rhodecode/lib/rc_cache/utils.py --- a/rhodecode/lib/rc_cache/utils.py +++ b/rhodecode/lib/rc_cache/utils.py @@ -21,13 +21,13 @@ import os import time import logging import functools +import decorator import threading from dogpile.cache import CacheRegion -from dogpile.cache.util import compat import rhodecode -from rhodecode.lib.utils import safe_str, sha1 +from rhodecode.lib.utils import safe_bytes, sha1 from rhodecode.lib.utils2 import safe_unicode, str2bool from rhodecode.model.db import Session, CacheKey, IntegrityError @@ -50,7 +50,7 @@ class RhodeCodeCacheRegion(CacheRegion): self, namespace=None, expiration_time=None, should_cache_fn=None, - to_str=compat.string_type, + to_str=str, function_key_generator=None, condition=True): """ @@ -58,74 +58,19 @@ class RhodeCodeCacheRegion(CacheRegion): condition isn't meet. This works a bit different than should_cache_fn And it's faster in cases we don't ever want to compute cached values """ - expiration_time_is_callable = compat.callable(expiration_time) + expiration_time_is_callable = callable(expiration_time) if function_key_generator is None: function_key_generator = self.function_key_generator - # workaround for py2 and cython problems, this block should be removed - # once we've migrated to py3 - if 'cython' == 'cython': - def decorator(fn): - if to_str is compat.string_type: - # backwards compatible - key_generator = function_key_generator(namespace, fn) - else: - key_generator = function_key_generator(namespace, fn, to_str=to_str) - - @functools.wraps(fn) - def decorate(*arg, **kw): - key = key_generator(*arg, **kw) - - @functools.wraps(fn) - def creator(): - return fn(*arg, **kw) - - if not condition: - return creator() - - timeout = expiration_time() if expiration_time_is_callable \ - else expiration_time - - return self.get_or_create(key, creator, timeout, should_cache_fn) - - def invalidate(*arg, **kw): - key = key_generator(*arg, **kw) - self.delete(key) - - def set_(value, *arg, **kw): - key = key_generator(*arg, **kw) - self.set(key, value) - - def get(*arg, **kw): - key = key_generator(*arg, **kw) - return self.get(key) - - def refresh(*arg, **kw): - key = key_generator(*arg, **kw) - value = fn(*arg, **kw) - self.set(key, value) - return value - - decorate.set = set_ - decorate.invalidate = invalidate - decorate.refresh = refresh - decorate.get = get - decorate.original = fn - decorate.key_generator = key_generator - decorate.__wrapped__ = fn - - return decorate - return decorator - def get_or_create_for_user_func(key_generator, user_func, *arg, **kw): if not condition: - log.debug('Calling un-cached method:%s', user_func.func_name) + log.debug('Calling un-cached method:%s', user_func.__name__) start = time.time() result = user_func(*arg, **kw) total = time.time() - start - log.debug('un-cached method:%s took %.4fs', user_func.func_name, total) + log.debug('un-cached method:%s took %.4fs', user_func.__name__, total) return result key = key_generator(*arg, **kw) @@ -133,11 +78,11 @@ class RhodeCodeCacheRegion(CacheRegion): timeout = expiration_time() if expiration_time_is_callable \ else expiration_time - log.debug('Calling cached method:`%s`', user_func.func_name) + log.debug('Calling cached method:`%s`', user_func.__name__) return self.get_or_create(key, user_func, timeout, should_cache_fn, (arg, kw)) def cache_decorator(user_func): - if to_str is compat.string_type: + if to_str is str: # backwards compatible key_generator = function_key_generator(namespace, user_func) else: @@ -200,7 +145,7 @@ def compute_key_from_params(*args): """ Helper to compute key from given params to be used in cache manager """ - return sha1("_".join(map(safe_str, args))) + return sha1(safe_bytes("_".join(map(str, args)))) def backend_key_generator(backend): @@ -232,7 +177,7 @@ def get_or_create_region(region_name, re if not region_obj: raise EnvironmentError( 'Region `{}` not in configured: {}.'.format( - region_name, region_meta.dogpile_cache_regions.keys())) + region_name, list(region_meta.dogpile_cache_regions.keys()))) region_uid_name = '{}:{}'.format(region_name, region_namespace) if isinstance(region_obj.actual_backend, FileNamespaceBackend): diff --git a/rhodecode/lib/vcs/__init__.py b/rhodecode/lib/vcs/__init__.py --- a/rhodecode/lib/vcs/__init__.py +++ b/rhodecode/lib/vcs/__init__.py @@ -24,8 +24,7 @@ for Python. Build with server client arc """ import atexit import logging -import urlparse -from cStringIO import StringIO +from io import StringIO import rhodecode from rhodecode.lib.vcs.conf import settings @@ -33,10 +32,6 @@ from rhodecode.lib.vcs.backends import g from rhodecode.lib.vcs.exceptions import ( VCSError, RepositoryError, CommitError, VCSCommunicationError) -VERSION = (0, 5, 0, 'dev') - -__version__ = '.'.join((str(each) for each in VERSION[:4])) - __all__ = [ 'get_version', 'get_vcs_instance', 'get_backend', 'VCSError', 'RepositoryError', 'CommitError', 'VCSCommunicationError'