author | robin <robin@reportlab.com> |
Mon, 06 Nov 2017 09:10:46 +0000 | |
changeset 4370 | 823a8c33ce43 |
parent 4330 | 617ffa6bbdc8 |
child 4528 | e09377955af8 |
permissions | -rw-r--r-- |
4330 | 1 |
#Copyright ReportLab Europe Ltd. 2000-2017 |
517 | 2 |
#see license.txt for license details |
4370
823a8c33ce43
fix history urls contribution by Ben Weiner <ben@readingtype.org.uk>; version-->3.4.17
robin <robin@reportlab.com>
parents:
4330
diff
changeset
|
3 |
#history https://bitbucket.org/rptlab/reportlab/history-node/tip/src/reportlab/lib/abag.py |
4252 | 4 |
__version__='3.3.0' |
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): |
3756 | 22 |
n = self.__class__(**self.__dict__) |
2721 | 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) |