/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: Canonical.com Patch Queue Manager
  • Date: 2010-02-11 04:02:41 UTC
  • mfrom: (5017.2.2 tariff)
  • Revision ID: pqm@pqm.ubuntu.com-20100211040241-w6n021dz0uus341n
(mbp) add import-tariff tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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."""
38
34
 
39
35
    def __init__(self, *args):
40
36
        """Create a new 'StaticTuple'"""
 
37
        for bit in args:
 
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),))
41
43
        num_keys = len(args)
42
44
        if num_keys < 0 or num_keys > 255:
43
 
            raise TypeError('StaticTuple(...) takes from 0 to 255 items')
44
 
        for bit in args:
45
 
            if type(bit) not in _valid_types:
46
 
                raise TypeError('StaticTuple can only point to'
47
 
                                ' StaticTuple, str, unicode, int, float, bool, or'
48
 
                                ' None not %s' % (type(bit),))
 
45
            raise ValueError('must have 1 => 256 key bits')
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.