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
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
def get_path_with_real_case(filename): from java.io import File f = File(filename) ret = f.getCanonicalPath() if IS_PY2 and not isinstance(ret, str): return ret.encode(getfilesystemencoding()) return ret
def get_path_with_real_case(filename): from java.io import File # noqa f = File(filename) ret = f.getCanonicalPath() if IS_PY2 and not isinstance(ret, str): return ret.encode(getfilesystemencoding()) return ret
def test_convert_utilities(tmpdir): import pydevd_file_utils test_dir = str(tmpdir.mkdir("Test_Convert_Utilities")) if IS_WINDOWS: normalized = pydevd_file_utils.normcase(test_dir) assert isinstance(normalized, str) # bytes on py2, unicode on py3 assert normalized.lower() == normalized upper_version = os.path.join(test_dir, 'ÁÉÍÓÚ') with open(upper_version, 'w') as stream: stream.write('test') with open(upper_version, 'r') as stream: assert stream.read() == 'test' with open(pydevd_file_utils.normcase(upper_version), 'r') as stream: assert stream.read() == 'test' assert '~' not in normalized for i in range(3): # Check if cache is ok. if i == 2: pydevd_file_utils._listdir_cache.clear() assert pydevd_file_utils.get_path_with_real_case('<does not EXIST>') == '<does not EXIST>' real_case = pydevd_file_utils.get_path_with_real_case(normalized) assert isinstance(real_case, str) # bytes on py2, unicode on py3 # Note test_dir itself cannot be compared with because pytest may # have passed the case normalized. assert real_case.endswith("Test_Convert_Utilities") if i == 2: # Check that we have the expected paths in the cache. assert pydevd_file_utils._listdir_cache[os.path.dirname(normalized).lower()] == ['Test_Convert_Utilities'] assert pydevd_file_utils._listdir_cache[(os.path.dirname(normalized).lower(), 'Test_Convert_Utilities'.lower())] == real_case if IS_PY2: # Test with unicode in python 2 too. real_case = pydevd_file_utils.get_path_with_real_case(normalized.decode( getfilesystemencoding())) assert isinstance(real_case, str) # bytes on py2, unicode on py3 # Note test_dir itself cannot be compared with because pytest may # have passed the case normalized. assert real_case.endswith("Test_Convert_Utilities") # Check that it works with a shortened path. shortened = pydevd_file_utils.convert_to_short_pathname(normalized) assert '~' in shortened with_real_case = pydevd_file_utils.get_path_with_real_case(shortened) assert with_real_case.endswith('Test_Convert_Utilities') assert '~' not in with_real_case else: # On other platforms, nothing should change assert pydevd_file_utils.normcase(test_dir) == test_dir assert pydevd_file_utils.get_path_with_real_case(test_dir) == test_dir
def convert_to_long_pathname(filename): buf = ctypes.create_unicode_buffer(260) GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW if IS_PY2: filename = unicode(filename, getfilesystemencoding()) rv = GetLongPathName(filename, buf, 260) if rv != 0 and rv <= 260: return buf.value return filename
def convert_to_long_pathname(filename): buf = ctypes.create_unicode_buffer(260) GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW if IS_PY2: filename = str(filename, getfilesystemencoding()) rv = GetLongPathName(filename, buf, 260) if rv != 0 and rv <= 260: return buf.value return filename
def _convert_to_long_pathname(filename): buf = ctypes.create_unicode_buffer(MAX_PATH) if IS_PY2: filename = filename.decode(getfilesystemencoding()) rv = GetLongPathName(filename, buf, MAX_PATH) if rv != 0 and rv <= MAX_PATH: return buf.value return filename
def norm_case(filename): # `normcase` doesn't lower case on Python 2 for non-English locale, but Java side does it, # so we should do it manually filename = os_normcase(filename) enc = getfilesystemencoding() if IS_PY3K or enc is None or enc.lower() == "utf-8": return filename try: return filename.decode(enc).lower().encode(enc) except: return filename
def convert_to_long_pathname(filename): if sys.platform != "win32": return filename else: if CTYPES_AVAILABLE: buf = ctypes.create_unicode_buffer(260) GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW rv = GetLongPathName(types.UnicodeType(filename), buf, 260) if rv != 0 and rv <= 260: return buf.value.encode(getfilesystemencoding()) return filename
def norm_case(filename): # `normcase` doesn't lower case on Python 2 for non-English locale, but Java side does it, # so we should do it manually filename = os_normcase(filename) enc = getfilesystemencoding() if IS_PY3K or enc is None or enc.lower() == "utf-8": return filename try: return filename.decode(enc).lower().encode(enc) except: return filename
def _get_path_with_real_case(filename): # Note: this previously made: # convert_to_long_pathname(convert_to_short_pathname(filename)) # but this is no longer done because we can't rely on getting the shortname # consistently (there are settings to disable it on Windows). # So, using approach which resolves by listing the dir. if IS_PY2 and isinstance(filename, unicode): # noqa filename = filename.encode(getfilesystemencoding()) if '~' in filename: filename = convert_to_long_pathname(filename) if filename.startswith('<') or not os_path_exists(filename): return filename # Not much we can do. drive, parts = os.path.splitdrive(os.path.normpath(filename)) drive = drive.upper() while parts.startswith(os.path.sep): parts = parts[1:] drive += os.path.sep parts = parts.lower().split(os.path.sep) try: return _resolve_listing(drive, iter(parts)) except FileNotFoundError: _listdir_cache.clear() # Retry once after clearing the cache we have. try: return _resolve_listing(drive, iter(parts)) except FileNotFoundError: if os_path_exists(filename): # This is really strange, ask the user to report as error. pydev_log.critical( 'pydev debugger: critical: unable to get real case for file. Details:\n' 'filename: %s\ndrive: %s\nparts: %s\n' '(please create a ticket in the tracker to address this).', filename, drive, parts ) pydev_log.exception() # Don't fail, just return the original file passed. return filename
def _get_path_with_real_case(filename): # Note: this previously made: # convert_to_long_pathname(convert_to_short_pathname(filename)) # but this is no longer done because we can't rely on getting the shortname # consistently (there are settings to disable it on Windows). # So, using approach which resolves by listing the dir. if IS_PY2 and isinstance(filename, unicode): # noqa filename = filename.encode(getfilesystemencoding()) if '~' in filename: filename = convert_to_long_pathname(filename) if filename.startswith('<') or not os.path.exists(filename): return filename # Not much we can do. drive, parts = os.path.splitdrive(os.path.normpath(filename)) drive = drive.upper() while parts.startswith(os.path.sep): parts = parts[1:] drive += os.path.sep parts = parts.lower().split(os.path.sep) try: return _resolve_listing(drive, iter(parts)) except FileNotFoundError: _listdir_cache.clear() # Retry once after clearing the cache we have. try: return _resolve_listing(drive, iter(parts)) except FileNotFoundError: if os.path.exists(filename): # This is really strange, ask the user to report as error. sys.stderr.write('\npydev debugger: critical: unable to get real case for file. Details:\n' 'filename: %s\ndrive: %s\nparts: %s\n' '(please create a ticket in the tracker to address this).\n\n' % ( filename, drive, parts)) pydev_log.exception() # Don't fail, just return the original file passed. return filename
from pydevd_concurrency_analyser.pydevd_thread_wrappers import ObjectWrapper, wrap_attr import pydevd_file_utils from _pydevd_bundle import pydevd_xml from _pydev_bundle._pydev_filesystem_encoding import getfilesystemencoding from _pydevd_bundle.pydevd_constants import dict_contains, get_thread_id, IS_PY3K file_system_encoding = getfilesystemencoding() try: from urllib import quote except: from urllib.parse import quote # @UnresolvedImport from _pydev_imps._pydev_saved_modules import threading threadingCurrentThread = threading.currentThread DONT_TRACE_THREADING = ['threading.py', 'pydevd.py'] INNER_METHODS = ['_stop'] INNER_FILES = ['threading.py'] THREAD_METHODS = ['start', '_stop', 'join'] LOCK_METHODS = ['__init__', 'acquire', 'release', '__enter__', '__exit__'] QUEUE_METHODS = ['put', 'get'] from _pydevd_bundle.pydevd_comm import GlobalDebuggerHolder, NetCommand import traceback import time # return time since epoch in milliseconds cur_time = lambda: int(round(time.time() * 1000000))
from pydevd_concurrency_analyser.pydevd_thread_wrappers import ObjectWrapper, wrap_attr import pydevd_file_utils from _pydevd_bundle import pydevd_xml from _pydev_bundle._pydev_filesystem_encoding import getfilesystemencoding from _pydevd_bundle.pydevd_constants import get_thread_id, IS_PY3K file_system_encoding = getfilesystemencoding() try: from urllib import quote except: from urllib.parse import quote # @UnresolvedImport from _pydev_imps._pydev_saved_modules import threading threadingCurrentThread = threading.currentThread DONT_TRACE_THREADING = ['threading.py', 'pydevd.py'] INNER_METHODS = ['_stop'] INNER_FILES = ['threading.py'] THREAD_METHODS = ['start', '_stop', 'join'] LOCK_METHODS = ['__init__', 'acquire', 'release', '__enter__', '__exit__'] QUEUE_METHODS = ['put', 'get'] from _pydevd_bundle.pydevd_comm import GlobalDebuggerHolder, NetCommand import traceback import time # return time since epoch in milliseconds cur_time = lambda: int(round(time.time() * 1000000))
def norm_case(filename): filename = os_normcase(filename) if IS_PY3K: return filename enc = getfilesystemencoding() return filename.decode(enc).lower().encode(enc)