/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/_static_tuple_py.py

  • Committer: Andrew Bennetts
  • Date: 2009-10-29 00:25:26 UTC
  • mfrom: (4775 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4778.
  • Revision ID: andrew.bennetts@canonical.com-20091029002526-0d0hb1jqt1qvd5a6
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
class StaticTuple(tuple):
25
25
    """A static type, similar to a tuple of strings."""
26
26
 
 
27
    __slots__ = ()
 
28
 
27
29
    def __new__(cls, *args):
28
30
        # Make the empty StaticTuple a singleton
29
31
        if not args and _empty_tuple is not None:
33
35
    def __init__(self, *args):
34
36
        """Create a new 'StaticTuple'"""
35
37
        for bit in args:
36
 
            if type(bit) not in (str, StaticTuple):
37
 
                raise TypeError('key bits must be strings or StaticTuple')
 
38
            if type(bit) not in (str, StaticTuple, unicode, int, long, float,
 
39
                                 None.__class__, bool):
 
40
                raise TypeError('StaticTuple can only point to'
 
41
                    ' StaticTuple, str, unicode, int, long, float, bool, or'
 
42
                    ' None not %s' % (type(bit),))
38
43
        num_keys = len(args)
39
44
        if num_keys < 0 or num_keys > 255:
40
45
            raise ValueError('must have 1 => 256 key bits')
45
50
    def __repr__(self):
46
51
        return '%s%s' % (self.__class__.__name__, tuple.__repr__(self))
47
52
 
 
53
    def __reduce__(self):
 
54
        return (StaticTuple, tuple(self))
 
55
 
 
56
    def __add__(self, other):
 
57
        """Concatenate self with other"""
 
58
        return StaticTuple.from_sequence(tuple.__add__(self,other))
 
59
 
48
60
    def as_tuple(self):
49
61
        return self
50
62