File size: 1,318 Bytes
2abfccb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from petrel_client.client_base import ClientBase
from petrel_client.common.io_profile import profile


class FakeClient(ClientBase):
    customized_get = None
    customized_put = None

    def __init__(self, client_type, conf, **kwargs):
        super(FakeClient, self).__init__(conf=conf, **kwargs)
        self.conf = conf
        self.type = client_type
        self.__enable_cache = conf.get_boolean(
            'enable_mc', False) or conf.get_boolean('enable_cache', False)

    @profile('get')
    def get(self, *args, **kwargs):
        if self.customized_get:
            return self.customized_get(*args, **kwargs)
        else:
            return b'data from FakeClient.'

    def get_with_info(self, *args, **kwargs):
        info = {}
        data = self.get(*args, **kwargs)
        return data, info

    @profile('put')
    def put(self, *args, **kwargs):
        if self.customized_put:
            return self.customized_put(*args, **kwargs)
        else:
            if self.type == 's3':
                body = args[3]
            else:
                body = args[1]
            return len(body)

    def put_with_info(self, *args, **kwargs):
        info = {}
        result = self.put(*args, **kwargs)
        return result, info

    def enable_cache(self):
        return self.__enable_cache