Python ntpath.normpath() Examples
The following are 30
code examples of ntpath.normpath().
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
ntpath
, or try the search function
.
Example #1
Source File: smb3.py From cracke-dit with MIT License | 6 votes |
def mkdir(self, shareName, pathName, password = None): # ToDo: Handle situations where share is password protected pathName = string.replace(pathName,'/', '\\') pathName = ntpath.normpath(pathName) if len(pathName) > 0 and pathName[0] == '\\': pathName = pathName[1:] treeId = self.connectTree(shareName) fileId = None try: fileId = self.create(treeId, pathName,GENERIC_ALL ,FILE_SHARE_READ | FILE_SHARE_WRITE |FILE_SHARE_DELETE, FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, FILE_CREATE, 0) finally: if fileId is not None: self.close(treeId, fileId) self.disconnectTree(treeId) return True
Example #2
Source File: smb3.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def rmdir(self, shareName, pathName, password = None): # ToDo: Handle situations where share is password protected pathName = string.replace(pathName,'/', '\\') pathName = ntpath.normpath(pathName) if len(pathName) > 0 and pathName[0] == '\\': pathName = pathName[1:] treeId = self.connectTree(shareName) fileId = None try: fileId = self.create(treeId, pathName, desiredAccess=DELETE | FILE_READ_ATTRIBUTES | SYNCHRONIZE, shareMode=FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, creationOptions=FILE_DIRECTORY_FILE | FILE_OPEN_REPARSE_POINT, creationDisposition=FILE_OPEN, fileAttributes=0) from impacket import smb delete_req = smb.SMBSetFileDispositionInfo() delete_req['DeletePending'] = True self.setInfo(treeId, fileId, inputBlob=delete_req, fileInfoClass=SMB2_FILE_DISPOSITION_INFO) finally: if fileId is not None: self.close(treeId, fileId) self.disconnectTree(treeId) return True
Example #3
Source File: smbmap.py From smbmap with GNU General Public License v3.0 | 6 votes |
def upload_file(self, host, src, dst): dst = dst.replace('/','\\') dst = ntpath.normpath(dst) dst = dst.split('\\') share = dst[0] dst = '\\'.join(dst[1:]) if os.path.exists(src): print('[+] Starting upload: %s (%s bytes)' % (src, os.path.getsize(src))) upFile = open(src, 'rb') try: self.smbconn[host].putFile(share, dst, upFile.read) print('[+] Upload complete') except Exception as e: print('[!]', e) print('[!] Error uploading file, you need to include destination file name in the path') upFile.close() else: print('[!] Invalid source. File does not exist') sys.exit()
Example #4
Source File: test_smbclient_shutil.py From smbprotocol with MIT License | 6 votes |
def test_copyfile_symlink_dont_follow(smb_share): src_filename = "%s\\source.txt" % smb_share src_link = "%s\\source-link.txt" % smb_share dst_filename = "%s\\target.txt" % smb_share with open_file(src_filename, mode='w') as fd: fd.write(u"content") symlink(src_filename, src_link) actual = copyfile(src_link, dst_filename, follow_symlinks=False) assert actual == dst_filename with open_file(dst_filename, mode='r') as fd: assert fd.read() == u"content" assert islink(dst_filename) assert readlink(dst_filename) == ntpath.normpath(src_filename)
Example #5
Source File: _os.py From smbprotocol with MIT License | 6 votes |
def _rename_information(src, dst, replace_if_exists=False, **kwargs): verb = 'replace' if replace_if_exists else 'rename' norm_src = ntpath.normpath(src) norm_dst = ntpath.normpath(dst) if not norm_dst.startswith('\\\\'): raise ValueError("dst must be an absolute path to where the file or directory should be %sd." % verb) src_root = ntpath.splitdrive(norm_src)[0] dst_root, dst_name = ntpath.splitdrive(norm_dst) if src_root.lower() != dst_root.lower(): raise ValueError("Cannot %s a file to a different root than the src." % verb) raw = SMBRawIO(src, mode='r', share_access='rwd', desired_access=FilePipePrinterAccessMask.DELETE, create_options=CreateOptions.FILE_OPEN_REPARSE_POINT, **kwargs) with SMBFileTransaction(raw) as transaction: file_rename = FileRenameInformation() file_rename['replace_if_exists'] = replace_if_exists file_rename['file_name'] = to_text(dst_name[1:]) # dst_name has \ prefix from splitdrive, we remove that. set_info(transaction, file_rename)
Example #6
Source File: _os.py From smbprotocol with MIT License | 6 votes |
def removedirs(name, **kwargs): """ Remove directories recursively. Works like rmdir() except that, if the leaf directory is successfully removed, removedirs() tries to successively remove every parent directory mentioned in path until an error is raised (which is ignored, because it generally means that a parent directory is not empty). :param name: The directory to start removing recursively from. :param kwargs: Common SMB Session arguments for smbclient. """ remove_dir = ntpath.normpath(name) while True: try: rmdir(remove_dir, **kwargs) except (SMBResponseException, OSError): return else: remove_dir = ntpath.dirname(remove_dir)
Example #7
Source File: _os.py From smbprotocol with MIT License | 6 votes |
def readlink(path, **kwargs): """ Return a string representing the path to which the symbolic link points. If the link is relative it will be converted to an absolute pathname relative to the link itself. The link target may point to a local path and not another UNC path. :param path: The path to the symbolic link to read. :param kwargs: Common SMB Session arguments for smbclient. :return: The link target path. """ norm_path = ntpath.normpath(path) reparse_buffer = _get_reparse_point(norm_path, **kwargs) reparse_tag = reparse_buffer['reparse_tag'] if reparse_tag.get_value() != ReparseTags.IO_REPARSE_TAG_SYMLINK: raise ValueError(to_native("Cannot read link of reparse point with tag %s at '%s'" % (str(reparse_tag), norm_path))) symlink_buffer = SymbolicLinkReparseDataBuffer() symlink_buffer.unpack(reparse_buffer['data_buffer'].get_value()) return symlink_buffer.resolve_link(norm_path)
Example #8
Source File: msvs.py From sitoa with Apache License 2.0 | 6 votes |
def printSources(self, hierarchy, commonprefix): sorteditems = sorted(hierarchy.items(), key=lambda a: a[0].lower()) # First folders, then files for key, value in sorteditems: if SCons.Util.is_Dict(value): self.file.write('\t\t\t<Filter\n' '\t\t\t\tName="%s"\n' '\t\t\t\tFilter="">\n' % (key)) self.printSources(value, commonprefix) self.file.write('\t\t\t</Filter>\n') for key, value in sorteditems: if SCons.Util.is_String(value): file = value if commonprefix: file = os.path.join(commonprefix, value) file = os.path.normpath(file) self.file.write('\t\t\t<File\n' '\t\t\t\tRelativePath="%s">\n' '\t\t\t</File>\n' % (file))
Example #9
Source File: shutil.py From smbprotocol with MIT License | 6 votes |
def copymode(src, dst, follow_symlinks=True, **kwargs): """ Copy the permission bits from src to dst. The file contents, owner, and group are unaffected. Due to the limitations of Windows, this function only sets/unsets the dst's FILE_ATTRIBUTE_READ_ONLY flag based on what src's attribute is set to. If follow_symlinks is 'False', and both src and dst are symbolic links, copymode() will attempt to modify the mode of dst itself (rather than the file it points to). This function supports src and dst being either a local or UNC path. A relative path will be resolved based on the current working directory. :param src: The src file or directory to copy the read only flag from. :param dst: The dst file or directory to copy the read only flag to. :param follow_symlinks: Whether to copy the read only flag on the symlink or the target of the symlink. :param kwargs: Common arguments used to build the SMB Session for any UNC paths. """ src_mode = stat.S_IMODE(_get_file_stat(src, follow_symlinks, **kwargs).st_mode) norm_dst = ntpath.normpath(dst) if norm_dst.startswith('\\\\'): read_only = not (src_mode & stat.S_IWRITE == stat.S_IWRITE and src_mode & stat.S_IREAD == stat.S_IREAD) _set_file_basic_info(dst, follow_symlinks, read_only=read_only, **kwargs) else: _local_chmod(dst, src_mode, follow_symlinks)
Example #10
Source File: smb3.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def mkdir(self, shareName, pathName, password = None): # ToDo: Handle situations where share is password protected pathName = string.replace(pathName,'/', '\\') pathName = ntpath.normpath(pathName) if len(pathName) > 0 and pathName[0] == '\\': pathName = pathName[1:] treeId = self.connectTree(shareName) fileId = None try: fileId = self.create(treeId, pathName,GENERIC_ALL ,FILE_SHARE_READ | FILE_SHARE_WRITE |FILE_SHARE_DELETE, FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, FILE_CREATE, 0) finally: if fileId is not None: self.close(treeId, fileId) self.disconnectTree(treeId) return True
Example #11
Source File: smb3.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def remove(self, shareName, pathName, password = None): # ToDo: Handle situations where share is password protected pathName = string.replace(pathName,'/', '\\') pathName = ntpath.normpath(pathName) if len(pathName) > 0 and pathName[0] == '\\': pathName = pathName[1:] treeId = self.connectTree(shareName) fileId = None try: fileId = self.create(treeId, pathName,DELETE | FILE_READ_ATTRIBUTES, FILE_SHARE_DELETE, FILE_NON_DIRECTORY_FILE | FILE_DELETE_ON_CLOSE, FILE_OPEN, 0) finally: if fileId is not None: self.close(treeId, fileId) self.disconnectTree(treeId) return True
Example #12
Source File: smb3.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def storeFile(self, shareName, path, callback, mode = FILE_OVERWRITE_IF, offset = 0, password = None, shareAccessMode = FILE_SHARE_WRITE): # ToDo: Handle situations where share is password protected path = string.replace(path,'/', '\\') path = ntpath.normpath(path) if len(path) > 0 and path[0] == '\\': path = path[1:] treeId = self.connectTree(shareName) fileId = None try: fileId = self.create(treeId, path, FILE_WRITE_DATA, shareAccessMode, FILE_NON_DIRECTORY_FILE, mode, 0) finished = False writeOffset = offset while not finished: data = callback(self._Connection['MaxWriteSize']) if len(data) == 0: break written = self.write(treeId, fileId, data, writeOffset, len(data)) writeOffset += written finally: if fileId is not None: self.close(treeId, fileId) self.disconnectTree(treeId)
Example #13
Source File: msvs.py From arnold-usd with Apache License 2.0 | 6 votes |
def printSources(self, hierarchy, kind, commonprefix, filter_name): keywords = {'Source Files': 'ClCompile', 'Header Files': 'ClInclude', 'Local Headers': 'ClInclude', 'Resource Files': 'None', 'Other Files': 'None'} sorteditems = sorted(hierarchy.items(), key = lambda a: a[0].lower()) # First folders, then files for key, value in sorteditems: if SCons.Util.is_Dict(value): self.printSources(value, kind, commonprefix, filter_name + '\\' + key) for key, value in sorteditems: if SCons.Util.is_String(value): file = value if commonprefix: file = os.path.join(commonprefix, value) file = os.path.normpath(file) self.file.write('\t\t<%s Include="%s" />\n' % (keywords[kind], file)) self.filters_file.write('\t\t<%s Include="%s">\n' '\t\t\t<Filter>%s</Filter>\n' '\t\t</%s>\n' % (keywords[kind], file, filter_name, keywords[kind]))
Example #14
Source File: msvs.py From web2board with GNU Lesser General Public License v3.0 | 6 votes |
def printSources(self, hierarchy, commonprefix): sorteditems = sorted(hierarchy.items(), key=lambda a: a[0].lower()) # First folders, then files for key, value in sorteditems: if SCons.Util.is_Dict(value): self.file.write('\t\t\t<Filter\n' '\t\t\t\tName="%s"\n' '\t\t\t\tFilter="">\n' % (key)) self.printSources(value, commonprefix) self.file.write('\t\t\t</Filter>\n') for key, value in sorteditems: if SCons.Util.is_String(value): file = value if commonprefix: file = os.path.join(commonprefix, value) file = os.path.normpath(file) self.file.write('\t\t\t<File\n' '\t\t\t\tRelativePath="%s">\n' '\t\t\t</File>\n' % (file))
Example #15
Source File: msvs.py From arnold-usd with Apache License 2.0 | 6 votes |
def printSources(self, hierarchy, commonprefix): sorteditems = sorted(hierarchy.items(), key=lambda a: a[0].lower()) # First folders, then files for key, value in sorteditems: if SCons.Util.is_Dict(value): self.file.write('\t\t\t<Filter\n' '\t\t\t\tName="%s"\n' '\t\t\t\tFilter="">\n' % (key)) self.printSources(value, commonprefix) self.file.write('\t\t\t</Filter>\n') for key, value in sorteditems: if SCons.Util.is_String(value): file = value if commonprefix: file = os.path.join(commonprefix, value) file = os.path.normpath(file) self.file.write('\t\t\t<File\n' '\t\t\t\tRelativePath="%s">\n' '\t\t\t</File>\n' % (file))
Example #16
Source File: smb3.py From cracke-dit with MIT License | 6 votes |
def rmdir(self, shareName, pathName, password = None): # ToDo: Handle situations where share is password protected pathName = string.replace(pathName,'/', '\\') pathName = ntpath.normpath(pathName) if len(pathName) > 0 and pathName[0] == '\\': pathName = pathName[1:] treeId = self.connectTree(shareName) fileId = None try: fileId = self.create(treeId, pathName, desiredAccess=DELETE | FILE_READ_ATTRIBUTES | SYNCHRONIZE, shareMode=FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, creationOptions=FILE_DIRECTORY_FILE | FILE_OPEN_REPARSE_POINT, creationDisposition=FILE_OPEN, fileAttributes=0) from impacket import smb delete_req = smb.SMBSetFileDispositionInfo() delete_req['DeletePending'] = True self.setInfo(treeId, fileId, inputBlob=delete_req, fileInfoClass=SMB2_FILE_DISPOSITION_INFO) finally: if fileId is not None: self.close(treeId, fileId) self.disconnectTree(treeId) return True
Example #17
Source File: msvs.py From pivy with ISC License | 6 votes |
def __init__(self, dswfile, source, env): self.dswfile = os.path.normpath(str(dswfile)) self.env = env if 'projects' not in env: raise SCons.Errors.UserError("You must specify a 'projects' argument to create an MSVSSolution.") projects = env['projects'] if not SCons.Util.is_List(projects): raise SCons.Errors.InternalError("The 'projects' argument must be a list of nodes.") projects = SCons.Util.flatten(projects) if len(projects) < 1: raise SCons.Errors.UserError("You must specify at least one project to create an MSVSSolution.") self.dspfiles = map(str, projects) if 'name' in self.env: self.name = self.env['name'] else: self.name = os.path.basename(SCons.Util.splitext(self.dswfile)[0]) self.name = self.env.subst(self.name)
Example #18
Source File: smb3.py From cracke-dit with MIT License | 6 votes |
def remove(self, shareName, pathName, password = None): # ToDo: Handle situations where share is password protected pathName = string.replace(pathName,'/', '\\') pathName = ntpath.normpath(pathName) if len(pathName) > 0 and pathName[0] == '\\': pathName = pathName[1:] treeId = self.connectTree(shareName) fileId = None try: fileId = self.create(treeId, pathName,DELETE | FILE_READ_ATTRIBUTES, FILE_SHARE_DELETE, FILE_NON_DIRECTORY_FILE | FILE_DELETE_ON_CLOSE, FILE_OPEN, 0) finally: if fileId is not None: self.close(treeId, fileId) self.disconnectTree(treeId) return True
Example #19
Source File: msvs.py From pivy with ISC License | 6 votes |
def printSources(self, hierarchy, commonprefix): sorteditems = hierarchy.items() # TODO(1.5): #sorteditems.sort(lambda a, b: cmp(a[0].lower(), b[0].lower())) sorteditems.sort(lambda a, b: cmp(string.lower(a[0]), string.lower(b[0]))) # First folders, then files for key, value in sorteditems: if SCons.Util.is_Dict(value): self.file.write('\t\t\t<Filter\n' '\t\t\t\tName="%s"\n' '\t\t\t\tFilter="">\n' % (key)) self.printSources(value, commonprefix) self.file.write('\t\t\t</Filter>\n') for key, value in sorteditems: if SCons.Util.is_String(value): file = value if commonprefix: file = os.path.join(commonprefix, value) file = os.path.normpath(file) self.file.write('\t\t\t<File\n' '\t\t\t\tRelativePath="%s">\n' '\t\t\t</File>\n' % (file))
Example #20
Source File: smb3.py From cracke-dit with MIT License | 6 votes |
def storeFile(self, shareName, path, callback, mode = FILE_OVERWRITE_IF, offset = 0, password = None, shareAccessMode = FILE_SHARE_WRITE): # ToDo: Handle situations where share is password protected path = string.replace(path,'/', '\\') path = ntpath.normpath(path) if len(path) > 0 and path[0] == '\\': path = path[1:] treeId = self.connectTree(shareName) fileId = None try: fileId = self.create(treeId, path, FILE_WRITE_DATA, shareAccessMode, FILE_NON_DIRECTORY_FILE, mode, 0) finished = False writeOffset = offset while not finished: data = callback(self._Connection['MaxWriteSize']) if len(data) == 0: break written = self.write(treeId, fileId, data, writeOffset, len(data)) writeOffset += written finally: if fileId is not None: self.close(treeId, fileId) self.disconnectTree(treeId)
Example #21
Source File: msvs.py From pivy with ISC License | 6 votes |
def _generateGUID(slnfile, name): """This generates a dummy GUID for the sln file to use. It is based on the MD5 signatures of the sln filename plus the name of the project. It basically just needs to be unique, and not change with each invocation.""" m = hashlib.md5() # Normalize the slnfile path to a Windows path (\ separators) so # the generated file has a consistent GUID even if we generate # it on a non-Windows platform. m.update(ntpath.normpath(str(slnfile)) + str(name)) # TODO(1.5) #solution = m.hexdigest().upper() solution = string.upper(_hexdigest(m.digest())) # convert most of the signature to GUID form (discard the rest) solution = "{" + solution[:8] + "-" + solution[8:12] + "-" + solution[12:16] + "-" + solution[16:20] + "-" + solution[20:32] + "}" return solution
Example #22
Source File: types.py From deepWordBug with Apache License 2.0 | 6 votes |
def _parse_unix(cls, volume_config): parts = volume_config.split(':') if len(parts) > 3: raise ConfigurationError( "Volume %s has incorrect format, should be " "external:internal[:mode]" % volume_config) if len(parts) == 1: external = None internal = os.path.normpath(parts[0]) else: external = os.path.normpath(parts[0]) internal = os.path.normpath(parts[1]) mode = 'rw' if len(parts) == 3: mode = parts[2] return cls(external, internal, mode)
Example #23
Source File: wmiexec_delete.py From spraykatz with MIT License | 6 votes |
def do_get(self, src_path): try: import ntpath newPath = ntpath.normpath(ntpath.join(self.__pwd, src_path)) drive, tail = ntpath.splitdrive(newPath) filename = ntpath.basename(tail) fh = open(filename,'wb') self.__transferClient.getFile(drive[:-1]+'$', tail, fh.write) fh.close() except Exception as e: logging.error(str(e)) if os.path.exists(filename): os.remove(filename)
Example #24
Source File: msvs.py From web2board with GNU Lesser General Public License v3.0 | 6 votes |
def printSources(self, hierarchy, kind, commonprefix, filter_name): keywords = {'Source Files': 'ClCompile', 'Header Files': 'ClInclude', 'Local Headers': 'ClInclude', 'Resource Files': 'None', 'Other Files': 'None'} sorteditems = sorted(hierarchy.items(), key = lambda a: a[0].lower()) # First folders, then files for key, value in sorteditems: if SCons.Util.is_Dict(value): self.printSources(value, kind, commonprefix, filter_name + '\\' + key) for key, value in sorteditems: if SCons.Util.is_String(value): file = value if commonprefix: file = os.path.join(commonprefix, value) file = os.path.normpath(file) self.file.write('\t\t<%s Include="%s" />\n' % (keywords[kind], file)) self.filters_file.write('\t\t<%s Include="%s">\n' '\t\t\t<Filter>%s</Filter>\n' '\t\t</%s>\n' % (keywords[kind], file, filter_name, keywords[kind]))
Example #25
Source File: wmiexec.py From spraykatz with MIT License | 6 votes |
def do_get(self, src_path): try: import ntpath newPath = ntpath.normpath(ntpath.join(self.__pwd, src_path)) drive, tail = ntpath.splitdrive(newPath) filename = ntpath.basename(tail) fh = open(filename,'wb') self.__transferClient.getFile(drive[:-1]+'$', tail, fh.write) fh.close() except Exception as e: logging.error(str(e)) if os.path.exists(filename): os.remove(filename)
Example #26
Source File: test_ntpath.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_normpath(self): tester("ntpath.normpath('A//////././//.//B')", r'A\B') tester("ntpath.normpath('A/./B')", r'A\B') tester("ntpath.normpath('A/foo/../B')", r'A\B') tester("ntpath.normpath('C:A//B')", r'C:A\B') tester("ntpath.normpath('D:A/./B')", r'D:A\B') tester("ntpath.normpath('e:A/foo/../B')", r'e:A\B') tester("ntpath.normpath('C:///A//B')", r'C:\A\B') tester("ntpath.normpath('D:///A/./B')", r'D:\A\B') tester("ntpath.normpath('e:///A/foo/../B')", r'e:\A\B') tester("ntpath.normpath('..')", r'..') tester("ntpath.normpath('.')", r'.') tester("ntpath.normpath('')", r'.') tester("ntpath.normpath('/')", '\\') tester("ntpath.normpath('c:/')", 'c:\\') tester("ntpath.normpath('/../.././..')", '\\') tester("ntpath.normpath('c:/../../..')", 'c:\\') tester("ntpath.normpath('../.././..')", r'..\..\..') tester("ntpath.normpath('K:../.././..')", r'K:..\..\..') tester("ntpath.normpath('C:////a/b')", r'C:\a\b') tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b') tester("ntpath.normpath('\\\\.\\NUL')", r'\\.\NUL') tester("ntpath.normpath('\\\\?\\D:/XY\\Z')", r'\\?\D:/XY\Z')
Example #27
Source File: types.py From deepWordBug with Apache License 2.0 | 5 votes |
def parse(cls, mount_dict, normalize=False, win_host=False): if mount_dict.get('source'): if mount_dict['type'] == 'tmpfs': raise ConfigurationError('tmpfs mounts can not specify a source') mount_dict['source'] = normpath(mount_dict['source'], win_host) if normalize: mount_dict['source'] = normalize_path_for_engine(mount_dict['source']) return cls(**mount_dict)
Example #28
Source File: msvs.py From sitoa with Apache License 2.0 | 5 votes |
def PrintSourceFiles(self): categories = {'Source Files': 'cpp|c|cxx|l|y|def|odl|idl|hpj|bat', 'Header Files': 'h|hpp|hxx|hm|inl', 'Local Headers': 'h|hpp|hxx|hm|inl', 'Resource Files': 'r|rc|ico|cur|bmp|dlg|rc2|rct|bin|cnt|rtf|gif|jpg|jpeg|jpe', 'Other Files': ''} for kind in sorted(categories.keys(), key=lambda a: a.lower()): if not self.sources[kind]: continue # skip empty groups self.file.write('# Begin Group "' + kind + '"\n\n') typelist = categories[kind].replace('|', ';') self.file.write('# PROP Default_Filter "' + typelist + '"\n') for file in self.sources[kind]: file = os.path.normpath(file) self.file.write('# Begin Source File\n\n' 'SOURCE="' + file + '"\n' '# End Source File\n') self.file.write('# End Group\n') # add the SConscript file outside of the groups self.file.write('# Begin Source File\n\n' 'SOURCE="' + str(self.sconscript) + '"\n' '# End Source File\n')
Example #29
Source File: types.py From deepWordBug with Apache License 2.0 | 5 votes |
def normpath(path, win_host=False): """ Custom path normalizer that handles Compose-specific edge cases like UNIX paths on Windows hosts and vice-versa. """ sysnorm = ntpath.normpath if win_host else os.path.normpath # If a path looks like a UNIX absolute path on Windows, it probably is; # we'll need to revert the backslashes to forward slashes after normalization flip_slashes = path.startswith('/') and IS_WINDOWS_PLATFORM path = sysnorm(path) if flip_slashes: path = path.replace('\\', '/') return path
Example #30
Source File: common.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def normalizePath(filepath): """ Returns normalized string representation of a given filepath >>> normalizePath('//var///log/apache.log') '//var/log/apache.log' """ retVal = filepath if retVal: retVal = retVal.strip("\r\n") retVal = ntpath.normpath(retVal) if isWindowsDriveLetterPath(retVal) else posixpath.normpath(retVal) return retVal