/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
141
141
    The use of intern() may defer breakage is but is not enough, the string
142
142
    object should be secure against module reloading and during teardown.
143
143
    """
 
144
    is_py3 = sys.version_info > (3,)
144
145
    try:
145
146
        import ctypes
146
147
        old_ptr = ctypes.c_void_p.in_dll(ctypes.pythonapi,
147
148
            "Py_FileSystemDefaultEncoding")
 
149
        if is_py3:
 
150
            has_enc = ctypes.c_int.in_dll(ctypes.pythonapi,
 
151
                "Py_HasFileSystemDefaultEncoding")
 
152
            as_utf8 = ctypes.PYFUNCTYPE(
 
153
                ctypes.POINTER(ctypes.c_char), ctypes.py_object)(
 
154
                    ("PyUnicode_AsUTF8", ctypes.pythonapi))
148
155
    except (ImportError, ValueError):
149
156
        return # No ctypes or not CPython implementation, do nothing
150
 
    new_ptr = ctypes.cast(ctypes.c_char_p(intern(new_enc)), ctypes.c_void_p)
151
 
    old_ptr.value = new_ptr.value
 
157
    if is_py3:
 
158
        new_enc = sys.intern(new_enc)
 
159
        enc_ptr = as_utf8(new_enc)
 
160
        has_enc.value = 1
 
161
    else:
 
162
        new_enc = intern(new_enc)
 
163
        enc_ptr = ctypes.c_char_p(new_enc)
 
164
    old_ptr.value = ctypes.cast(enc_ptr, ctypes.c_void_p).value
152
165
    if sys.getfilesystemencoding() != new_enc:
153
166
        raise RuntimeError("Failed to change the filesystem default encoding")
154
167
    return new_enc