Python posixpath 模块,basename() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用posixpath.basename()

项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_realpath_symlink_loops(self):
        # Bug #930024, return the path unchanged if we get into an infinite
        # symlink loop.
        try:
            old_path = abspath('.')
            os.symlink(ABSTFN, ABSTFN)
            self.assertEqual(realpath(ABSTFN), ABSTFN)

            os.symlink(ABSTFN+"1", ABSTFN+"2")
            os.symlink(ABSTFN+"2", ABSTFN+"1")
            self.assertEqual(realpath(ABSTFN+"1"), ABSTFN+"1")
            self.assertEqual(realpath(ABSTFN+"2"), ABSTFN+"2")

            # Test using relative path as well.
            os.chdir(dirname(ABSTFN))
            self.assertEqual(realpath(basename(ABSTFN)), ABSTFN)
        finally:
            os.chdir(old_path)
            support.unlink(ABSTFN)
            support.unlink(ABSTFN+"1")
            support.unlink(ABSTFN+"2")
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def _find_url_name(self, index_url, url_name, req):
        """Finds the true URL name of a package, when the given name isn't quite correct.
        This is usually used to implement case-insensitivity."""
        if not index_url.url.endswith('/'):
            # Vaguely part of the PyPI API... weird but true.
            ## FIXME: bad to modify this?
            index_url.url += '/'
        page = self._get_page(index_url, req)
        if page is None:
            logger.fatal('Cannot fetch index base URL %s' % index_url)
            return
        norm_name = normalize_name(req.url_name)
        for link in page.links:
            base = posixpath.basename(link.path.rstrip('/'))
            if norm_name == normalize_name(base):
                logger.notify('Real name of requirement %s is %s' % (url_name, base))
                return base
        return None
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def get_package_loader(self, package, package_path):
        from pkg_resources import DefaultProvider, ResourceManager, \
            get_provider
        loadtime = datetime.utcnow()
        provider = get_provider(package)
        manager = ResourceManager()
        filesystem_bound = isinstance(provider, DefaultProvider)

        def loader(path):
            if path is None:
                return None, None
            path = posixpath.join(package_path, path)
            if not provider.has_resource(path):
                return None, None
            basename = posixpath.basename(path)
            if filesystem_bound:
                return basename, self._opener(
                    provider.get_resource_filename(manager, path))
            return basename, lambda: (
                provider.get_resource_stream(manager, path),
                loadtime,
                0
            )
        return loader
项目:pyrsss    作者:butala    | 项目源码 | 文件源码
def fetch_sideshow_ionex(path,
                         date,
                         work_path=None,
                         templates=[JPLH_TEMPLATE, JPLH_ARCHIVE_TEMPLATE]):
    """
    ???
    """
    with SmartTempDir(work_path) as work_path:
        for template in templates:
            server_fname = template.format(date=date)
            local_fname = os.path.join(path, posixpath.basename(server_fname)[:-3])
            try:
                update_sideshow_file(local_fname,
                                     server_fname)
                return local_fname
            except:
                logger.info('could not download {}'.format(server_fname))
                continue
    raise RuntimeError('could not download IONEX file from sideshow for {:%Y-%m-%d}'.format(date))
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def get_package_loader(self, package, package_path):
        from pkg_resources import DefaultProvider, ResourceManager, \
            get_provider
        loadtime = datetime.utcnow()
        provider = get_provider(package)
        manager = ResourceManager()
        filesystem_bound = isinstance(provider, DefaultProvider)

        def loader(path):
            if path is None:
                return None, None
            path = posixpath.join(package_path, path)
            if not provider.has_resource(path):
                return None, None
            basename = posixpath.basename(path)
            if filesystem_bound:
                return basename, self._opener(
                    provider.get_resource_filename(manager, path))
            s = provider.get_resource_string(manager, path)
            return basename, lambda: (
                BytesIO(s),
                loadtime,
                len(s)
            )
        return loader
项目:harbour-sailfinder    作者:DylanVanAssche    | 项目源码 | 文件源码
def get_package_loader(self, package, package_path):
        from pkg_resources import DefaultProvider, ResourceManager, \
            get_provider
        loadtime = datetime.utcnow()
        provider = get_provider(package)
        manager = ResourceManager()
        filesystem_bound = isinstance(provider, DefaultProvider)

        def loader(path):
            if path is None:
                return None, None
            path = posixpath.join(package_path, path)
            if not provider.has_resource(path):
                return None, None
            basename = posixpath.basename(path)
            if filesystem_bound:
                return basename, self._opener(
                    provider.get_resource_filename(manager, path))
            return basename, lambda: (
                provider.get_resource_stream(manager, path),
                loadtime,
                0
            )
        return loader
项目:harbour-sailfinder    作者:DylanVanAssche    | 项目源码 | 文件源码
def get_package_loader(self, package, package_path):
        from pkg_resources import DefaultProvider, ResourceManager, \
            get_provider
        loadtime = datetime.utcnow()
        provider = get_provider(package)
        manager = ResourceManager()
        filesystem_bound = isinstance(provider, DefaultProvider)

        def loader(path):
            if path is None:
                return None, None
            path = posixpath.join(package_path, path)
            if not provider.has_resource(path):
                return None, None
            basename = posixpath.basename(path)
            if filesystem_bound:
                return basename, self._opener(
                    provider.get_resource_filename(manager, path))
            return basename, lambda: (
                provider.get_resource_stream(manager, path),
                loadtime,
                0
            )
        return loader
项目:python-tutorial    作者:Akuli    | 项目源码 | 文件源码
def find_links(this_file):
    """Read links of a markdown file.

    Return a list of (target, title, lineno) pairs where title can be None.
    """
    result = []

    with common.slashfix_open(this_file, 'r') as f:
        for match, lineno in common.find_links(f):
            target = match.group(2)
            if '#' in target:
                file, title = target.split('#', 1)
                if not file:
                    # link to this file, [blabla](#hi)
                    file = posixpath.basename(this_file)
            else:
                file = target
                title = None

            result.append((file, title, lineno))

    return result
项目:Texty    作者:sarthfrey    | 项目源码 | 文件源码
def get_package_loader(self, package, package_path):
        from pkg_resources import DefaultProvider, ResourceManager, \
            get_provider
        loadtime = datetime.utcnow()
        provider = get_provider(package)
        manager = ResourceManager()
        filesystem_bound = isinstance(provider, DefaultProvider)

        def loader(path):
            if path is None:
                return None, None
            path = posixpath.join(package_path, path)
            if not provider.has_resource(path):
                return None, None
            basename = posixpath.basename(path)
            if filesystem_bound:
                return basename, self._opener(
                    provider.get_resource_filename(manager, path))
            return basename, lambda: (
                provider.get_resource_stream(manager, path),
                loadtime,
                0
            )
        return loader
项目:nojs    作者:chrisdickinson    | 项目源码 | 文件源码
def __init__(self, symbolizer):
      self._symbolizer = symbolizer
      self._lib_file_name = posixpath.basename(symbolizer.elf_file_path)

      # The request queue (i.e. addresses pushed to addr2line's stdin and not
      # yet retrieved on stdout)
      self._request_queue = collections.deque()

      # This is essentially len(self._request_queue). It has been optimized to a
      # separate field because turned out to be a perf hot-spot.
      self.queue_size = 0

      # Keep track of the number of symbols a process has processed to
      # avoid a single process growing too big and using all the memory.
      self._processed_symbols_count = 0

      # Objects required to handle the addr2line subprocess.
      self._proc = None  # Subprocess.Popen(...) instance.
      self._thread = None  # Threading.thread instance.
      self._out_queue = None  # Queue.Queue instance (for buffering a2l stdout).
      self._RestartAddr2LineProcess()
项目:arithmancer    作者:google    | 项目源码 | 文件源码
def get_package_loader(self, package, package_path):
        from pkg_resources import DefaultProvider, ResourceManager, \
             get_provider
        loadtime = datetime.utcnow()
        provider = get_provider(package)
        manager = ResourceManager()
        filesystem_bound = isinstance(provider, DefaultProvider)
        def loader(path):
            if path is None:
                return None, None
            path = posixpath.join(package_path, path)
            if not provider.has_resource(path):
                return None, None
            basename = posixpath.basename(path)
            if filesystem_bound:
                return basename, self._opener(
                    provider.get_resource_filename(manager, path))
            return basename, lambda: (
                provider.get_resource_stream(manager, path),
                loadtime,
                0
            )
        return loader
项目:tesismometro    作者:joapaspe    | 项目源码 | 文件源码
def get_package_loader(self, package, package_path):
        from pkg_resources import DefaultProvider, ResourceManager, \
             get_provider
        loadtime = datetime.utcnow()
        provider = get_provider(package)
        manager = ResourceManager()
        filesystem_bound = isinstance(provider, DefaultProvider)
        def loader(path):
            if path is None:
                return None, None
            path = posixpath.join(package_path, path)
            if not provider.has_resource(path):
                return None, None
            basename = posixpath.basename(path)
            if filesystem_bound:
                return basename, self._opener(
                    provider.get_resource_filename(manager, path))
            return basename, lambda: (
                provider.get_resource_stream(manager, path),
                loadtime,
                0
            )
        return loader
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def _find_url_name(self, index_url, url_name, req):
        """Finds the true URL name of a package, when the given name isn't quite correct.
        This is usually used to implement case-insensitivity."""
        if not index_url.url.endswith('/'):
            # Vaguely part of the PyPI API... weird but true.
            ## FIXME: bad to modify this?
            index_url.url += '/'
        page = self._get_page(index_url, req)
        if page is None:
            logger.fatal('Cannot fetch index base URL %s' % index_url)
            return
        norm_name = normalize_name(req.url_name)
        for link in page.links:
            base = posixpath.basename(link.path.rstrip('/'))
            if norm_name == normalize_name(base):
                logger.notify('Real name of requirement %s is %s' % (url_name, base))
                return base
        return None
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def get_package_loader(self, package, package_path):
        from pkg_resources import DefaultProvider, ResourceManager, \
             get_provider
        loadtime = datetime.utcnow()
        provider = get_provider(package)
        manager = ResourceManager()
        filesystem_bound = isinstance(provider, DefaultProvider)
        def loader(path):
            if path is None:
                return None, None
            path = posixpath.join(package_path, path)
            if not provider.has_resource(path):
                return None, None
            basename = posixpath.basename(path)
            if filesystem_bound:
                return basename, self._opener(
                    provider.get_resource_filename(manager, path))
            return basename, lambda: (
                provider.get_resource_stream(manager, path),
                loadtime,
                0
            )
        return loader
项目:chromium-build    作者:discordapp    | 项目源码 | 文件源码
def __init__(self, symbolizer):
      self._symbolizer = symbolizer
      self._lib_file_name = posixpath.basename(symbolizer.elf_file_path)

      # The request queue (i.e. addresses pushed to addr2line's stdin and not
      # yet retrieved on stdout)
      self._request_queue = collections.deque()

      # This is essentially len(self._request_queue). It has been optimized to a
      # separate field because turned out to be a perf hot-spot.
      self.queue_size = 0

      # Keep track of the number of symbols a process has processed to
      # avoid a single process growing too big and using all the memory.
      self._processed_symbols_count = 0

      # Objects required to handle the addr2line subprocess.
      self._proc = None  # Subprocess.Popen(...) instance.
      self._thread = None  # Threading.thread instance.
      self._out_queue = None  # Queue.Queue instance (for buffering a2l stdout).
      self._RestartAddr2LineProcess()
