~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/__init__.py

  • Committer: Samuel Bronson
  • Date: 2012-08-30 20:36:18 UTC
  • mto: (6015.57.3 2.4)
  • mto: This revision was merged to the branch mainline in revision 6558.
  • Revision ID: naesten@gmail.com-20120830203618-y2dzw91nqpvpgxvx
Update INSTALL for switch to Python 2.6 and up.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
We hope you enjoy this library.
32
32
"""
33
33
 
34
 
from __future__ import absolute_import
35
 
 
36
34
import time
37
35
 
38
36
# Keep track of when bzrlib was first imported, so that we can give rough
39
37
# timestamps relative to program start in the log file kept by bzrlib.trace.
40
38
_start_time = time.time()
41
39
 
42
 
import codecs
43
40
import sys
44
41
 
45
42
 
46
43
IGNORE_FILENAME = ".bzrignore"
47
44
 
48
45
 
49
 
__copyright__ = "Copyright 2005-2012 Canonical Ltd."
 
46
__copyright__ = "Copyright 2005-2011 Canonical Ltd."
50
47
 
51
48
# same format as sys.version_info: "A tuple containing the five components of
52
49
# the version number: major, minor, micro, releaselevel, and serial. All
55
52
# Python version 2.0 is (2, 0, 0, 'final', 0)."  Additionally we use a
56
53
# releaselevel of 'dev' for unreleased under-development code.
57
54
 
58
 
version_info = (2, 6, 0, 'dev', 1)
 
55
version_info = (2, 4, 3, 'dev', 0)
59
56
 
60
57
# API compatibility version
61
58
api_minimum_version = (2, 4, 0)
134
131
__version__ = _format_version_tuple(version_info)
135
132
version_string = __version__
136
133
 
137
 
 
138
 
def _patch_filesystem_default_encoding(new_enc):
139
 
    """Change the Python process global encoding for filesystem names
140
 
    
141
 
    The effect is to change how open() and other builtin functions handle
142
 
    unicode filenames on posix systems. This should only be done near startup.
143
 
 
144
 
    The new encoding string passed to this function must survive until process
145
 
    termination, otherwise the interpreter may access uninitialized memory.
146
 
    The use of intern() may defer breakage is but is not enough, the string
147
 
    object should be secure against module reloading and during teardown.
148
 
    """
149
 
    try:
150
 
        import ctypes
151
 
        old_ptr = ctypes.c_void_p.in_dll(ctypes.pythonapi,
152
 
            "Py_FileSystemDefaultEncoding")
153
 
    except (ImportError, ValueError):
154
 
        return # No ctypes or not CPython implementation, do nothing
155
 
    new_ptr = ctypes.cast(ctypes.c_char_p(intern(new_enc)), ctypes.c_void_p)
156
 
    old_ptr.value = new_ptr.value
157
 
    if sys.getfilesystemencoding() != new_enc:
158
 
        raise RuntimeError("Failed to change the filesystem default encoding")
159
 
    return new_enc
160
 
 
161
 
 
162
 
# When running under the bzr script, override bad filesystem default encoding.
163
 
# This is not safe to do for all users of bzrlib, other scripts should instead
164
 
# just ensure a usable locale is set via the $LANG variable on posix systems.
165
 
_fs_enc = sys.getfilesystemencoding()
166
 
if getattr(sys, "_bzr_default_fs_enc", None) is not None:
167
 
    if (_fs_enc is None or codecs.lookup(_fs_enc).name == "ascii"):
168
 
        _fs_enc = _patch_filesystem_default_encoding(sys._bzr_default_fs_enc)
169
 
if _fs_enc is None:
170
 
    _fs_enc = "ascii"
171
 
else:
172
 
    _fs_enc = codecs.lookup(_fs_enc).name
173
 
 
174
 
 
175
134
# bzr has various bits of global state that are slowly being eliminated.
176
135
# This variable is intended to permit any new state-like things to be attached
177
136
# to a library_state.BzrLibraryState object rather than getting new global
178
137
# variables that need to be hunted down. Accessing the current BzrLibraryState
179
138
# through this variable is not encouraged: it is better to pass it around as
180
139
# part of the context of an operation than to look it up directly, but when
181
 
# that is too hard, it is better to use this variable than to make a brand new
 
140
# that is too hard, it is better to use this variable than to make a branch new
182
141
# global variable.
183
142
# If using this variable by looking it up (because it can't be easily obtained)
184
143
# it is important to store the reference you get, rather than looking it up