diff --git a/rhodecode/authentication/base.py b/rhodecode/authentication/base.py --- a/rhodecode/authentication/base.py +++ b/rhodecode/authentication/base.py @@ -28,9 +28,9 @@ import logging import time import traceback import warnings +import functools from pyramid.threadlocal import get_current_registry -from sqlalchemy.ext.hybrid import hybrid_property from rhodecode.authentication.interface import IAuthnPluginRegistry from rhodecode.authentication.schema import AuthnPluginSettingsSchemaBase @@ -52,6 +52,31 @@ VCS_TYPE = 'vcs' HTTP_TYPE = 'http' +class hybrid_property(object): + """ + a property decorator that works both for instance and class + """ + def __init__(self, fget, fset=None, fdel=None, expr=None): + self.fget = fget + self.fset = fset + self.fdel = fdel + self.expr = expr or fget + functools.update_wrapper(self, fget) + + def __get__(self, instance, owner): + if instance is None: + return self.expr(owner) + else: + return self.fget(instance) + + def __set__(self, instance, value): + self.fset(instance, value) + + def __delete__(self, instance): + self.fdel(instance) + + + class LazyFormencode(object): def __init__(self, formencode_obj, *args, **kwargs): self.formencode_obj = formencode_obj diff --git a/rhodecode/tests/auth_external_test.py b/rhodecode/tests/auth_external_test.py --- a/rhodecode/tests/auth_external_test.py +++ b/rhodecode/tests/auth_external_test.py @@ -27,8 +27,8 @@ rhodecode.tests.auth_external_test import logging import traceback -from rhodecode.authentication.base import RhodeCodeExternalAuthPlugin -from sqlalchemy.ext.hybrid import hybrid_property +from rhodecode.authentication.base import ( + RhodeCodeExternalAuthPlugin, hybrid_property) from rhodecode.model.db import User from rhodecode.lib.ext_json import formatted_json