當前位置: 首頁>>代碼示例>>Python>>正文


Python fnmatch.fnmatch方法代碼示例

本文整理匯總了Python中fnmatch.fnmatch方法的典型用法代碼示例。如果您正苦於以下問題:Python fnmatch.fnmatch方法的具體用法?Python fnmatch.fnmatch怎麽用?Python fnmatch.fnmatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fnmatch的用法示例。


在下文中一共展示了fnmatch.fnmatch方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _get_measures_by_name

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def _get_measures_by_name(resources, metric_wildcards, operations,
                              start, stop, granularity, needed_overlap, fill,
                              details):

        references = []
        for r in resources:
            references.extend([
                processor.MetricReference(m, agg, r, wildcard)
                for wildcard, agg in metric_wildcards
                for m in r.metrics if fnmatch.fnmatch(m.name, wildcard)
            ])

        if not references:
            raise indexer.NoSuchMetric(set((m for (m, a) in metric_wildcards)))

        response = {
            "measures": get_measures_or_abort(
                references, operations, start, stop, granularity,
                needed_overlap, fill)
        }
        if details:
            response["references"] = set((r.resource for r in references))
        return response 
開發者ID:gnocchixyz,項目名稱:gnocchi,代碼行數:25,代碼來源:api.py

示例2: load_data

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def load_data(folder):
    images_sat = [img for img in os.listdir(os.path.join(folder, "sat_img")) if fnmatch.fnmatch(img, "*.tif*")]
    images_map = [img for img in os.listdir(os.path.join(folder, "map")) if fnmatch.fnmatch(img, "*.tif*")]
    assert(len(images_sat) == len(images_map))
    images_sat.sort()
    images_map.sort()
    # images are 1500 by 1500 pixels each
    data = np.zeros((len(images_sat), 3, 1500, 1500), dtype=np.uint8)
    target = np.zeros((len(images_sat), 1, 1500, 1500), dtype=np.uint8)
    ctr = 0
    for sat_im, map_im in zip(images_sat, images_map):
        data[ctr] = plt.imread(os.path.join(folder, "sat_img", sat_im)).transpose((2, 0, 1))
        # target has values 0 and 255. make that 0 and 1
        target[ctr, 0] = plt.imread(os.path.join(folder, "map", map_im))/255
        ctr += 1
    return data, target 
開發者ID:Lasagne,項目名稱:Recipes,代碼行數:18,代碼來源:massachusetts_road_dataset_utils.py

示例3: match

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def match(path: Path, pattern_list: Iterable) -> bool:
    """
    Check if a Path matches to one of the patterns

    Internally fnmatch is used.
    See https://docs.python.org/3/library/fnmatch.html for details.

    Arguments:
        path (Path): Path to check if it matches to one of the patterns
        pattern_list (iterable): Iterable (e.g tuple or list) of patterns to
            match against the path

    Returns:
        Boolean: True if path matches a pattern of the list
    """
    for pattern in pattern_list:
        if fnmatch.fnmatch(str(path), pattern):
            return True
    return False 
開發者ID:greenbone,項目名稱:autohooks,代碼行數:21,代碼來源:path.py

示例4: fnmatch

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def fnmatch(self, pattern):
        """return true if the basename/fullname matches the glob-'pattern'.

        valid pattern characters::

            *       matches everything
            ?       matches any single character
            [seq]   matches any character in seq
            [!seq]  matches any char not in seq

        If the pattern contains a path-separator then the full path
        is used for pattern matching and a '*' is prepended to the
        pattern.

        if the pattern doesn't contain a path-separator the pattern
        is only matched against the basename.
        """
        return FNMatcher(pattern)(self) 
開發者ID:pytest-dev,項目名稱:py,代碼行數:20,代碼來源:common.py

示例5: __call__

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def __call__(self, path):
        pattern = self.pattern

        if (pattern.find(path.sep) == -1 and
        iswin32 and
        pattern.find(posixpath.sep) != -1):
            # Running on Windows, the pattern has no Windows path separators,
            # and the pattern has one or more Posix path separators. Replace
            # the Posix path separators with the Windows path separator.
            pattern = pattern.replace(posixpath.sep, path.sep)

        if pattern.find(path.sep) == -1:
            name = path.basename
        else:
            name = str(path) # path.strpath # XXX svn?
            if not os.path.isabs(pattern):
                pattern = '*' + path.sep + pattern
        return fnmatch.fnmatch(name, pattern) 
