コード例 #1
0
ファイル: cache.py プロジェクト: lecram/beaker
        def cached(*args):
            if not cache[0]:
                if region is not None:
                    if region not in cache_regions:
                        raise BeakerException(
                            'Cache region not configured: %s' % region)
                    reg = cache_regions[region]
                    if not reg.get('enabled', True):
                        return func(*args)
                    cache[0] = Cache._get_cache(namespace, reg)
                elif manager:
                    cache[0] = manager.get_cache(namespace, **kwargs)
                else:
                    raise Exception("'manager + kwargs' or 'region' "
                                    "argument is required")

            if skip_self:
                allargs = deco_args + args[1:]
            else:
                allargs = deco_args + args
            cache_key = " ".join(map(util.text_type, allargs))
            cache_key = cache_key.encode("utf8")
            if region:
                key_length = cache_regions[region]['key_length']
            else:
                key_length = kwargs.pop('key_length', 250)
            if len(cache_key) + len(namespace) > int(key_length):
                cache_key = sha1(cache_key).hexdigest()

            def go():
                return func(*args)

            return cache[0].get_value(cache_key, createfunc=go)
コード例 #2
0
ファイル: cache.py プロジェクト: stevenkampen/Bolognium
def _cache_decorator_invalidate(cache, key_length, args):
    """Invalidate a cache key based on function arguments."""

    cache_key = " ".join(map(str, args))
    if len(cache_key) > key_length:
        cache_key = sha1(cache_key).hexdigest()
    cache.remove_value(cache_key)
コード例 #3
0
ファイル: cache.py プロジェクト: isabella232/beaker-1
def _cache_decorator_invalidate(cache, key_length, args):
    """Invalidate a cache key based on function arguments."""

    cache_key = u_(" ").join(map(u_, args))
    if len(cache_key) + len(cache.namespace_name) > key_length:
        cache_key = sha1(cache_key.encode("utf-8")).hexdigest()
    cache.remove_value(cache_key)
コード例 #4
0
ファイル: memcached.py プロジェクト: jureslak/ankete
 def _format_key(self, key):
     if not isinstance(key, str):
         key = key.decode('ascii')
     formated_key = (self.namespace + '_' + key).replace(' ', '\302\267')
     if len(formated_key) > MAX_KEY_LENGTH:
         formated_key = sha1(formated_key).hexdigest()
     return formated_key
コード例 #5
0
ファイル: memcached.py プロジェクト: spoqa/beaker
 def _format_key(self, key):
     if not isinstance(key, str):
         key = key.decode("ascii")
     formated_key = (self.namespace + "_" + key).replace(" ", "\302\267")
     if len(formated_key) > MAX_KEY_LENGTH:
         formated_key = sha1(formated_key).hexdigest()
     return formated_key
コード例 #6
0
ファイル: cache.py プロジェクト: bbangert/beaker
def _cache_decorator_invalidate(cache, key_length, args):
    """Invalidate a cache key based on function arguments."""

    cache_key = u_(" ").join(map(u_, args))
    if len(cache_key) + len(cache.namespace_name) > key_length:
        cache_key = sha1(cache_key.encode("utf-8")).hexdigest()
    cache.remove_value(cache_key)
コード例 #7
0
ファイル: memcached.py プロジェクト: sakurazuka/Lesson20
 def _format_key(self, key):
     if not isinstance(key, str):
         key = key.decode('ascii')
     formated_key = (self.namespace + '_' + key).replace(' ', '\302\267')
     if len(formated_key) > MAX_KEY_LENGTH:
         formated_key = sha1(formated_key).hexdigest()
     return formated_key
コード例 #8
0
ファイル: redisnm.py プロジェクト: phamkhanh07/django
 def _format_key(self, key):
     if not isinstance(key, str):
         key = key.decode('ascii')
     if len(key) > (self.MAX_KEY_LENGTH - len(self.namespace) - len('beaker_cache:') - 1):
         if not PY2:
             key = key.encode('utf-8')
         key = sha1(key).hexdigest()
     return 'beaker_cache:%s:%s' % (self.namespace, key)
コード例 #9
0
ファイル: mongodb.py プロジェクト: Madhuri8090/my-first-blog1
 def _format_key(self, key):
     if not isinstance(key, str):
         key = key.decode('ascii')
     if len(key) > (self.MAX_KEY_LENGTH - len(self.namespace) - 1):
         if not PY2:
             key = key.encode('utf-8')
         key = sha1(key).hexdigest()
     return '%s:%s' % (self.namespace, key)
