Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

# -*- coding: utf-8 -*- 

__all__ = ['_return_self', '_exec_context'] 

 

from functools import wraps 

 

def _return_self(method): 

 

    @wraps(method) 

    def wrapped(self, *funargs, **funkwargs): 

 

        new_data = method(self, *funargs, **funkwargs) 

 

        if not isinstance(new_data, type(self.data)): 

            raise TypeError('All method should return velue of type {}: {} is returned.'.format(type(self.data), type(new_data))) 

 

        self.data = new_data 

        return self 

 

    return wrapped 

 

def _exec_context(method): 

 

    @wraps(method) 

    def wrapped(self, *funargs, **funkwargs): 

 

        self._under_execution_context = True 

 

        return method(self, *funargs, **funkwargs) 

 

    return wrapped