equal
deleted
inserted
replaced
26 ry = AttrMapValue(isNumber), |
26 ry = AttrMapValue(isNumber), |
27 ) |
27 ) |
28 |
28 |
29 |
29 |
30 ''' |
30 ''' |
31 from UserDict import UserDict |
|
32 from reportlab.lib.validators import isAnything, _SequenceTypes, DerivedValue |
31 from reportlab.lib.validators import isAnything, _SequenceTypes, DerivedValue |
33 from reportlab import rl_config |
32 from reportlab import rl_config |
34 |
33 |
35 class CallableValue: |
34 class CallableValue: |
36 '''a class to allow callable initial values''' |
35 '''a class to allow callable initial values''' |
48 def __init__(self,validate=None,desc=None,initial=None, advancedUsage=0, **kw): |
47 def __init__(self,validate=None,desc=None,initial=None, advancedUsage=0, **kw): |
49 self.validate = validate or isAnything |
48 self.validate = validate or isAnything |
50 self.desc = desc |
49 self.desc = desc |
51 self._initial = initial |
50 self._initial = initial |
52 self._advancedUsage = advancedUsage |
51 self._advancedUsage = advancedUsage |
53 for k,v in list(kw.items()): |
52 for k,v in kw.items(): |
54 setattr(self,k,v) |
53 setattr(self,k,v) |
55 |
54 |
56 def __getattr__(self,name): |
55 def __getattr__(self,name): |
57 #hack to allow callable initial values |
56 #hack to allow callable initial values |
58 if name=='initial': |
57 if name=='initial': |
63 raise AttributeError(name) |
62 raise AttributeError(name) |
64 |
63 |
65 def __repr__(self): |
64 def __repr__(self): |
66 return 'AttrMapValue(%s)' % ', '.join(['%s=%r' % i for i in self.__dict__.items()]) |
65 return 'AttrMapValue(%s)' % ', '.join(['%s=%r' % i for i in self.__dict__.items()]) |
67 |
66 |
68 class AttrMap(UserDict): |
67 class AttrMap(dict): |
69 def __init__(self,BASE=None,UNWANTED=[],**kw): |
68 def __init__(self,BASE=None,UNWANTED=[],**kw): |
70 data = {} |
69 data = {} |
71 if BASE: |
70 if BASE: |
72 if isinstance(BASE,AttrMap): |
71 if isinstance(BASE,AttrMap): |
73 data = BASE.data #they used BASECLASS._attrMap |
72 data = BASE.data #they used BASECLASS._attrMap |
77 if hasattr(B,'_attrMap'): |
76 if hasattr(B,'_attrMap'): |
78 data.update(getattr(B._attrMap,'data',{})) |
77 data.update(getattr(B._attrMap,'data',{})) |
79 else: |
78 else: |
80 raise ValueError('BASE=%s has wrong kind of value' % str(B)) |
79 raise ValueError('BASE=%s has wrong kind of value' % str(B)) |
81 |
80 |
82 UserDict.__init__(self,data) |
81 dict.__init__(self,data) |
83 self.remove(UNWANTED) |
82 self.remove(UNWANTED) |
84 self.data.update(kw) |
83 self.data.update(kw) |
85 |
84 |
86 def update(self,kw): |
85 def update(self,kw): |
87 if isinstance(kw,AttrMap): kw = kw.data |
86 if isinstance(kw,AttrMap): kw = kw.data |