コード例 #10
0
ファイル: redisnm.py プロジェクト: isabella232/beaker-1
 def _format_key(self, key):
     if not isinstance(key, str):
         key = key.decode("ascii")
     if len(key) > (self.MAX_KEY_LENGTH - len(self.namespace) -
                    len("beaker_cache:") - 1):
         if not PY2:
             key = key.encode("utf-8")
         key = sha1(key).hexdigest()
     return "beaker_cache:%s:%s" % (self.namespace, key)
コード例 #11
0
 def _format_key(self, key):
     if not isinstance(key, str):
         key = key.decode("ascii")
     formated_key = (self.namespace + "_" + key).replace(" ", "\302\267")
     if len(formated_key) > MAX_KEY_LENGTH:
         if not PY2:
             formated_key = formated_key.encode("utf-8")
         formated_key = sha1(formated_key).hexdigest()
     return formated_key
コード例 #12
0
ファイル: cache.py プロジェクト: 3DMeny/pyload
def _cache_decorator_invalidate(cache, key_length, args):
    """Invalidate a cache key based on function arguments."""

    try:
        cache_key = " ".join(map(str, args))
    except UnicodeEncodeError:
        cache_key = " ".join(map(unicode, args))
    if len(cache_key) + len(cache.namespace_name) > key_length:
        cache_key = sha1(cache_key).hexdigest()
    cache.remove_value(cache_key)
コード例 #13
0
def _cache_decorator_invalidate(cache, key_length, args):
    """Invalidate a cache key based on function arguments."""

    try:
        cache_key = " ".join(map(str, args))
    except UnicodeEncodeError:
        cache_key = " ".join(map(str, args))
    if len(cache_key) + len(cache.namespace_name) > key_length:
        cache_key = sha1(cache_key).hexdigest()
    cache.remove_value(cache_key)
コード例 #14
0
    def _set_password(self, password):
        """Hash password on the fly."""
        if isinstance(password, unicode):
            password_8bit = password.encode('UTF-8')
        else:
            password_8bit = password

        salt = sha1()
        salt.update(os.urandom(60))
        hash = sha1()
        hash.update(password_8bit + salt.hexdigest())
        hashed_password = salt.hexdigest() + hash.hexdigest()

        # Make sure the hased password is an UTF-8 object at the end of the
        # process because SQLAlchemy _wants_ a unicode object for Unicode
        # fields
        if not isinstance(hashed_password, unicode):
            hashed_password = hashed_password.decode('UTF-8')

        self.password = hashed_password
コード例 #15
0
ファイル: __init__.py プロジェクト: Kentzo/BZD-tests
    def _set_password(self, password):
        """Hash password on the fly."""
        if isinstance(password, unicode):
            password_8bit = password.encode('UTF-8')
        else:
            password_8bit = password

        salt = sha1()
        salt.update(os.urandom(60))
        hash = sha1()
        hash.update(password_8bit + salt.hexdigest())
        hashed_password = salt.hexdigest() + hash.hexdigest()

        # Make sure the hased password is an UTF-8 object at the end of the
        # process because SQLAlchemy _wants_ a unicode object for Unicode
        # fields
        if not isinstance(hashed_password, unicode):
            hashed_password = hashed_password.decode('UTF-8')

        self.password = hashed_password
コード例 #16
0
        def cached(*args, **kwargs):
            if not cache[0]:
                if region is not None:
                    if region not in cache_regions:
                        raise BeakerException(
                            'Cache region not configured: %s' % region)
                    reg = cache_regions[region]
                    if not reg.get('enabled', True):
                        return func(*args, **kwargs)
                    cache[0] = Cache._get_cache(namespace, reg)
                elif manager:
                    cache[0] = manager.get_cache(namespace, **options)
                else:
                    raise Exception("'manager + kwargs' or 'region' "
                                    "argument is required")

            cache_key_kwargs = []
            if kwargs:
                # kwargs provided, merge them in positional args
                # to avoid having different cache keys.
                args, kwargs = bindfuncargs(signature, args, kwargs)
                cache_key_kwargs = [
                    u_(':').join((u_(key), u_(value)))
                    for key, value in kwargs.items()
                ]

            cache_key_args = args
            if skip_self:
                cache_key_args = args[1:]

            cache_key = u_(" ").join(
                map(u_, chain(deco_args, cache_key_args, cache_key_kwargs)))

            if region:
                cachereg = cache_regions[region]
                key_length = cachereg.get('key_length',
                                          util.DEFAULT_CACHE_KEY_LENGTH)
            else:
                key_length = options.pop('key_length',
                                         util.DEFAULT_CACHE_KEY_LENGTH)

            # TODO: This is probably a bug as length is checked before converting to UTF8
            # which will cause cache_key to grow in size.
            if len(cache_key) + len(namespace) > int(key_length):
                cache_key = sha1(cache_key.encode('utf-8')).hexdigest()

            def go():
                return func(*args, **kwargs)

            # save org function name
            go.__name__ = '_cached_%s' % (func.__name__, )

            return cache[0].get_value(cache_key, createfunc=go)
