/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: Marius Kruger
  • Date: 2010-07-10 21:28:56 UTC
  • mto: (5384.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: marius.kruger@enerweb.co.za-20100710212856-uq4ji3go0u5se7hx
* Update documentation
* add NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
strings.
21
21
"""
22
22
 
23
 
from __future__ import absolute_import
24
 
 
25
 
import sys
26
 
 
27
23
 
28
24
class StaticTuple(tuple):
29
25
    """A static type, similar to a tuple of strings."""
42
38
        if num_keys < 0 or num_keys > 255:
43
39
            raise TypeError('StaticTuple(...) takes from 0 to 255 items')
44
40
        for bit in args:
45
 
            if type(bit) not in _valid_types:
 
41
            if type(bit) not in (str, StaticTuple, unicode, int, long, float,
 
42
                                 None.__class__, bool):
46
43
                raise TypeError('StaticTuple can only point to'
47
 
                                ' StaticTuple, str, unicode, int, float, bool, or'
48
 
                                ' None not %s' % (type(bit),))
 
44
                    ' StaticTuple, str, unicode, int, long, float, bool, or'
 
45
                    ' None not %s' % (type(bit),))
49
46
        # We don't need to pass args to tuple.__init__, because that was
50
47
        # already handled in __new__.
51
48
        tuple.__init__(self)
58
55
 
59
56
    def __add__(self, other):
60
57
        """Concatenate self with other"""
61
 
        return StaticTuple.from_sequence(tuple.__add__(self, other))
 
58
        return StaticTuple.from_sequence(tuple.__add__(self,other))
62
59
 
63
60
    def as_tuple(self):
64
61
        return tuple(self)
75
72
        return StaticTuple(*seq)
76
73
 
77
74
 
78
 
_valid_types = (bytes, str, StaticTuple, int, float, None.__class__, bool)
79
 
if sys.version_info < (3,):
80
 
    _valid_types += (long, unicode)
81
 
 
82
75
 
83
76
# Have to set it to None first, so that __new__ can determine whether
84
77
# the _empty_tuple singleton has been created yet or not.