author | rptlab |
Tue, 30 Apr 2013 14:20:22 +0100 | |
branch | py33 |
changeset 3721 | 0c93dd8ff567 |
parent 3617 | ae5744e97c42 |
child 3756 | 475d5ceb83b9 |
permissions | -rw-r--r-- |
3617 | 1 |
#Copyright ReportLab Europe Ltd. 2000-2012 |
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__ |
3721 | 28 |
K = list(D.keys()) |
3125 | 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() |
3721 | 35 |
print(AB) |
36 |
print(CD) |