コード例 #17
0
ファイル: __init__.py プロジェクト: Kentzo/BZD-tests
    def validate_password(self, password):
        """
        Check the password against existing credentials.

        :param password: the password that was provided by the user to
            try and authenticate. This is the clear text version that we will
            need to match against the hashed one in the database.
        :type password: unicode object.
        :return: Whether the password is valid.
        :rtype: bool

        """
        hashed_pass = sha1()
        hashed_pass.update(password + self.password[:40])
        return self.password[40:] == hashed_pass.hexdigest()
コード例 #18
0
    def validate_password(self, password):
        """
        Check the password against existing credentials.

        :param password: the password that was provided by the user to
            try and authenticate. This is the clear text version that we will
            need to match against the hashed one in the database.
        :type password: unicode object.
        :return: Whether the password is valid.
        :rtype: bool

        """
        hashed_pass = sha1()
        hashed_pass.update(password + self.password[:40])
        return self.password[40:] == hashed_pass.hexdigest()
コード例 #19
0
ファイル: cache.py プロジェクト: assembl/beaker
        def cached(*args, **kwargs):
            if not cache[0]:
                if region is not None:
                    if region not in cache_regions:
                        raise BeakerException(
                            'Cache region not configured: %s' % region)
                    reg = cache_regions[region]
                    if not reg.get('enabled', True):
                        return func(*args, **kwargs)
                    cache[0] = Cache._get_cache(namespace, reg)
                elif manager:
                    cache[0] = manager.get_cache(namespace, **options)
                else:
                    raise Exception("'manager + kwargs' or 'region' "
                                    "argument is required")

            cache_key_kwargs = []
            if kwargs:
                # kwargs provided, merge them in positional args
                # to avoid having different cache keys.
                args, kwargs = bindfuncargs(signature, args, kwargs)
                cache_key_kwargs = [u_(':').join((u_(key), u_(value))) for key, value in kwargs.items()]

            cache_key_args = args
            if skip_self:
                cache_key_args = args[1:]

            cache_key = u_(" ").join(map(u_, chain(deco_args, cache_key_args, cache_key_kwargs)))

            if region:
                cachereg = cache_regions[region]
                key_length = cachereg.get('key_length', util.DEFAULT_CACHE_KEY_LENGTH)
            else:
                key_length = options.pop('key_length', util.DEFAULT_CACHE_KEY_LENGTH)

            # TODO: This is probably a bug as length is checked before converting to UTF8
            # which will cause cache_key to grow in size.
            if len(cache_key) + len(namespace) > int(key_length):
                cache_key = sha1(cache_key.encode('utf-8')).hexdigest()

            def go():
                return func(*args, **kwargs)
            # save org function name
            go.__name__ = '_cached_%s' % (func.__name__,)

            return cache[0].get_value(cache_key, createfunc=go)
コード例 #20
0
ファイル: cache.py プロジェクト: Skuu/AppSistem
        def cached(*args):
            if not cache[0]:
                if region is not None:
                    if region not in cache_regions:
                        raise BeakerException(
                            'Cache region not configured: %s' % region)
                    reg = cache_regions[region]
                    if not reg.get('enabled', True):
                        return func(*args)
                    cache[0] = Cache._get_cache(namespace, reg)
                elif manager:
                    cache[0] = manager.get_cache(namespace, **kwargs)
                else:
                    raise Exception("'manager + kwargs' or 'region' "
                                    "argument is required")

            if skip_self:
                try:
                    cache_key = " ".join(map(str, deco_args + args[1:]))
                except UnicodeEncodeError:
                    cache_key = " ".join(map(unicode, deco_args + args[1:]))
            else:
                try:
                    cache_key = " ".join(map(str, deco_args + args))
                except UnicodeEncodeError:
                    cache_key = " ".join(map(unicode, deco_args + args))
            if region:
                cachereg = cache_regions[region]
                key_length = cachereg.get('key_length', util.DEFAULT_CACHE_KEY_LENGTH)
            else:
                key_length = kwargs.pop('key_length', util.DEFAULT_CACHE_KEY_LENGTH)
            if len(cache_key) + len(namespace) > int(key_length):
                if util.py3k:
                    cache_key = cache_key.encode('utf-8')
                cache_key = sha1(cache_key).hexdigest()

            def go():
                return func(*args)

            return cache[0].get_value(cache_key, createfunc=go)
