Python ctypes.create_unicode_buffer() Examples
The following are 30
code examples of ctypes.create_unicode_buffer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ctypes
, or try the search function
.
Example #1
Source File: appdirs.py From pkg_resources with MIT License | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): import ctypes csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #2
Source File: pydevd_file_utils.py From PyDev.Debugger with Eclipse Public License 1.0 | 6 votes |
def _convert_to_short_pathname(filename): buf = ctypes.create_unicode_buffer(MAX_PATH) if IS_PY2 and isinstance(filename, str): filename = filename.decode(getfilesystemencoding()) rv = GetShortPathName(filename, buf, MAX_PATH) if rv != 0 and rv <= MAX_PATH: filename = buf.value if IS_PY2: filename = filename.encode(getfilesystemencoding()) return filename # Note that we have a cache for previous list dirs... the only case where this may be an # issue is if the user actually changes the case of an existing file on windows while # the debugger is executing (as this seems very unlikely and the cache can save a # reasonable time -- especially on mapped drives -- it seems nice to have it).
Example #3
Source File: appdirs.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): import ctypes csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #4
Source File: test_unicode.py From oss-ftp with MIT License | 6 votes |
def test_buffers(self): ctypes.set_conversion_mode("ascii", "strict") buf = ctypes.create_unicode_buffer("abc") self.assertEqual(len(buf), 3+1) ctypes.set_conversion_mode("ascii", "replace") buf = ctypes.create_unicode_buffer("ab���") self.assertEqual(buf[:], u"ab\uFFFD\uFFFD\uFFFD\0") self.assertEqual(buf[::], u"ab\uFFFD\uFFFD\uFFFD\0") self.assertEqual(buf[::-1], u"\0\uFFFD\uFFFD\uFFFDba") self.assertEqual(buf[::2], u"a\uFFFD\uFFFD") self.assertEqual(buf[6:5:-1], u"") ctypes.set_conversion_mode("ascii", "ignore") buf = ctypes.create_unicode_buffer("ab���") # is that correct? not sure. But with 'ignore', you get what you pay for.. self.assertEqual(buf[:], u"ab\0\0\0\0") self.assertEqual(buf[::], u"ab\0\0\0\0") self.assertEqual(buf[::-1], u"\0\0\0\0ba") self.assertEqual(buf[::2], u"a\0\0") self.assertEqual(buf[6:5:-1], u"")
Example #5
Source File: appdirs.py From anpr with Creative Commons Attribution 4.0 International | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): import ctypes csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #6
Source File: appdirs.py From anpr with Creative Commons Attribution 4.0 International | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): import ctypes csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #7
Source File: appdirs.py From anpr with Creative Commons Attribution 4.0 International | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #8
Source File: appdirs.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): import ctypes csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #9
Source File: appdirs.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #10
Source File: appdirs.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): import ctypes csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #11
Source File: appdirs.py From pex with Apache License 2.0 | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): import ctypes csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #12
Source File: appdirs.py From pex with Apache License 2.0 | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): import ctypes csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #13
Source File: testutils.py From pythonfinder with MIT License | 6 votes |
def normalize_path(path): # type: (AnyStr) -> AnyStr """ Return a case-normalized absolute variable-expanded path. :param str path: The non-normalized path :return: A normalized, expanded, case-normalized path :rtype: str """ path = os.path.abspath(os.path.expandvars(os.path.expanduser(str(path)))) if os.name == "nt" and os.path.exists(path): try: from ctypes import create_unicode_buffer, windll except ImportError: path = os.path.normpath(os.path.normcase(path)) else: BUFSIZE = 500 buffer = create_unicode_buffer(BUFSIZE) get_long_path_name = windll.kernel32.GetLongPathNameW get_long_path_name(six.ensure_text(path), buffer, BUFSIZE) path = buffer.value return path return os.path.normpath(os.path.normcase(path))
Example #14
Source File: test_unicode.py From BinderFilter with MIT License | 6 votes |
def test_buffers(self): ctypes.set_conversion_mode("ascii", "strict") buf = ctypes.create_unicode_buffer("abc") self.assertEqual(len(buf), 3+1) ctypes.set_conversion_mode("ascii", "replace") buf = ctypes.create_unicode_buffer("ab���") self.assertEqual(buf[:], u"ab\uFFFD\uFFFD\uFFFD\0") self.assertEqual(buf[::], u"ab\uFFFD\uFFFD\uFFFD\0") self.assertEqual(buf[::-1], u"\0\uFFFD\uFFFD\uFFFDba") self.assertEqual(buf[::2], u"a\uFFFD\uFFFD") self.assertEqual(buf[6:5:-1], u"") ctypes.set_conversion_mode("ascii", "ignore") buf = ctypes.create_unicode_buffer("ab���") # is that correct? not sure. But with 'ignore', you get what you pay for.. self.assertEqual(buf[:], u"ab\0\0\0\0") self.assertEqual(buf[::], u"ab\0\0\0\0") self.assertEqual(buf[::-1], u"\0\0\0\0ba") self.assertEqual(buf[::2], u"a\0\0") self.assertEqual(buf[6:5:-1], u"")
Example #15
Source File: PlatformManagerWindows.py From lackey with MIT License | 6 votes |
def getWindowByTitle(self, wildcard, order=0): """ Returns a handle for the first window that matches the provided "wildcard" regex """ EnumWindowsProc = ctypes.WINFUNCTYPE( ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.py_object) def callback(hwnd, context): if ctypes.windll.user32.IsWindowVisible(hwnd): length = ctypes.windll.user32.GetWindowTextLengthW(hwnd) buff = ctypes.create_unicode_buffer(length + 1) ctypes.windll.user32.GetWindowTextW(hwnd, buff, length + 1) if re.search(context["wildcard"], buff.value, flags=re.I) != None and not context["handle"]: if context["order"] > 0: context["order"] -= 1 else: context["handle"] = hwnd return True data = {"wildcard": wildcard, "handle": None, "order": order} ctypes.windll.user32.EnumWindows(EnumWindowsProc(callback), ctypes.py_object(data)) return data["handle"]
Example #16
Source File: path.py From Computable with MIT License | 6 votes |
def _get_long_path_name(path): """Get a long path name (expand ~) on Windows using ctypes. Examples -------- >>> get_long_path_name('c:\\docume~1') u'c:\\\\Documents and Settings' """ try: import ctypes except ImportError: raise ImportError('you need to have ctypes installed for this to work') _GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW _GetLongPathName.argtypes = [ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint ] buf = ctypes.create_unicode_buffer(260) rv = _GetLongPathName(path, buf, 260) if rv == 0 or rv > 260: return path else: return buf.value
Example #17
Source File: appdirs.py From FuYiSpider with Apache License 2.0 | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #18
Source File: appdirs.py From FuYiSpider with Apache License 2.0 | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): import ctypes csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #19
Source File: appdirs.py From FuYiSpider with Apache License 2.0 | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #20
Source File: appdirs.py From FuYiSpider with Apache License 2.0 | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): import ctypes csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #21
Source File: test_uflash.py From uflash with MIT License | 6 votes |
def test_find_microbit_nt_missing(): """ Simulate being on os.name == 'nt' and a disk with a volume name 'MICROBIT' does not exist for a micro:bit device. """ mock_windll = mock.MagicMock() mock_windll.kernel32 = mock.MagicMock() mock_windll.kernel32.GetVolumeInformationW = mock.MagicMock() mock_windll.kernel32.GetVolumeInformationW.return_value = None with mock.patch('os.name', 'nt'): with mock.patch('os.path.exists', return_value=True): return_value = ctypes.create_unicode_buffer(1024) with mock.patch('ctypes.create_unicode_buffer', return_value=return_value): ctypes.windll = mock_windll assert uflash.find_microbit() is None
Example #22
Source File: test_uflash.py From uflash with MIT License | 6 votes |
def test_find_microbit_nt_exists(): """ Simulate being on os.name == 'nt' and a disk with a volume name 'MICROBIT' exists indicating a connected micro:bit device. """ mock_windll = mock.MagicMock() mock_windll.kernel32 = mock.MagicMock() mock_windll.kernel32.GetVolumeInformationW = mock.MagicMock() mock_windll.kernel32.GetVolumeInformationW.return_value = None # # Have every drive claim to be removable # mock_windll.kernel32.GetDriveTypeW = mock.MagicMock() mock_windll.kernel32.GetDriveTypeW.return_value = 2 with mock.patch('os.name', 'nt'): with mock.patch('os.path.exists', return_value=True): return_value = ctypes.create_unicode_buffer('MICROBIT') with mock.patch('ctypes.create_unicode_buffer', return_value=return_value): ctypes.windll = mock_windll assert uflash.find_microbit() == 'A:\\'
Example #23
Source File: client.py From gdog with GNU General Public License v3.0 | 6 votes |
def detectForgroundWindows(): #Stolen fom https://sjohannes.wordpress.com/2012/03/23/win32-python-getting-all-window-titles/ EnumWindows = ctypes.windll.user32.EnumWindows EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int)) GetWindowText = ctypes.windll.user32.GetWindowTextW GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW IsWindowVisible = ctypes.windll.user32.IsWindowVisible titles = [] def foreach_window(hwnd, lParam): if IsWindowVisible(hwnd): length = GetWindowTextLength(hwnd) buff = ctypes.create_unicode_buffer(length + 1) GetWindowText(hwnd, buff, length + 1) titles.append(buff.value) return True EnumWindows(EnumWindowsProc(foreach_window), 0) return titles
Example #24
Source File: appdirs.py From vnpy_crypto with MIT License | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #25
Source File: appdirs.py From vnpy_crypto with MIT License | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): import ctypes csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #26
Source File: appdirs.py From kobo-predict with BSD 2-Clause "Simplified" License | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #27
Source File: appdirs.py From Python24 with MIT License | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #28
Source File: appdirs.py From Python24 with MIT License | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): import ctypes csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #29
Source File: appdirs.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): import ctypes csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value
Example #30
Source File: appdirs.py From ironpython2 with Apache License 2.0 | 6 votes |
def _get_win_folder_with_ctypes(csidl_name): import ctypes csidl_const = { "CSIDL_APPDATA": 26, "CSIDL_COMMON_APPDATA": 35, "CSIDL_LOCAL_APPDATA": 28, }[csidl_name] buf = ctypes.create_unicode_buffer(1024) ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) # Downgrade to short path name if have highbit chars. See # <http://bugs.activestate.com/show_bug.cgi?id=85099>. has_high_char = False for c in buf: if ord(c) > 255: has_high_char = True break if has_high_char: buf2 = ctypes.create_unicode_buffer(1024) if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024): buf = buf2 return buf.value