31
31
We hope you enjoy this library.
34
from __future__ import absolute_import
36
38
# Keep track of when bzrlib was first imported, so that we can give rough
37
39
# timestamps relative to program start in the log file kept by bzrlib.trace.
38
40
_start_time = time.time()
52
55
# Python version 2.0 is (2, 0, 0, 'final', 0)." Additionally we use a
53
56
# releaselevel of 'dev' for unreleased under-development code.
55
version_info = (2, 5, 0, 'dev', 1)
58
version_info = (2, 5, 0, 'dev', 5)
57
60
# API compatibility version
58
61
api_minimum_version = (2, 4, 0)
131
134
__version__ = _format_version_tuple(version_info)
132
135
version_string = __version__
138
def _patch_filesystem_default_encoding(new_enc):
139
"""Change the Python process global encoding for filesystem names
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.
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.
153
pythonapi = getattr(ctypes, "pythonapi", None)
154
if pythonapi is None:
155
# Not CPython ctypes implementation
157
old_ptr = ctypes.c_void_p.in_dll(pythonapi, "Py_FileSystemDefaultEncoding")
158
new_ptr = ctypes.cast(ctypes.c_char_p(intern(new_enc)), ctypes.c_void_p)
159
old_ptr.value = new_ptr.value
160
if sys.getfilesystemencoding() != new_enc:
161
raise RuntimeError("Failed to change the filesystem default encoding")
165
# When running under the bzr script, override bad filesystem default encoding.
166
# This is not safe to do for all users of bzrlib, other scripts should instead
167
# just ensure a usable locale is set via the $LANG variable on posix systems.
168
_fs_enc = sys.getfilesystemencoding()
169
if getattr(sys, "_bzr_default_fs_enc", None) is not None:
170
if (_fs_enc is None or codecs.lookup(_fs_enc).name == "ascii"):
171
_fs_enc = _patch_filesystem_default_encoding(sys._bzr_default_fs_enc)
175
_fs_enc = codecs.lookup(_fs_enc).name
134
178
# bzr has various bits of global state that are slowly being eliminated.
135
179
# This variable is intended to permit any new state-like things to be attached
136
180
# to a library_state.BzrLibraryState object rather than getting new global
137
181
# variables that need to be hunted down. Accessing the current BzrLibraryState
138
182
# through this variable is not encouraged: it is better to pass it around as
139
183
# part of the context of an operation than to look it up directly, but when
140
# that is too hard, it is better to use this variable than to make a branch new
184
# that is too hard, it is better to use this variable than to make a brand new
141
185
# global variable.
142
186
# If using this variable by looking it up (because it can't be easily obtained)
143
187
# it is important to store the reference you get, rather than looking it up