def test__getfullpathname(self): self.assertEqual(nt._getfullpathname('.'), nt.getcwd()) self.assertEqual(nt._getfullpathname('<bad>'), os.path.join(nt.getcwd(), '<bad>')) self.assertEqual(nt._getfullpathname('bad:'), os.path.join(nt.getcwd(), 'bad:')) self.assertEqual(nt._getfullpathname(':bad:'), os.path.join(nt.getcwd(), ':bad:')) self.assertEqual(nt._getfullpathname('::'), '::\\') self.assertEqual(nt._getfullpathname('1:'), '1:\\') self.assertEqual(nt._getfullpathname('1:a'), '1:\\a') self.assertEqual(nt._getfullpathname('1::'), '1:\\:') self.assertEqual(nt._getfullpathname('1:\\'), '1:\\')
def test__getfullpathname(): AreEqual(nt._getfullpathname('.'), nt.getcwd()) AreEqual(nt._getfullpathname('<bad>'), path_combine(nt.getcwd(), '<bad>')) AreEqual(nt._getfullpathname('bad:'), path_combine(nt.getcwd(), 'bad:')) AreEqual(nt._getfullpathname(':bad:'), path_combine(nt.getcwd(), ':bad:')) AreEqual(nt._getfullpathname('::'), '::\\') AreEqual(nt._getfullpathname('1:'), '1:\\') AreEqual(nt._getfullpathname('1:a'), '1:\\a') AreEqual(nt._getfullpathname('1::'), '1:\\:') AreEqual(nt._getfullpathname('1:\\'), '1:\\')
def test__getfullpathname(): AreEqual(nt._getfullpathname("."), nt.getcwd()) AreEqual(nt._getfullpathname("<bad>"), path_combine(nt.getcwd(), "<bad>")) AreEqual(nt._getfullpathname("bad:"), path_combine(nt.getcwd(), "bad:")) AreEqual(nt._getfullpathname(":bad:"), path_combine(nt.getcwd(), ":bad:")) AreEqual(nt._getfullpathname("::"), "::\\") AreEqual(nt._getfullpathname("1:"), "1:\\") AreEqual(nt._getfullpathname("1:a"), "1:\\a") AreEqual(nt._getfullpathname("1::"), "1:\\:") AreEqual(nt._getfullpathname("1:\\"), "1:\\")
def my_abspath1(path): """ Modification of ntpath.abspath() that avoids doing an import. """ if path: try: path = _getfullpathname(path) except WindowsError: pass else: try: path = getcwd() except UnicodeDecodeError: # # This exception can be raised in py3k (alpha) on nt. # path = getcwdu() np = os.path.normpath(path) if (len(np) >= 2) and (np[1:2] == ':'): np = np[:1].upper() + np[1:] return np
def abspath_expanduser_unicode(path, base=None, long_path=True): """ Return the absolute version of a path. If 'base' is given and 'path' is relative, the path will be expanded relative to 'base'. 'path' must be a Unicode string. 'base', if given, must be a Unicode string corresponding to an absolute path as returned by a previous call to abspath_expanduser_unicode. On Windows, the result will be a long path unless long_path is given as False. """ if not isinstance(path, str): raise AssertionError("paths must be Unicode strings") if base is not None and long_path: precondition_abspath(base) path = expanduser(path) if _getfullpathname: # On Windows, os.path.isabs will incorrectly return True # for paths without a drive letter (that are not UNC paths), # e.g. "\\". See <http://bugs.python.org/issue1669539>. try: if base is None: path = _getfullpathname(path or u".") else: path = _getfullpathname(os.path.join(base, path)) except OSError: pass if not os.path.isabs(path): if base is None: cwd = os.getcwd() if PY2: cwd = cwd.decode('utf8') path = os.path.join(cwd, path) else: path = os.path.join(base, path) # We won't hit <http://bugs.python.org/issue5827> because # there is always at least one Unicode path component. path = os.path.normpath(path) if sys.platform == "win32" and long_path: path = to_windows_long_path(path) return path
def abspath_expanduser_unicode(path, base=None, long_path=True): """ Return the absolute version of a path. If 'base' is given and 'path' is relative, the path will be expanded relative to 'base'. 'path' must be a Unicode string. 'base', if given, must be a Unicode string corresponding to an absolute path as returned by a previous call to abspath_expanduser_unicode. On Windows, the result will be a long path unless long_path is given as False. """ if not isinstance(path, unicode): raise AssertionError("paths must be Unicode strings") if base is not None and long_path: precondition_abspath(base) path = expanduser(path) if _getfullpathname: # On Windows, os.path.isabs will incorrectly return True # for paths without a drive letter (that are not UNC paths), # e.g. "\\". See <http://bugs.python.org/issue1669539>. try: if base is None: path = _getfullpathname(path or u".") else: path = _getfullpathname(os.path.join(base, path)) except OSError: pass if not os.path.isabs(path): if base is None: path = os.path.join(os.getcwdu(), path) else: path = os.path.join(base, path) # We won't hit <http://bugs.python.org/issue5827> because # there is always at least one Unicode path component. path = os.path.normpath(path) if sys.platform == "win32" and long_path: path = to_windows_long_path(path) return path
def abspath(path): if path: try: path = _getfullpathname(path) except WindowsError: pass elif isinstance(path, bytes): path = os.getcwdb() else: path = os.getcwd() return normpath(path)
def abspath(path): """Return the absolute version of a path.""" if path: # Empty path must return current working directory. try: path = _getfullpathname(path) except WindowsError: pass # Bad path - return unchanged. else: path = os.getcwd() return normpath(path)
def abspath(path): """Return the absolute version of a path.""" if path: try: path = _getfullpathname(path) except WindowsError: pass elif isinstance(path, unicode): path = os.getcwdu() else: path = os.getcwd() return normpath(path)
def abspath(path): """Return the absolute version of a path.""" if path: path = os.fspath(path) try: path = _getfullpathname(path) except OSError: pass elif isinstance(path, bytes): path = os.getcwdb() else: path = os.getcwd() return normpath(path)
def abspath(path): """Return the absolute version of a path.""" if path: # Empty path must return current working directory. path = os.fspath(path) try: path = _getfullpathname(path) except OSError: pass # Bad path - return unchanged. elif isinstance(path, bytes): path = os.getcwdb() else: path = os.getcwd() return normpath(path)
def __init__(self, name, mode=DEFAULT_MODE, handle=None, use_errno=False, use_last_error=False, winmode=None): self._name = name flags = self._func_flags_ if use_errno: flags |= _FUNCFLAG_USE_ERRNO if use_last_error: flags |= _FUNCFLAG_USE_LASTERROR if _sys.platform.startswith("aix"): """When the name contains ".a(" and ends with ")", e.g., "libFOO.a(libFOO.so)" - this is taken to be an archive(member) syntax for dlopen(), and the mode is adjusted. Otherwise, name is presented to dlopen() as a file argument. """ if name and name.endswith(")") and ".a(" in name: mode |= (_os.RTLD_MEMBER | _os.RTLD_NOW) if _os.name == "nt": if winmode is not None: mode = winmode else: import nt mode = nt._LOAD_LIBRARY_SEARCH_DEFAULT_DIRS if '/' in name or '\\' in name: self._name = nt._getfullpathname(self._name) mode |= nt._LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR # PATH is how DLL lookup has always worked in the past # in Python on Windows. IMHO both the above mode flags # are not wanted and should have been seen as serious # regressions to Python on Windows. We should however # propagate any PATH changes that have happened to Python # library and that is not yet implemented. LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008 mode = LOAD_WITH_ALTERED_SEARCH_PATH class _FuncPtr(_CFuncPtr): _flags_ = flags _restype_ = self._func_restype_ self._FuncPtr = _FuncPtr if handle is None: self._handle = _dlopen(self._name, mode) else: self._handle = handle
def __init__(self, name, mode=DEFAULT_MODE, handle=None, use_errno=False, use_last_error=False, winmode=None): self._name = name flags = self._func_flags_ if use_errno: flags |= _FUNCFLAG_USE_ERRNO if use_last_error: flags |= _FUNCFLAG_USE_LASTERROR if _sys.platform.startswith("aix"): """When the name contains ".a(" and ends with ")", e.g., "libFOO.a(libFOO.so)" - this is taken to be an archive(member) syntax for dlopen(), and the mode is adjusted. Otherwise, name is presented to dlopen() as a file argument. """ if name and name.endswith(")") and ".a(" in name: mode |= (_os.RTLD_MEMBER | _os.RTLD_NOW) if _os.name == "nt": if winmode is not None: mode = winmode else: import nt mode = nt._LOAD_LIBRARY_SEARCH_DEFAULT_DIRS if '/' in name or '\\' in name: self._name = nt._getfullpathname(self._name) mode |= nt._LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR class _FuncPtr(_CFuncPtr): _flags_ = flags _restype_ = self._func_restype_ self._FuncPtr = _FuncPtr self._builtin = {} if handle is None: if isinstance(self._name, dict): self._builtin = self._name['symbols'] self._name = self._name['name'] self._handle = 0 else: self._handle = _dlopen(self._name, mode) else: self._handle = handle
def abspath_expanduser_unicode(path): """Return the absolute version of a path.""" assert isinstance(path, unicode), path path = os.path.expanduser(path) if _getfullpathname: # On Windows, os.path.isabs will return True for paths without a drive letter, # e.g. "\\". See <http://bugs.python.org/issue1669539>. try: path = _getfullpathname(path or u".") except OSError: pass if not os.path.isabs(path): path = os.path.join(os.getcwdu(), path) # We won't hit <http://bugs.python.org/issue5827> because # there is always at least one Unicode path component. return os.path.normpath(path)
def abspath(path): """Return the absolute version of a path""" try: from nt import _getfullpathname except ImportError: # Not running on Windows - mock up something sensible. global abspath def _abspath(path): if not isabs(path): path = join(os.getcwd(), path) return normpath(path) abspath = _abspath return _abspath(path) if path: # Empty path must return current working directory. try: path = _getfullpathname(path) except WindowsError: pass # Bad path - return unchanged. else: path = os.getcwd() return normpath(path)
def abspath(path): """Return the absolute version of a path.""" try: return _getfullpathname(path) except OSError: return _abspath_fallback(path)
import clr import shutil clr.AddReference("System.Xml") from System.Xml import XmlDocument, XmlNamespaceManager from System import Guid from System.IO import File, Path, Directory, FileInfo, FileAttributes #List of predetermined directories and files which should not be included in #the MSI excludedDirectories = [] excludedFiles = [] #Automatically determine what's currently not working under IronPython sys.path.append(nt.environ["DLR_ROOT"] + r"\Languages\IronPython\Tests\Tools") base_dir = nt._getfullpathname( nt.environ["DLR_ROOT"] + r"\External.LCA_RESTRICTED\Languages\CPython\27") import stdmodules BROKEN_LIST = stdmodules.main(base_dir) if len(BROKEN_LIST) < 10: #If there are less than ten modules/directories listed in BROKEN_LIST #chances are good stdmodules is broken! exc_msg = "It's highly unlikely that only %d CPy standard modules are broken under IP!" % len( BROKEN_LIST) print exc_msg raise Exception(exc_msg) #Specify Packages and Modules that should not be included here. excludedDirectories += [ "/Lib/test",
def abspath(self): from nt import _getfullpathname return NTPath(_getfullpathname(str(self)))
def abspath(path): """Return the absolute version of a path.""" try: return _getfullpathname(path) except (OSError, ValueError): return _abspath_fallback(path)
def abspath(path): """Return the absolute version of a path.""" try: return normpath(_getfullpathname(path)) except (OSError, ValueError): return _abspath_fallback(path)
# Module 'ntpath' -- common operations on WinNT/Win95 pathnames
import shutil clr.AddReference("System.Xml") from System.Xml import XmlDocument, XmlNamespaceManager from System import Guid from System.IO import File, Path, Directory, FileInfo, FileAttributes #List of predetermined directories and files which should not be included in #the MSI excludedDirectories = [] excludedFiles = [] #Automatically determine what's currently not working under IronPython sys.path.append(nt.environ["DLR_ROOT"] + r"\Languages\IronPython\Tests\Tools") base_dir = nt._getfullpathname(nt.environ["DLR_ROOT"] + r"\External.LCA_RESTRICTED\Languages\CPython\27") import stdmodules BROKEN_LIST = stdmodules.main(base_dir) if len(BROKEN_LIST)<10: #If there are less than ten modules/directories listed in BROKEN_LIST #chances are good stdmodules is broken! exc_msg = "It's highly unlikely that only %d CPy standard modules are broken under IP!" % len(BROKEN_LIST) print exc_msg raise Exception(exc_msg) #Specify Packages and Modules that should not be included here. excludedDirectories += [ "/Lib/test", "/Lib/idlelib",
def _getfullpathname(path): if isinstance(path, str): return nt._getfullpathname(path) else: return nt._getfullpathname(path.as_bytes())
def _getfullpathname(path): return nt._getfullpathname(_as_bytes(path))