52
53
# Python version 2.0 is (2, 0, 0, 'final', 0)." Additionally we use a
53
54
# releaselevel of 'dev' for unreleased under-development code.
55
version_info = (2, 4, 0, 'dev', 5)
56
version_info = (2, 5, 0, 'dev', 5)
57
58
# API compatibility version
58
59
api_minimum_version = (2, 4, 0)
131
132
__version__ = _format_version_tuple(version_info)
132
133
version_string = __version__
136
def _patch_filesystem_default_encoding(new_enc):
137
"""Change the Python process global encoding for filesystem names
139
The effect is to change how open() and other builtin functions handle
140
unicode filenames on posix systems. This should only be done near startup.
142
The new encoding string passed to this function must survive until process
143
termination, otherwise the interpreter may access uninitialized memory.
144
The use of intern() may defer breakage is but is not enough, the string
145
object should be secure against module reloading and during teardown.
151
pythonapi = getattr(ctypes, "pythonapi", None)
152
if pythonapi is None:
153
# Not CPython ctypes implementation
155
old_ptr = ctypes.c_void_p.in_dll(pythonapi, "Py_FileSystemDefaultEncoding")
156
new_ptr = ctypes.cast(ctypes.c_char_p(intern(new_enc)), ctypes.c_void_p)
157
old_ptr.value = new_ptr.value
158
if sys.getfilesystemencoding() != new_enc:
159
raise RuntimeError("Failed to change the filesystem default encoding")
163
# When running under the bzr script, override bad filesystem default encoding.
164
# This is not safe to do for all users of bzrlib, other scripts should instead
165
# just ensure a usable locale is set via the $LANG variable on posix systems.
166
_fs_enc = sys.getfilesystemencoding()
167
if getattr(sys, "_bzr_default_fs_enc", None) is not None:
168
if (_fs_enc is None or codecs.lookup(_fs_enc).name == "ascii"):
169
_fs_enc = _patch_filesystem_default_encoding(sys._bzr_default_fs_enc)
173
_fs_enc = codecs.lookup(_fs_enc).name
134
176
# bzr has various bits of global state that are slowly being eliminated.
135
177
# This variable is intended to permit any new state-like things to be attached
136
178
# to a library_state.BzrLibraryState object rather than getting new global
137
179
# variables that need to be hunted down. Accessing the current BzrLibraryState
138
180
# through this variable is not encouraged: it is better to pass it around as
139
181
# 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
182
# that is too hard, it is better to use this variable than to make a brand new
141
183
# global variable.
142
184
# If using this variable by looking it up (because it can't be easily obtained)
143
185
# it is important to store the reference you get, rather than looking it up