项目:HAHA-NO-UR    作者:DamourYouKnow    | 项目源码 | 文件源码
def _handle_solo_scout(self):
        """
        Handles a solo scout

        :return: Path of scout image
        """
        card = await self._scout_cards()

        # Send error message if no card was returned
        if not card:
            self.results = []
            return None

        card = card[0]

        if card["card_image"] is None:
            url = "http:" + card["card_idolized_image"]
        else:
            url = "http:" + card["card_image"]

        fname = basename(urlsplit(url).path)
        image_path = idol_img_path.joinpath(fname)
        bytes_ = await get_one_img(
            url, image_path, self._bot.session_manager)
        return ScoutImage(bytes_, fname)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_realpath_resolve_first(self):
        # Bug #1213894: The first component of the path, if not absolute,
        # must be resolved too.

        try:
            old_path = abspath('.')
            os.mkdir(ABSTFN)
            os.mkdir(ABSTFN + "/k")
            os.symlink(ABSTFN, ABSTFN + "link")
            os.chdir(dirname(ABSTFN))

            base = basename(ABSTFN)
            self.assertEqual(realpath(base + "link"), ABSTFN)
            self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
        finally:
            os.chdir(old_path)
            support.unlink(ABSTFN + "link")
            safe_rmdir(ABSTFN + "/k")
            safe_rmdir(ABSTFN)
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def _find_url_name(self, index_url, url_name, req):
        """Finds the true URL name of a package, when the given name isn't quite correct.
        This is usually used to implement case-insensitivity."""
        if not index_url.url.endswith('/'):
            # Vaguely part of the PyPI API... weird but true.
            ## FIXME: bad to modify this?
            index_url.url += '/'
        page = self._get_page(index_url, req)
        if page is None:
            logger.fatal('Cannot fetch index base URL %s' % index_url)
            return
        norm_name = normalize_name(req.url_name)
        for link in page.links:
            base = posixpath.basename(link.path.rstrip('/'))
            if norm_name == normalize_name(base):
                logger.notify('Real name of requirement %s is %s' % (url_name, base))
                return base
        return None
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def score_url(self, url):
        """
        Give an url a score which can be used to choose preferred URLs
        for a given project release.
        """
        t = urlparse(url)
        basename = posixpath.basename(t.path)
        compatible = True
        is_wheel = basename.endswith('.whl')
        if is_wheel:
            compatible = is_compatible(Wheel(basename), self.wheel_tags)
        return (t.scheme != 'https', 'pypi.python.org' in t.netloc,
                is_wheel, compatible, basename)
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def filename(self):
        _, netloc, path, _, _ = urllib_parse.urlsplit(self.url)
        name = posixpath.basename(path.rstrip('/')) or netloc
        name = urllib_parse.unquote(name)
        assert name, ('URL %r produced no filename' % self.url)
        return name
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def splitext(self):
        return splitext(posixpath.basename(self.path.rstrip('/')))
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def show_url(self):
        return posixpath.basename(self.url.split('#', 1)[0].split('?', 1)[0])
项目:my-first-blog    作者:AnkurBegining    | 项目源码 | 文件源码
def score_url(self, url):
        """
        Give an url a score which can be used to choose preferred URLs
        for a given project release.
        """
        t = urlparse(url)
        basename = posixpath.basename(t.path)
        compatible = True
        is_wheel = basename.endswith('.whl')
        if is_wheel:
            compatible = is_compatible(Wheel(basename), self.wheel_tags)
        return (t.scheme != 'https', 'pypi.python.org' in t.netloc,
                is_wheel, compatible, basename)
项目:my-first-blog    作者:AnkurBegining    | 项目源码 | 文件源码
def filename(self):
        _, netloc, path, _, _ = urllib_parse.urlsplit(self.url)
        name = posixpath.basename(path.rstrip('/')) or netloc
        name = urllib_parse.unquote(name)
        assert name, ('URL %r produced no filename' % self.url)
        return name
项目:my-first-blog    作者:AnkurBegining    | 项目源码 | 文件源码
def splitext(self):
        return splitext(posixpath.basename(self.path.rstrip('/')))
项目:my-first-blog    作者:AnkurBegining    | 项目源码 | 文件源码
def show_url(self):
        return posixpath.basename(self.url.split('#', 1)[0].split('?', 1)[0])
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def score_url(self, url):
        """
        Give an url a score which can be used to choose preferred URLs
        for a given project release.
        """
        t = urlparse(url)
        return (t.scheme != 'https', 'pypi.python.org' in t.netloc,
                posixpath.basename(t.path))
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def filename(self):
        _, netloc, path, _, _ = urlparse.urlsplit(self.url)
        name = posixpath.basename(path.rstrip('/')) or netloc
        assert name, ('URL %r produced no filename' % self.url)
        return name
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def splitext(self):
        return splitext(posixpath.basename(self.path.rstrip('/')))
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def show_url(self):
        return posixpath.basename(self.url.split('#', 1)[0].split('?', 1)[0])
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def get_directory_loader(self, directory):
        def loader(path):
            if path is not None:
                path = os.path.join(directory, path)
            else:
                path = directory
            if os.path.isfile(path):
                return os.path.basename(path), self._opener(path)
            return None, None
        return loader
项目:pip-update-requirements    作者:alanhamlett    | 项目源码 | 文件源码
def score_url(self, url):
        """
        Give an url a score which can be used to choose preferred URLs
        for a given project release.
        """
        t = urlparse(url)
        basename = posixpath.basename(t.path)
        compatible = True
        is_wheel = basename.endswith('.whl')
        is_downloadable = basename.endswith(self.downloadable_extensions)
        if is_wheel:
            compatible = is_compatible(Wheel(basename), self.wheel_tags)
        return (t.scheme != 'https', 'pypi.python.org' in t.netloc,
                is_downloadable, is_wheel, compatible, basename)