開發者ID:pytest-dev,項目名稱:py,代碼行數:20,代碼來源:common.py

示例6: _get_source

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def _get_source(self):
        if Version(self.version) == "3.4.0":
            filename = os.path.basename(self.conan_data["sources"][self.version]["url"])
            tools.download(filename=filename, **self.conan_data["sources"][self.version])

            with tarfile.TarFile.open(filename, 'r:*') as tarredgzippedFile:
                # NOTE: In fruit v3.4.0, The archive file contains the file names
                # build and BUILD in the extras/bazel_root/third_party/fruit directory.
                # Extraction fails on a case-insensitive file system due to file
                # name conflicts.
                # Exclude build as a workaround.
                exclude_pattern = "%s/extras/bazel_root/third_party/fruit/build" % (self._extracted_dir,)
                members = list(filter(lambda m: not fnmatch(m.name, exclude_pattern),
                                    tarredgzippedFile.getmembers()))
                tarredgzippedFile.extractall(".", members=members)
        else:
            tools.get(**self.conan_data["sources"][self.version]) 
開發者ID:conan-io,項目名稱:conan-center-index,代碼行數:19,代碼來源:conanfile.py

示例7: _ancestor_target

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def _ancestor_target(self):
        if "CONAN_OPENSSL_CONFIGURATION" in os.environ:
            return os.environ["CONAN_OPENSSL_CONFIGURATION"]
        query = "%s-%s-%s" % (self.settings.os, self.settings.arch, self.settings.compiler)
        ancestor = next((self._targets[i] for i in self._targets if fnmatch.fnmatch(query, i)), None)
        if not ancestor:
            raise ConanInvalidConfiguration("unsupported configuration: %s %s %s, "
                                            "please open an issue: "
                                            "https://github.com/conan-io/conan-center-index/issues. "
                                            "alternatively, set the CONAN_OPENSSL_CONFIGURATION environment variable "
                                            "into your conan profile "
                                            "(list of configurations can be found by running './Configure --help')." %
                                            (self.settings.os,
                                            self.settings.arch,
                                            self.settings.compiler))
        return ancestor 
開發者ID:conan-io,項目名稱:conan-center-index,代碼行數:18,代碼來源:conanfile.py

示例8: expect

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def expect(self, cat, messagepattern="*", invert=False):
        __tracebackhide__ = True
        if not messagepattern.startswith("*"):
            messagepattern = "*{}".format(messagepattern)
        while self._index < len(self.instance.reported_lines):
            try:
                call = self.getnext(cat)
            except LookupError:
                break
            for lmsg in call[1:]:
                lmsg = str(lmsg).replace("\n", " ")
                if fnmatch(lmsg, messagepattern):
                    if invert:
                        raise AssertionError(
                            "found {}({!r}), didn't expect it".format(cat, messagepattern),
                        )
                    return
        if not invert:
            raise AssertionError(
                "looking for {}({!r}), no reports found at >={:d} in {!r}".format(
                    cat, messagepattern, self._index + 1, self.instance.reported_lines,
                ),
            ) 
開發者ID:tox-dev,項目名稱:tox,代碼行數:25,代碼來源:_pytestplugin.py

示例9: fnmatch

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def fnmatch(filename, patterns, default=True):
    # type: (str, List[str], bool) -> bool
    """Wrap :func:`fnmatch.fnmatch` to add some functionality.

    :param str filename:
        Name of the file we're trying to match.
    :param list patterns:
        Patterns we're using to try to match the filename.
    :param bool default:
        The default value if patterns is empty
    :returns:
        True if a pattern matches the filename, False if it doesn't.
        ``default`` if patterns is empty.
    """
    if not patterns:
        return default
    return any(_fnmatch.fnmatch(filename, pattern) for pattern in patterns) 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:19,代碼來源:utils.py

示例10: should_skip

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def should_skip(filename, config, path='/'):
    """Returns True if the file should be skipped based on the passed in settings."""
    for skip_path in config['skip']:
        if posixpath.abspath(posixpath.join(path, filename)) == posixpath.abspath(skip_path.replace('\\', '/')):
            return True

    position = os.path.split(filename)
    while position[1]:
        if position[1] in config['skip']:
            return True
        position = os.path.split(position[0])

    for glob in config['skip_glob']:
        if fnmatch.fnmatch(filename, glob):
            return True

    return False 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:19,代碼來源:settings.py

