~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/__init__.py

(jelmer) Correct detection of Python implementations that don't support the
 C api when patching the default filesystem encoding. (Martin Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
    """
149
149
    try:
150
150
        import ctypes
151
 
    except ImportError:
152
 
        return
153
 
    pythonapi = getattr(ctypes, "pythonapi", None)
154
 
    if pythonapi is None:
155
 
        # Not CPython ctypes implementation
156
 
        return
157
 
    old_ptr = ctypes.c_void_p.in_dll(pythonapi, "Py_FileSystemDefaultEncoding")
 
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
158
155
    new_ptr = ctypes.cast(ctypes.c_char_p(intern(new_enc)), ctypes.c_void_p)
159
156
    old_ptr.value = new_ptr.value
160
157
    if sys.getfilesystemencoding() != new_enc: