1
# Copyright (C) 2009, 2010 Canonical Ltd
1
# Copyright (C) 2009 Canonical Ltd
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
39
35
def __init__(self, *args):
40
36
"""Create a new '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),))
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')
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)
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))
63
60
def as_tuple(self):
75
72
return StaticTuple(*seq)
78
_valid_types = (bytes, str, StaticTuple, int, float, None.__class__, bool)
79
if sys.version_info < (3,):
80
_valid_types += (long, unicode)
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.