示例11: test_fnmatch

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def test_fnmatch(self):
        """ Test the matching done by fnmatch. """
        matrix = [
            ["pagure", "*", True],
            ["ns/pagure", "*", True],
            ["forks/user/ns/pagure", "*", True],
            ["forks/user/pagure", "*", True],
            ["pagure", "rpms/*", False],
            ["rpms/pagure", "rpms/*", True],
            ["forks/user/pagure", "rpms/*", False],
            ["forks/user/pagure", "rpms/*", False],
            ["pagure", "pagure", True],
            ["rpms/pagure", "pagure", False],
            ["forks/user/pagure", "pagure", False],
            ["forks/user/pagure", "pagure", False],
            ["pagure", "pag*", True],
            ["rpms/pagure", "pag*", False],
            ["forks/user/pagure", "pag*", False],
            ["forks/user/pagure", "pag*", False],
        ]
        for row in matrix:
            self.assertEqual(fnmatch.fnmatch(row[0], row[1]), row[2]) 
開發者ID:Pagure,項目名稱:pagure,代碼行數:24,代碼來源:test_fnmatch.py

示例12: read_train_and_test_data_from_path

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def read_train_and_test_data_from_path(path):
    only_files = [f for f in listdir(path) if (isfile(join(path, f)))]
    train_files = [f for f in only_files if fnmatch.fnmatch(f, '*_train.tsv')]
    data_names = ["_".join(f.split("_")[:-1]) for f in train_files]
    data_table = {}
    data_table_no_entities = {}
    
    for name in data_names:
        train_data, train_labels = read_data_from_file(join(path, name + "_train.tsv"))
        test_data, test_labels = read_data_from_file(join(path, name + "_test.tsv"))
        
        is_multiclass = name.find('multiclass') > -1
        
        # without entities as well:
        train_data_no_entities, indices_to_remove = remove_entities_from_text(train_data)
        train_labels_no_entities = train_labels
        test_data_no_entities, indices_to_remove = remove_entities_from_text(test_data)
        test_labels_no_entities = test_labels
        
        data_table[name] = TrainTestData(train_data, train_labels, test_data, test_labels, is_multiclass)
        data_table_no_entities[name] = TrainTestData(train_data_no_entities, train_labels_no_entities,
                                                     test_data_no_entities, test_labels_no_entities, is_multiclass)
    
    return data_table, data_table_no_entities 
開發者ID:CatalystCode,項目名稱:corpus-to-graph-ml,代碼行數:26,代碼來源:features_generation_tools.py

示例13: _expand_package_ids

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def _expand_package_ids(self, id_patterns, source):
        for id_pattern in id_patterns:
            if '*' in id_pattern:
                pkg_ids = [
                    pkg_id for pkg_id in source if fnmatch(pkg_id, id_pattern)
                ]

                if pkg_ids:
                    yield from pkg_ids

                else:
                    # The pattern could not be expanded, yield it back
                    yield id_pattern

            else:
                yield id_pattern 
開發者ID:ideascube,項目名稱:ideascube,代碼行數:18,代碼來源:catalog.py

示例14: is_hidden

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def is_hidden(self, filename, path, goto=''):
        if not (path or goto):  # special case for ThisPC
            return False
        tests = self.view.settings().get('dired_hidden_files_patterns', ['.*'])
        if isinstance(tests, str):
            tests = [tests]
        if any(fnmatch.fnmatch(filename, pattern) for pattern in tests):
            return True
        if sublime.platform() != 'windows':
            return False
        # check for attribute on windows:
        try:
            attrs = ctypes.windll.kernel32.GetFileAttributesW(join(path, goto, filename))
            assert attrs != -1
            result = bool(attrs & 2)
        except (AttributeError, AssertionError):
            result = False
        return result 
開發者ID:aziz,項目名稱:SublimeFileBrowser,代碼行數:20,代碼來源:common.py

示例15: match_file

# 需要導入模塊: import fnmatch [as 別名]
# 或者: from fnmatch import fnmatch [as 別名]
def match_file(filename, exclude):
    """Return True if file is okay for modifying/recursing."""
    base_name = os.path.basename(filename)

    if base_name.startswith('.'):
        return False

    for pattern in exclude:
        if fnmatch.fnmatch(base_name, pattern):
            return False
        if fnmatch.fnmatch(filename, pattern):
            return False

    if not os.path.isdir(filename) and not is_python_file(filename):
        return False

    return True 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:19,代碼來源:autopep8.py


注:本文中的fnmatch.fnmatch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。