/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: Andrew Bennetts
  • Date: 2009-10-21 11:13:40 UTC
  • mto: This revision was merged to the branch mainline in revision 4762.
  • Revision ID: andrew.bennetts@canonical.com-20091021111340-w7x4d5yf83qwjncc
Add test that WSGI glue allows request handlers to access paths above that request's. backing transport, so long as it is within the WSGI app's backing transport.

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'"""
 
35
        for bit in args:
 
36
            if type(bit) not in (str, StaticTuple):
 
37
                raise TypeError('key bits must be strings or StaticTuple')
37
38
        num_keys = len(args)
38
39
        if num_keys < 0 or num_keys > 255:
39
 
            raise TypeError('StaticTuple(...) takes from 0 to 255 items')
40
 
        for bit in args:
41
 
            if type(bit) not in (str, StaticTuple, unicode, int, long, float,
42
 
                                 None.__class__, bool):
43
 
                raise TypeError('StaticTuple can only point to'
44
 
                    ' StaticTuple, str, unicode, int, long, float, bool, or'
45
 
                    ' None not %s' % (type(bit),))
 
40
            raise ValueError('must have 1 => 256 key bits')
46
41
        # We don't need to pass args to tuple.__init__, because that was
47
42
        # already handled in __new__.
48
43
        tuple.__init__(self)
50
45
    def __repr__(self):
51
46
        return '%s%s' % (self.__class__.__name__, tuple.__repr__(self))
52
47
 
53
 
    def __reduce__(self):
54
 
        return (StaticTuple, tuple(self))
55
 
 
56
 
    def __add__(self, other):
57
 
        """Concatenate self with other"""
58
 
        return StaticTuple.from_sequence(tuple.__add__(self,other))
59
 
 
60
48
    def as_tuple(self):
61
 
        return tuple(self)
 
49
        return self
62
50
 
63
51
    def intern(self):
64
52
        return _interned_tuples.setdefault(self, self)