src/reportlab/lib/abag.py
author robin <robin@reportlab.com>
Tue, 07 Mar 2017 10:00:34 +0000
changeset 4330 617ffa6bbdc8
parent 4252 fe660f227cac
child 4370 823a8c33ce43
permissions -rw-r--r--
changes for release 3.4.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4330
617ffa6bbdc8 changes for release 3.4.0
robin <robin@reportlab.com>
parents: 4252
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2017
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
4252
fe660f227cac changes for release 3.3.0
robin
parents: 4067
diff changeset
     4
__version__='3.3.0'
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):
3756
475d5ceb83b9 apply 3707: abag.py: preserve class during cloning
robin
parents: 3721
diff changeset
    22
        n = self.__class__(**self.__dict__)
2721
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)