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

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

#!/usr/bin/env python 

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

# 

# This file is part of rdlm-py released under the MIT license. 

# See the LICENSE file for more information. 

 

import json 

import datetime 

from rdlmpy.exceptions import RDLMClientException 

 

 

def iso8601_to_datetime(iso8601_string): 

    return datetime.datetime.strptime(iso8601_string[0:19], "%Y-%m-%dT%H:%M:%S") 

 

 

class RDLMLock(object): 

    ''' 

    Class which defines a lock object 

    ''' 

 

    url = None 

    title = None 

    uid = None 

    lifetime = None 

    wait = None 

    active_since = None 

    active_expires = None 

    wait_since = None 

    wait_expires = None 

 

    def __init__(self, url): 

        self.url = url 

 

    @staticmethod 

    def factory(url, get_request_output): 

        res = None 

        try: 

            tmp = json.loads(get_request_output) 

            if tmp['active']: 

                res = RDLMActiveLock(url) 

                res.active_since = iso8601_to_datetime(tmp['active_since']) 

                res.active_expires = iso8601_to_datetime(tmp['active_expires']) 

            else: 

                res = RDLMWaitingLock(url) 

                res.wait_since = iso8601_to_datetime(tmp['wait_since']) 

                res.wait_expires = iso8601_to_datetime(tmp['wait_expires']) 

            res.title = tmp['title'] 

            res.uid = tmp['uid'] 

            res.lifetime = tmp['lifetime'] 

            res.wait = tmp['wait'] 

        except: 

            raise RDLMClientException("impossible to build the lock object") 

        return res 

 

 

class RDLMActiveLock(RDLMLock): 

 

    @property 

    def active(self): 

        return True 

 

 

class RDLMWaitingLock(RDLMLock): 

 

    @property 

    def active(self): 

        return False