Completed
Pull Request — master (#138)
by
unknown
20:13
created

wechatpy.session.MemoryStorage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%
Metric Value
dl 0
loc 15
ccs 10
cts 11
cp 0.9091
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A MemoryStorage.set() 0 4 2
A MemoryStorage.get() 0 2 1
A MemoryStorage.delete() 0 2 1
A MemoryStorage.__init__() 0 2 1
1
# -*- coding: utf-8 -*-
2 10
from __future__ import absolute_import, unicode_literals
3 10
from wechatpy.session import SessionStorage
4
5
6 10
class MemoryStorage(SessionStorage):
7
8 10
    def __init__(self):
9 10
        self._data = {}
10
11 10
    def get(self, key, default=None):
12 10
        return self._data.get(key, default)
13
14 10
    def set(self, key, value, ttl=None):
15 10
        if value is None:
16 10
            return
17 10
        self._data[key] = value
18
19 10
    def delete(self, key):
20
        self._data.pop(key, None)
21