当前位置: 首页>>代码示例>>Python>>正文


Python posixpath.splitext方法代码示例

本文整理汇总了Python中posixpath.splitext方法的典型用法代码示例。如果您正苦于以下问题:Python posixpath.splitext方法的具体用法?Python posixpath.splitext怎么用?Python posixpath.splitext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在posixpath的用法示例。


在下文中一共展示了posixpath.splitext方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: guess_type

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import splitext [as 别名]
def guess_type(self, path):
        """Guess the type of a file.

        Argument is a PATH (a filename).

        Return value is a string of the form type/subtype,
        usable for a MIME Content-type header.

        The default implementation looks the file's extension
        up in the table self.extensions_map, using application/octet-stream
        as a default; however it would be permissible (if
        slow) to look inside the data to make a better guess.

        """

        base, ext = posixpath.splitext(path)
        if ext in self.extensions_map:
            return self.extensions_map[ext]
        ext = ext.lower()
        if ext in self.extensions_map:
            return self.extensions_map[ext]
        else:
            return self.extensions_map[''] 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:25,代码来源:server.py

示例2: find_command

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import splitext [as 别名]
def find_command(cmd, paths=None, pathext=None):
    """Searches the PATH for the given command and returns its path"""
    if paths is None:
        paths = os.environ.get('PATH', '').split(os.pathsep)
    if isinstance(paths, string_types):
        paths = [paths]
    # check if there are funny path extensions for executables, e.g. Windows
    if pathext is None:
        pathext = get_pathext()
    pathext = [ext for ext in pathext.lower().split(os.pathsep) if len(ext)]
    # don't use extensions if the command ends with one of them
    if os.path.splitext(cmd)[1].lower() in pathext:
        pathext = ['']
    # check if we find the command on PATH
    for path in paths:
        # try without extension first
        cmd_path = os.path.join(path, cmd)
        for ext in pathext:
            # then including the extension
            cmd_path_ext = cmd_path + ext
            if os.path.isfile(cmd_path_ext):
                return cmd_path_ext
        if os.path.isfile(cmd_path):
            return cmd_path
    raise BadCommand('Cannot find command %r' % cmd) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:27,代码来源:util.py

示例3: unpack_file

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import splitext [as 别名]
def unpack_file(filename, location, content_type, link):
    filename = os.path.realpath(filename)
    if (content_type == 'application/zip'
        or filename.endswith('.zip')
        or filename.endswith('.pybundle')
        or filename.endswith('.whl')
        or zipfile.is_zipfile(filename)):
        unzip_file(filename, location, flatten=not filename.endswith(('.pybundle', '.whl')))
    elif (content_type == 'application/x-gzip'
          or tarfile.is_tarfile(filename)
          or splitext(filename)[1].lower() in ('.tar', '.tar.gz', '.tar.bz2', '.tgz', '.tbz')):
        untar_file(filename, location)
    elif (content_type and content_type.startswith('text/html')
          and is_svn_page(file_contents(filename))):
        # We don't really care about this
        from pip.vcs.subversion import Subversion
        Subversion('svn+' + link.url).unpack(location)
    else:
        ## FIXME: handle?
        ## FIXME: magic signatures?
        logger.fatal('Cannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive format'
                     % (filename, location, content_type))
        raise InstallationError('Cannot determine archive format of %s' % location) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:25,代码来源:util.py

示例4: AddSourceToTarget

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import splitext [as 别名]
def AddSourceToTarget(source, type, pbxp, xct):
  # TODO(mark): Perhaps source_extensions and library_extensions can be made a
  # little bit fancier.
  source_extensions = ['c', 'cc', 'cpp', 'cxx', 'm', 'mm', 's', 'swift']

  # .o is conceptually more of a "source" than a "library," but Xcode thinks
  # of "sources" as things to compile and "libraries" (or "frameworks") as
  # things to link with. Adding an object file to an Xcode target's frameworks
  # phase works properly.
  library_extensions = ['a', 'dylib', 'framework', 'o']

  basename = posixpath.basename(source)
  (root, ext) = posixpath.splitext(basename)
  if ext:
    ext = ext[1:].lower()

  if ext in source_extensions and type != 'none':
    xct.SourcesPhase().AddFile(source)
  elif ext in library_extensions and type != 'none':
    xct.FrameworksPhase().AddFile(source)
  else:
    # Files that aren't added to a sources or frameworks build phase can still
    # go into the project file, just not as part of a build phase.
    pbxp.AddOrGetFileInRootGroup(source) 
