/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: Aaron Bentley
  • Date: 2009-10-23 03:35:32 UTC
  • mto: (4603.1.22 shelve-editor)
  • mto: This revision was merged to the branch mainline in revision 4795.
  • Revision ID: aaron@aaronbentley.com-20091023033532-exo2sfgc3rn1e434
Remove test code.

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