Completed
Push — master ( e6b198...e30f90 )
by Messense
11:09 queued 10:06
created

wechatpy.session.ShoveStorage.delete()   A

Complexity

Conditions 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 4.3145
Metric Value
cc 2
dl 0
loc 6
ccs 1
cts 6
cp 0.1666
crap 4.3145
rs 9.4285
1
# -*- coding: utf-8 -*-
2 9
from __future__ import absolute_import, unicode_literals
3 9
from wechatpy.session import SessionStorage
4
5
6 9
class ShoveStorage(SessionStorage):
7
8 9
    def __init__(self, shove, prefix='wechatpy'):
9 9
        self.shove = shove
10 9
        self.prefix = prefix
11
12 9
    def key_name(self, key):
13 9
        return '{0}:{1}'.format(self.prefix, key)
14
15 9
    def get(self, key, default=None):
16 9
        key = self.key_name(key)
17 9
        try:
18 9
            return self.shove[key]
19
        except KeyError:
20
            return default
21
22 9
    def set(self, key, value, ttl=None):
23 9
        if value is None:
24 9
            return
25
26 9
        key = self.key_name(key)
27 9
        self.shove[key] = value
28
29 9
    def delete(self, key):
30
        key = self.key_name(key)
31
        try:
32
            del self.shove[key]
33
        except KeyError:
34
            pass
35