src/reportlab/lib/abag.py
author rptlab
Tue, 30 Apr 2013 14:20:22 +0100
branchpy33
changeset 3721 0c93dd8ff567
parent 3617 ae5744e97c42
child 3756 475d5ceb83b9
permissions -rw-r--r--
initial changes from 2to3-3.3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3617
ae5744e97c42 reportlab: copyright date changes
robin
parents: 3290
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2012
517
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
     2
#see license.txt for license details
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 1683
diff changeset
     3
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/lib/abag.py
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 1683
diff changeset
     4
__version__=''' $Id$ '''
3029
eded59f94021 adding docstrings to lib
andy
parents: 2964
diff changeset
     5
__doc__='''Data structure to hold a collection of attributes, used by styles.'''
517
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
     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
36bbae746b58 Changed comment to be slightly more meaningful
rgbecker
parents: 561
diff changeset
     9
3029
eded59f94021 adding docstrings to lib
andy
parents: 2964
diff changeset
    10
    This predates modern Python.  Doing this again, we'd use a subclass
eded59f94021 adding docstrings to lib
andy
parents: 2964
diff changeset
    11
    of dict.
eded59f94021 adding docstrings to lib
andy
parents: 2964
diff changeset
    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
36bbae746b58 Changed comment to be slightly more meaningful
rgbecker
parents: 561
diff changeset
    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
f52c73a6fa96 abag.py: improve speed
rgbecker
parents: 2332
diff changeset
    19
        self.__dict__.update(attr)
517
dffd258916bc Initial version split from paraparser.py
rgbecker
parents:
diff changeset
    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
f52c73a6fa96 abag.py: improve speed
rgbecker
parents: 2332
diff changeset
    22
        n = ABag(**self.__dict__)
f52c73a6fa96 abag.py: improve speed
rgbecker
parents: 2332
diff changeset
    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
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    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
371c68e6a3c9 reportlab: improve abag output
rgbecker
parents: 3029
diff changeset
    27
        D = self.__dict__
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
    28
        K = list(D.keys())
3125
371c68e6a3c9 reportlab: improve abag output
rgbecker
parents: 3029
diff changeset
    29
        K.sort()
371c68e6a3c9 reportlab: improve abag output
rgbecker
parents: 3029
diff changeset
    30
        return '%s(%s)' % (self.__class__.__name__,', '.join(['%s=%r' % (k,D[k]) for k in K]))
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
    31
548
223699ff68fc added a __repr__ for debug purposes
aaron_watters
parents: 517
diff changeset
    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
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
    35
    print(AB)
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
    36
    print(CD)