~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/util/configobj/configobj.py

  • Committer: Andrew Bennetts
  • Date: 2008-02-18 08:30:38 UTC
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080218083038-tts55zsx5xrz3l2e
Lots of assorted hackery to reduce the number of imports for common operations.  Improves 'rocks', 'st' and 'help' times by ~50ms on my laptop.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    raise RuntimeError("Python v.2.2 or later needed")
25
25
 
26
26
import os, re
27
 
compiler = None
28
 
try:
29
 
    import compiler
30
 
except ImportError:
31
 
    # for IronPython
32
 
    pass
 
27
 
 
28
from bzrlib.lazy_import import lazy_import
 
29
lazy_import(globals(), """
 
30
import compiler
 
31
""")
 
32
 
33
33
from types import StringTypes
34
34
from warnings import warn
35
35
try:
88
88
    None: BOM_UTF8
89
89
    }
90
90
 
91
 
try:
92
 
    from validate import VdtMissingValue
93
 
except ImportError:
94
 
    VdtMissingValue = None
95
 
 
96
 
try:
97
 
    enumerate
98
 
except NameError:
99
 
    def enumerate(obj):
100
 
        """enumerate for Python 2.2."""
101
 
        i = -1
102
 
        for item in obj:
103
 
            i += 1
104
 
            yield i, item
105
 
 
106
 
try:
107
 
    True, False
108
 
except NameError:
109
 
    True, False = 1, 0
110
 
 
111
 
 
112
91
__version__ = '4.4.0'
113
92
 
114
93
__revision__ = '$Id: configobj.py 156 2006-01-31 14:57:08Z fuzzyman $'
159
138
 
160
139
def getObj(s):
161
140
    s = "a=" + s
162
 
    if compiler is None:
163
 
        raise ImportError('compiler module not available')
164
141
    p = compiler.parse(s)
165
142
    return p.getChildren()[1].getChildren()[0].getChildren()[1]
166
143
 
2029
2006
            if self.configspec is None:
2030
2007
                raise ValueError, 'No configspec supplied.'
2031
2008
            if preserve_errors:
 
2009
                try:
 
2010
                    from validate import VdtMissingValue
 
2011
                except ImportError:
 
2012
                    VdtMissingValue = None
2032
2013
                if VdtMissingValue is None:
2033
2014
                    raise ImportError('Missing validate module.')
2034
2015
            section = self