/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-02-14 03:16:54 UTC
  • mfrom: (7479.2.3 no-more-python2)
  • Revision ID: breezy.the.bot@gmail.com-20200214031654-bp1xtv2jr9nmhto3
Drop python2 support.

Merged from https://code.launchpad.net/~jelmer/brz/no-more-python2/+merge/378694

Show diffs side-by-side

added added

removed removed

Lines of Context:
129
129
    The use of intern() may defer breakage is but is not enough, the string
130
130
    object should be secure against module reloading and during teardown.
131
131
    """
132
 
    is_py3 = sys.version_info > (3,)
133
132
    try:
134
133
        import ctypes
135
134
        old_ptr = ctypes.c_void_p.in_dll(ctypes.pythonapi,
136
135
                                         "Py_FileSystemDefaultEncoding")
137
 
        if is_py3:
138
 
            has_enc = ctypes.c_int.in_dll(ctypes.pythonapi,
139
 
                                          "Py_HasFileSystemDefaultEncoding")
140
 
            as_utf8 = ctypes.PYFUNCTYPE(
141
 
                ctypes.POINTER(ctypes.c_char), ctypes.py_object)(
142
 
                    ("PyUnicode_AsUTF8", ctypes.pythonapi))
 
136
        has_enc = ctypes.c_int.in_dll(ctypes.pythonapi,
 
137
                                      "Py_HasFileSystemDefaultEncoding")
 
138
        as_utf8 = ctypes.PYFUNCTYPE(
 
139
            ctypes.POINTER(ctypes.c_char), ctypes.py_object)(
 
140
                ("PyUnicode_AsUTF8", ctypes.pythonapi))
143
141
    except (ImportError, ValueError):
144
142
        return  # No ctypes or not CPython implementation, do nothing
145
 
    if is_py3:
146
 
        new_enc = sys.intern(new_enc)
147
 
        enc_ptr = as_utf8(new_enc)
148
 
        has_enc.value = 1
149
 
    else:
150
 
        new_enc = intern(new_enc)
151
 
        enc_ptr = ctypes.c_char_p(new_enc)
 
143
    new_enc = sys.intern(new_enc)
 
144
    enc_ptr = as_utf8(new_enc)
 
145
    has_enc.value = 1
152
146
    old_ptr.value = ctypes.cast(enc_ptr, ctypes.c_void_p).value
153
147
    if sys.getfilesystemencoding() != new_enc:
154
148
        raise RuntimeError("Failed to change the filesystem default encoding")