summaryrefslogtreecommitdiff
path: root/coip/apps/scim/schema.py
blob: 5290cd5d000eb264f43c2ea5c77d93ef8fe785fb (plain)
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
'''
Created on Apr 12, 2012

@author: leifj
'''
from coip.apps.scim import NotAvailable

class ScimAttribute(object):
    def __get__(self,o,objtype=None):
        raise NotAvailable()
    
    def __set__(self,o,v):
        raise NotAvailable()
        
    def __delete__(self,o):
        raise NotAvailable()
        
    def add(self,o,v):
        raise NotAvailable()
    
    def remove(self,o,v):
        raise NotAvailable()

class scim_simple_attribute(ScimAttribute):

    def __init__(self,attr):
        self._attr = attr

    def __get__(self,o,objtype=None):
        a = getattr(o,self._attr)
        if hasattr(a,'__call__'):
            return "%s" % a()
        else:
            return "%s" % a
    
    def __set__(self,o,v):
        a = getattr(o,self._attr)
        if hasattr(a,'__call__'):
            a(v)
        else:
            setattr(o,self._attr,v)
        
    def __delete__(self,o):
        a = getattr(o,self._attr)
        if not hasattr(a,'__call__'):
            setattr(o,self._attr,None)

class scim_reference_attribute(ScimAttribute):
        def __init__(self,attr):
            self._attr = attr

        def __get__(self,o,objtype=None):
            a = getattr(o,self._attr)
            if a != None:
                return a.uuid
            else:
                return None