开发者ID:refack,项目名称:GYP3,代码行数:26,代码来源:xcode.py

示例5: PerformBuild

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import splitext [as 别名]
def PerformBuild(data, configurations, params):
  options = params['options']

  for build_file, build_file_dict in data.items():
    (build_file_root, build_file_ext) = os.path.splitext(build_file)
    if build_file_ext != '.gyp':
      continue
    xcodeproj_path = build_file_root + options.suffix + '.xcodeproj'
    if options.generator_output:
      xcodeproj_path = os.path.join(options.generator_output, xcodeproj_path)

  for config in configurations:
    arguments = ['xcodebuild', '-project', xcodeproj_path]
    arguments += ['-configuration', config]
    print("Building [%s]: %s" % (config, arguments))
    subprocess.check_call(arguments) 
开发者ID:refack,项目名称:GYP3,代码行数:18,代码来源:xcode.py

示例6: _guess_type

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import splitext [as 别名]
def _guess_type(self, path):
        """Guess the type of a file.

        Argument is a PATH (a filename).

        Return value is a string of the form type/subtype,
        usable for a MIME Content-type header.

        The default implementation looks the file's extension
        up in the table self.extensions_map, using application/octet-stream
        as a default; however it would be permissible (if
        slow) to look inside the data to make a better guess.
        """
        base, ext = posixpath.splitext(path)
        if ext in self.extensions_map:
            return self.extensions_map[ext]
        ext = ext.lower()
        if ext in self.extensions_map:
            return self.extensions_map[ext]
        else:
            return self.extensions_map[''] 
开发者ID:omererdem,项目名称:honeything,代码行数:23,代码来源:web-cmd.py

示例7: is_python

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import splitext [as 别名]
def is_python(self, path):
        """Test whether argument path is a Python script."""
        head, tail = os.path.splitext(path)
        return tail.lower() in (".py", ".pyw") 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:6,代码来源:server.py

示例8: _guess_zip_filename

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import splitext [as 别名]
def _guess_zip_filename(zf: zipfile.ZipFile) -> str:
    """Guess which file to use inside a zip file."""
    files = zf.namelist()
    if len(files) == 1:
        return files[0]
    else:
        for e in files:
            if posixpath.splitext(e)[0].lower() == 'hosts':
                return e
    raise FileNotFoundError("No hosts file found in zip") 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:12,代码来源:adblock.py

示例9: splitext

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import splitext [as 别名]
def splitext(path):
    """Like os.path.splitext, but take off .tar too"""
    base, ext = posixpath.splitext(path)
    if base.lower().endswith('.tar'):
        ext = base[-4:] + ext
        base = base[:-4]
    return base, ext 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:__init__.py

示例10: splitext

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import splitext [as 别名]
def splitext(self, the_path):
        """
        Like os.path.splitext, but takes off .tar, too
        """
        base, ext = posixpath.splitext(the_path)
        if base.lower().endswith('.tar'):
            ext = base[-4:] + ext
            base = base[:-4]
        return base, ext 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:11,代码来源:templates.py

示例11: is_archive_file

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import splitext [as 别名]
def is_archive_file(name):
    """Return True if `name` is a considered as an archive file."""
    ext = splitext(name)[1].lower()
    if ext in ARCHIVE_EXTENSIONS:
        return True
    return False 
开发者ID:python-poetry,项目名称:poetry,代码行数:8,代码来源:utils.py

示例12: splitext

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import splitext [as 别名]
def splitext(path):
    """Like os.path.splitext, but take off .tar too"""
    base, ext = posixpath.splitext(path)
    if base.lower().endswith(".tar"):
        ext = base[-4:] + ext
        base = base[:-4]
    return base, ext 
开发者ID:python-poetry,项目名称:poetry,代码行数:9,代码来源:utils.py

示例13: splitextTest

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import splitext [as 别名]
def splitextTest(self, path, filename, ext):
        self.assertEqual(posixpath.splitext(path), (filename, ext))
        self.assertEqual(posixpath.splitext("/" + path), ("/" + filename, ext))
        self.assertEqual(posixpath.splitext("abc/" + path), ("abc/" + filename, ext))
        self.assertEqual(posixpath.splitext("abc.def/" + path), ("abc.def/" + filename, ext))
        self.assertEqual(posixpath.splitext("/abc.def/" + path), ("/abc.def/" + filename, ext))
        self.assertEqual(posixpath.splitext(path + "/"), (filename + ext + "/", "")) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_posixpath.py


注:本文中的posixpath.splitext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。