项目:pip-update-requirements    作者:alanhamlett    | 项目源码 | 文件源码
def filename(self):
        _, netloc, path, _, _ = urllib_parse.urlsplit(self.url)
        name = posixpath.basename(path.rstrip('/')) or netloc
        name = urllib_parse.unquote(name)
        assert name, ('URL %r produced no filename' % self.url)
        return name
项目:pip-update-requirements    作者:alanhamlett    | 项目源码 | 文件源码
def splitext(self):
        return splitext(posixpath.basename(self.path.rstrip('/')))
项目:pip-update-requirements    作者:alanhamlett    | 项目源码 | 文件源码
def show_url(self):
        return posixpath.basename(self.url.split('#', 1)[0].split('?', 1)[0])
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def score_url(self, url):
        """
        Give an url a score which can be used to choose preferred URLs
        for a given project release.
        """
        t = urlparse(url)
        basename = posixpath.basename(t.path)
        compatible = True
        is_wheel = basename.endswith('.whl')
        if is_wheel:
            compatible = is_compatible(Wheel(basename), self.wheel_tags)
        return (t.scheme != 'https', 'pypi.python.org' in t.netloc,
                is_wheel, compatible, basename)
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def filename(self):
        _, netloc, path, _, _ = urllib_parse.urlsplit(self.url)
        name = posixpath.basename(path.rstrip('/')) or netloc
        name = urllib_parse.unquote(name)
        assert name, ('URL %r produced no filename' % self.url)
        return name
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def splitext(self):
        return splitext(posixpath.basename(self.path.rstrip('/')))
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def show_url(self):
        return posixpath.basename(self.url.split('#', 1)[0].split('?', 1)[0])
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def get_file_loader(self, filename):
        return lambda x: (os.path.basename(filename), self._opener(filename))
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def get_directory_loader(self, directory):
        def loader(path):
            if path is not None:
                path = os.path.join(directory, path)
            else:
                path = directory
            if os.path.isfile(path):
                return os.path.basename(path), self._opener(path)
            return None, None
        return loader
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def score_url(self, url):
        """
        Give an url a score which can be used to choose preferred URLs
        for a given project release.
        """
        t = urlparse(url)
        basename = posixpath.basename(t.path)
        compatible = True
        is_wheel = basename.endswith('.whl')
        if is_wheel:
            compatible = is_compatible(Wheel(basename), self.wheel_tags)
        return (t.scheme != 'https', 'pypi.python.org' in t.netloc,
                is_wheel, compatible, basename)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def filename(self):
        _, netloc, path, _, _ = urllib_parse.urlsplit(self.url)
        name = posixpath.basename(path.rstrip('/')) or netloc
        name = urllib_parse.unquote(name)
        assert name, ('URL %r produced no filename' % self.url)
        return name
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def splitext(self):
        return splitext(posixpath.basename(self.path.rstrip('/')))
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def show_url(self):
        return posixpath.basename(self.url.split('#', 1)[0].split('?', 1)[0])
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def score_url(self, url):
        """
        Give an url a score which can be used to choose preferred URLs
        for a given project release.
        """
        t = urlparse(url)
        basename = posixpath.basename(t.path)
        compatible = True
        is_wheel = basename.endswith('.whl')
        if is_wheel:
            compatible = is_compatible(Wheel(basename), self.wheel_tags)
        return (t.scheme != 'https', 'pypi.python.org' in t.netloc,
                is_wheel, compatible, basename)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def splitext(self):
        return splitext(posixpath.basename(self.path.rstrip('/')))
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def show_url(self):
        return posixpath.basename(self.url.split('#', 1)[0].split('?', 1)[0])
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def score_url(self, url):
        """
        Give an url a score which can be used to choose preferred URLs
        for a given project release.
        """
        t = urlparse(url)
        basename = posixpath.basename(t.path)
        compatible = True
        is_wheel = basename.endswith('.whl')
        if is_wheel:
            compatible = is_compatible(Wheel(basename), self.wheel_tags)
        return (t.scheme != 'https', 'pypi.python.org' in t.netloc,
                is_wheel, compatible, basename)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def filename(self):
        _, netloc, path, _, _ = urllib_parse.urlsplit(self.url)
        name = posixpath.basename(path.rstrip('/')) or netloc
        name = urllib_parse.unquote(name)
        assert name, ('URL %r produced no filename' % self.url)
        return name