Total Complexity | 8 |
Total Lines | 29 |
Duplicated Lines | 0 % |
Coverage | 69.57% |
1 | # -*- coding: utf-8 -*- |
||
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 |