author | andy |
Thu, 17 Dec 2009 16:18:34 +0000 | |
changeset 3290 | 6e5e33a15a3d |
parent 3125 | 371c68e6a3c9 |
child 3617 | ae5744e97c42 |
permissions | -rw-r--r-- |
3290 | 1 |
#Copyright ReportLab Europe Ltd. 2000-2010 |
517 | 2 |
#see license.txt for license details |
2332 | 3 |
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/lib/abag.py |
4 |
__version__=''' $Id$ ''' |
|
3029 | 5 |
__doc__='''Data structure to hold a collection of attributes, used by styles.''' |
517 | 6 |
class ABag: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1559
diff
changeset
|
7 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1559
diff
changeset
|
8 |
'Attribute Bag' - a trivial BAG class for holding attributes. |
566 | 9 |
|
3029 | 10 |
This predates modern Python. Doing this again, we'd use a subclass |
11 |
of dict. |
|
12 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1559
diff
changeset
|
13 |
You may initialize with keyword arguments. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1559
diff
changeset
|
14 |
a = ABag(k0=v0,....,kx=vx,....) ==> getattr(a,'kx')==vx |
566 | 15 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1559
diff
changeset
|
16 |
c = a.clone(ak0=av0,.....) copy with optional additional attributes. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1559
diff
changeset
|
17 |
""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1559
diff
changeset
|
18 |
def __init__(self,**attr): |
2721 | 19 |
self.__dict__.update(attr) |
517 | 20 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1559
diff
changeset
|
21 |
def clone(self,**attr): |
2721 | 22 |
n = ABag(**self.__dict__) |
23 |
if attr: n.__dict__.update(attr) |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1559
diff
changeset
|
24 |
return n |
548 | 25 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1559
diff
changeset
|
26 |
def __repr__(self): |
3125 | 27 |
D = self.__dict__ |
28 |
K = D.keys() |
|
29 |
K.sort() |
|
30 |
return '%s(%s)' % (self.__class__.__name__,', '.join(['%s=%r' % (k,D[k]) for k in K])) |
|
1683 | 31 |
|
548 | 32 |
if __name__=="__main__": |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1559
diff
changeset
|
33 |
AB = ABag(a=1, c="hello") |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1559
diff
changeset
|
34 |
CD = AB.clone() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1559
diff
changeset
|
35 |
print AB |
2721 | 36 |
print CD |