reportlab/lib/abag.py
author rgbecker
Wed, 27 Mar 2002 10:39:22 +0000
changeset 1559 2bb75ab0d0aa
parent 1440 243d35446390
child 1677 1450177dd19e
permissions -rw-r--r--
Added __version__
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
517
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
     1
#copyright ReportLab Inc. 2000
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
     2
#see license.txt for license details
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
     3
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/lib/abag.py?cvsroot=reportlab
1559
2bb75ab0d0aa Added __version__
rgbecker
parents: 1440
diff changeset
     4
#$Header: /tmp/reportlab/reportlab/lib/abag.py,v 1.6 2002/03/27 10:39:21 rgbecker Exp $
2bb75ab0d0aa Added __version__
rgbecker
parents: 1440
diff changeset
     5
__version__=''' $Id: abag.py,v 1.6 2002/03/27 10:39:21 rgbecker Exp $ '''
561
58942687b2e1 Docstring modified.
dinu_gherman
parents: 548
diff changeset
     6
517
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
     7
class ABag:
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
     8
	"""
1440
243d35446390 Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents: 566
diff changeset
     9
	'Attribute Bag' - a trivial BAG class for holding attributes.
566
36bbae746b58 Changed comment to be slightly more meaningful
rgbecker
parents: 561
diff changeset
    10
1440
243d35446390 Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents: 566
diff changeset
    11
	You may initialize with keyword arguments.
566
36bbae746b58 Changed comment to be slightly more meaningful
rgbecker
parents: 561
diff changeset
    12
	a = ABag(k0=v0,....,kx=vx,....) ==> getattr(a,'kx')==vx
36bbae746b58 Changed comment to be slightly more meaningful
rgbecker
parents: 561
diff changeset
    13
36bbae746b58 Changed comment to be slightly more meaningful
rgbecker
parents: 561
diff changeset
    14
	c = a.clone(ak0=av0,.....) copy with optional additional attributes.
517
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    15
	"""
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    16
	def __init__(self,**attr):
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    17
		for k,v in attr.items():
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    18
			setattr(self,k,v)
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    19
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    20
	def clone(self,**attr):
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    21
		n = apply(ABag,(),self.__dict__)
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    22
		if attr != {}: apply(ABag.__init__,(n,),attr)
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    23
		return n
548
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    24
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    25
	def __repr__(self):
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    26
		import string
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    27
		n = self.__class__.__name__
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    28
		L = [n+"("]
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    29
		keys = self.__dict__.keys()
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    30
		for k in keys:
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    31
			v = getattr(self, k)
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    32
			rk = repr(k)
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    33
			rv = repr(v)
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    34
			rk = "  "+string.replace(rk, "\n", "\n  ")
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    35
			rv = "    "+string.replace(rv, "\n", "\n    ")
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    36
			L.append(rk)
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    37
			L.append(rv)
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    38
		L.append(") #"+n)
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    39
		return string.join(L, "\n")
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    40
		
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    41
if __name__=="__main__":
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    42
	AB = ABag(a=1, c="hello")
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    43
	CD = AB.clone()
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    44
	print AB
566
36bbae746b58 Changed comment to be slightly more meaningful
rgbecker
parents: 561
diff changeset
    45
	print CD