/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 breezy/_static_tuple_py.py

  • Committer: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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