コード例 #21
0
        def cached(*args):
            if not cache[0]:
                if region is not None:
                    if region not in cache_regions:
                        raise BeakerException(
                            'Cache region not configured: %s' % region)
                    reg = cache_regions[region]
                    if not reg.get('enabled', True):
                        return func(*args)
                    cache[0] = Cache._get_cache(namespace, reg)
                elif manager:
                    cache[0] = manager.get_cache(namespace, **kwargs)
                else:
                    raise Exception("'manager + kwargs' or 'region' "
                                    "argument is required")

            if skip_self:
                try:
                    cache_key = " ".join(map(str, deco_args + args[1:]))
                except UnicodeEncodeError:
                    cache_key = " ".join(map(unicode, deco_args + args[1:]))
            else:
                try:
                    cache_key = " ".join(map(str, deco_args + args))
                except UnicodeEncodeError:
                    cache_key = " ".join(map(unicode, deco_args + args))
            if region:
                key_length = cache_regions[region]['key_length']
            else:
                key_length = kwargs.pop('key_length', 250)
            if len(cache_key) + len(namespace) > int(key_length):
                if util.py3k:
                    cache_key = cache_key.encode('utf-8')
                cache_key = sha1(cache_key).hexdigest()

            def go():
                return func(*args)

            return cache[0].get_value(cache_key, createfunc=go)
コード例 #22
0
        def cached(*args):
            if not cache[0]:
                if region is not None:
                    if region not in cache_regions:
                        raise BeakerException(
                            'Cache region not configured: %s' % region)
                    reg = cache_regions[region]
                    if not reg.get('enabled', True):
                        return func(*args)
                    cache[0] = Cache._get_cache(namespace, reg)
                elif manager:
                    cache[0] = manager.get_cache(namespace, **kwargs)
                else:
                    raise Exception("'manager + kwargs' or 'region' "
                                    "argument is required")

            cache_key_args = args
            if skip_self:
                cache_key_args = args[1:]
            cache_key = u_(" ").join(map(u_, deco_args + cache_key_args))

            if region:
                cachereg = cache_regions[region]
                key_length = cachereg.get('key_length',
                                          util.DEFAULT_CACHE_KEY_LENGTH)
            else:
                key_length = kwargs.pop('key_length',
                                        util.DEFAULT_CACHE_KEY_LENGTH)

            # TODO: This is probably a bug as length is checked before converting to UTF8
            # which will cause cache_key to grow in size.
            if len(cache_key) + len(namespace) > int(key_length):
                cache_key = sha1(cache_key.encode('utf-8')).hexdigest()

            def go():
                return func(*args)

            return cache[0].get_value(cache_key, createfunc=go)
コード例 #23
0
ファイル: cache.py プロジェクト: jheld/beaker
        def cached(*args):
            if not cache[0]:
                if region is not None:
                    if region not in cache_regions:
                        raise BeakerException(
                            'Cache region not configured: %s' % region)
                    reg = cache_regions[region]
                    if not reg.get('enabled', True):
                        return func(*args)
                    cache[0] = Cache._get_cache(namespace, reg)
                elif manager:
                    cache[0] = manager.get_cache(namespace, **kwargs)
                else:
                    raise Exception("'manager + kwargs' or 'region' "
                                    "argument is required")

            cache_key_args = args
            if skip_self:
                cache_key_args = args[1:]
            cache_key = u_(" ").join(map(u_, deco_args + cache_key_args))

            if region:
                cachereg = cache_regions[region]
                key_length = cachereg.get('key_length', util.DEFAULT_CACHE_KEY_LENGTH)
            else:
                key_length = kwargs.pop('key_length', util.DEFAULT_CACHE_KEY_LENGTH)

            # TODO: This is probably a bug as length is checked before converting to UTF8
            # which will cause cache_key to grow in size.
            if len(cache_key) + len(namespace) > int(key_length):
                cache_key = sha1(cache_key.encode('utf-8')).hexdigest()

            def go():
                return func(*args)

            return cache[0].get_value(cache_key, createfunc=go)
コード例 #24
0
 def _format_key(self, key):
     formated_key = self.namespace + '_' + key.replace(' ', '\302\267')
     if len(formated_key) > MAX_KEY_LENGTH:
         formated_key = sha1(formated_key).hexdigest()
     return formated_key
コード例 #25
0
ファイル: memcached.py プロジェクト: jellonek/beaker
 def _format_key(self, key):
     formated_key = self.namespace + "_" + key.replace(" ", "\302\267")
     if len(formated_key) > MAX_KEY_LENGTH:
         formated_key = sha1(formated_key).hexdigest()
     return formated_key
コード例 #26
0
ファイル: memcached.py プロジェクト: XingjianXu/ptcoding
 def _format_key(self, key):
     formated_key = self.namespace + '_' + key.replace(' ', '\302\267')
     if len(formated_key) > MAX_KEY_LENGTH:
         formated_key = sha1(formated_key).hexdigest()
     return formated_key