reportlab/lib/abag.py
author dinu_gherman
Wed, 10 Jan 2001 09:08:10 +0000
changeset 561 58942687b2e1
parent 548 223699ff68fc
child 566 36bbae746b58
permissions -rw-r--r--
Docstring modified.
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
561
58942687b2e1 Docstring modified.
dinu_gherman
parents: 548
diff changeset
     4
#$Header: /tmp/reportlab/reportlab/lib/abag.py,v 1.3 2001/01/10 09:08:10 dinu_gherman Exp $
58942687b2e1 Docstring modified.
dinu_gherman
parents: 548
diff changeset
     5
517
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
     6
class ABag:
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
     7
	"""
561
58942687b2e1 Docstring modified.
dinu_gherman
parents: 548
diff changeset
     8
	A trivial BAG class for holding attributes.
58942687b2e1 Docstring modified.
dinu_gherman
parents: 548
diff changeset
     9
	(Perhaps AttrBag would be a better name.)
517
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    10
	"""
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    11
	def __init__(self,**attr):
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    12
		for k,v in attr.items():
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    13
			setattr(self,k,v)
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    14
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    15
	def clone(self,**attr):
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    16
		n = apply(ABag,(),self.__dict__)
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    17
		if attr != {}: apply(ABag.__init__,(n,),attr)
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    18
		return n
548
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    19
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    20
	def __repr__(self):
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    21
		import string
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    22
		n = self.__class__.__name__
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    23
		L = [n+"("]
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    24
		keys = self.__dict__.keys()
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    25
		for k in keys:
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    26
			v = getattr(self, k)
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    27
			rk = repr(k)
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    28
			rv = repr(v)
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    29
			rk = "  "+string.replace(rk, "\n", "\n  ")
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    30
			rv = "    "+string.replace(rv, "\n", "\n    ")
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    31
			L.append(rk)
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    32
			L.append(rv)
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    33
		L.append(") #"+n)
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    34
		return string.join(L, "\n")
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    35
		
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    36
if __name__=="__main__":
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    37
	AB = ABag(a=1, c="hello")
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    38
	CD = AB.clone()
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    39
	print AB
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    40
	print CD