~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/static_tuple.py

  • Committer: John Arbash Meinel
  • Date: 2009-11-02 17:15:20 UTC
  • mto: (4668.1.3 2.1.0b2)
  • mto: This revision was merged to the branch mainline in revision 4782.
  • Revision ID: john@arbash-meinel.com-20091102171520-8udwpeq12bnz1vkb
Fix bug #471193, allow tuples into the CHK code.

Instead of raising a TypeError immediately, add a debug flag and only
raise TypeErrors if that flag is set. Sort of like how we did
ensure_unicode() for api changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Interface thunk for a StaticTuple implementation."""
18
18
 
 
19
from bzrlib import debug
 
20
 
19
21
try:
20
22
    from bzrlib._static_tuple_c import StaticTuple
21
23
except ImportError, e:
23
25
    osutils.failed_to_load_extension(e)
24
26
    from bzrlib._static_tuple_py import StaticTuple
25
27
 
 
28
 
 
29
def expect_static_tuple(obj):
 
30
    """Check if the passed object is a StaticTuple.
 
31
 
 
32
    Cast it if necessary, but if the 'static_tuple' debug flag is set, raise an
 
33
    error instead.
 
34
    """
 
35
    if 'static_tuple' not in debug.debug_flags:
 
36
        return StaticTuple.from_sequence(obj)
 
37
    if type(obj) is not StaticTuple:
 
38
        raise TypeError('We expected a StaticTuple not a %s' % (type(obj),))
 
39
    return obj