Python fnmatch 模块,fnmatchcase() 实例源码

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

项目:jx-sqlite    作者:mozilla    | 项目源码 | 文件源码
def find_packages(where='.', lib_prefix='', exclude=()):
    """
    SNAGGED FROM distribute-0.6.49-py2.7.egg/setuptools/__init__.py
    """
    out = []
    stack = [(convert_path(where), lib_prefix)]
    while stack:
        where, prefix = stack.pop(0)
        for name in os.listdir(where):
            fn = os.path.join(where,name)
            if ('.' not in name and os.path.isdir(fn) and
                os.path.isfile(os.path.join(fn, '__init__.py'))
            ):
                out.append(prefix + name); stack.append((fn, prefix+name + '.'))
    for pat in list(exclude)+['ez_setup', 'distribute_setup']:
        from fnmatch import fnmatchcase
        out = [item for item in out if not fnmatchcase(item, pat)]
    return out
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def multi_wildcard_match(self, wildcards):
        if hasattr(self, 'nkd_fnmatchcase'):
            fnmatchcase = self.nkd_fnmatchcase
        else:
            from fnmatch import fnmatchcase
            self.nkd_fnmatchcase = fnmatchcase
        wc_list = wildcards.split('|')
        return_list = []
        for wc in wc_list:
            temp_list = [ x for x in self if fnmatchcase(x, wc) ]
            for result in temp_list:
                return_list.append(result)
        return return_list

    #------------------------------------------------------------------------------
    # XList Cast Methods
    #------------------------------------------------------------------------------
    #------------------------------------------------------------------------------
    # [ xset method ] (XSet)
    #  return an XSet with unique XList item values and XList attributes
    #------------------------------------------------------------------------------
项目:pymotw3    作者:reingart    | 项目源码 | 文件源码
def Apply(self, url):
    """ Process the URL, as above. """
    if (not url) or (not url.loc):
      return None

    if self._wildcard:
      if fnmatch.fnmatchcase(url.loc, self._wildcard):
        return self._pass
      return None

    if self._regexp:
      if self._regexp.search(url.loc):
        return self._pass
      return None

    assert False # unreachable
  #end def Apply
#end class Filter
项目:fac    作者:mickael9    | 项目源码 | 文件源码
def _find(cls, pattern, manager, name, version):
        name = '*' if name is None else name

        installed = glob(
            os.path.join(
                manager.config.mods_directory,
                pattern
            )
        )
        for path in installed:
            try:
                mod = cls(manager, path)

            except Exception as ex:
                print('Warning: invalid mod %s: %s' % (path, ex))
                continue

            if not fnmatchcase(mod.name, name):
                continue

            if version is not None and version != mod.version:
                continue

            yield mod
项目:pyramid_webpack    作者:stevearc    | 项目源码 | 文件源码
def _chunk_filter(self, extensions):
        """ Create a filter from the extensions and ignore files """
        if isinstance(extensions, six.string_types):
            extensions = extensions.split()

        def _filter(chunk):
            """ Exclusion filter """
            name = chunk['name']
            if extensions is not None:
                if not any(name.endswith(e) for e in extensions):
                    return False
            for pattern in self.state.ignore_re:
                if pattern.match(name):
                    return False
            for pattern in self.state.ignore:
                if fnmatch.fnmatchcase(name, pattern):
                    return False
            return True
        return _filter
项目:plone.server    作者:plone    | 项目源码 | 文件源码
def apply_cors(request):
    """Second part of the cors function to validate."""
    from plone.server import app_settings
    headers = {}
    origin = request.headers.get('Origin', None)
    if origin:
        if not any([fnmatch.fnmatchcase(origin, o)
                    for o in app_settings['cors']['allow_origin']]):
            logger.error('Origin %s not allowed' % origin)
            raise HTTPUnauthorized()
        elif request.headers.get('Access-Control-Allow-Credentials', False):
            headers['Access-Control-Allow-Origin', origin]
        else:
            if any([o == "*" for o in app_settings['cors']['allow_origin']]):
                headers['Access-Control-Allow-Origin'] = '*'
            else:
                headers['Access-Control-Allow-Origin'] = origin
    if request.headers.get(
            'Access-Control-Request-Method', None) != 'OPTIONS':
        if app_settings['cors']['allow_credentials']:
            headers['Access-Control-Allow-Credentials'] = 'True'
        if len(app_settings['cors']['allow_headers']):
            headers['Access-Control-Expose-Headers'] = \
                ', '.join(app_settings['cors']['allow_headers'])
    return headers
项目:moz-sql-parser    作者:mozilla    | 项目源码 | 文件源码
def find_packages(where='.', lib_prefix='', exclude=()):
    """
    SNAGGED FROM distribute-0.6.49-py2.7.egg/setuptools/__init__.py
    """
    out = []
    stack=[(convert_path(where), lib_prefix)]
    while stack:
        where,prefix = stack.pop(0)
        for name in os.listdir(where):
            fn = os.path.join(where,name)
            if ('.' not in name and os.path.isdir(fn) and
                os.path.isfile(os.path.join(fn,'__init__.py'))
            ):
                out.append(prefix+name); stack.append((fn,prefix+name+'.'))
    for pat in list(exclude)+['ez_setup', 'distribute_setup']:
        from fnmatch import fnmatchcase
        out = [item for item in out if not fnmatchcase(item,pat)]
    return out
项目:PigeonScript    作者:SilversApprentice    | 项目源码 | 文件源码
def match(self, path_pattern):
        """
        Return True if this path matches the given pattern.
        """
        cf = self._flavour.casefold
        path_pattern = cf(path_pattern)
        drv, root, pat_parts = self._flavour.parse_parts((path_pattern,))
        if not pat_parts:
            raise ValueError("empty pattern")
        if drv and drv != cf(self._drv):
            return False
        if root and root != cf(self._root):
            return False
        parts = self._cparts
        if drv or root:
            if len(pat_parts) != len(parts):
                return False
            pat_parts = pat_parts[1:]
        elif len(pat_parts) > len(parts):
            return False
        for part, pat in zip(reversed(parts), reversed(pat_parts)):
            if not fnmatch.fnmatchcase(part, pat):
                return False
        return True
项目:guillotina    作者:plone    | 项目源码 | 文件源码
def get_headers(self):
        settings = await self.get_settings()
        headers = {}
        origin = self.request.headers.get('Origin', None)
        if origin:
            if '*' in settings['allow_origin']:
                headers['Access-Control-Allow-Origin'] = '*'
            elif any([fnmatch.fnmatchcase(origin, o)
                      for o in settings['allow_origin']]):
                headers['Access-Control-Allow-Origin'] = origin
            else:
                logger.error('Origin %s not allowed' % origin,
                             request=self.request)
                raise HTTPUnauthorized()
        if self.request.headers.get(
                'Access-Control-Request-Method', None) != 'OPTIONS':
            if settings['allow_credentials']:
                headers['Access-Control-Allow-Credentials'] = 'True'
            if len(settings['allow_headers']):
                headers['Access-Control-Expose-Headers'] = ', '.join(
                    settings['allow_headers'])
        return headers
项目:click-configfile    作者:click-contrib    | 项目源码 | 文件源码
def fnmatch(self, pattern, normcase=None):
        """ Return ``True`` if `self.name` matches the given `pattern`.

        `pattern` - A filename pattern with wildcards,
            for example ``'*.py'``. If the pattern contains a `normcase`
            attribute, it is applied to the name and path prior to comparison.

        `normcase` - (optional) A function used to normalize the pattern and
            filename before matching. Defaults to :meth:`self.module`, which defaults
            to :meth:`os.path.normcase`.

        .. seealso:: :func:`fnmatch.fnmatch`
        """
        default_normcase = getattr(pattern, 'normcase', self.module.normcase)
        normcase = normcase or default_normcase
        name = normcase(self.name)
        pattern = normcase(pattern)
        return fnmatch.fnmatchcase(name, pattern)
项目:click-configfile    作者:click-contrib    | 项目源码 | 文件源码
def match(self, path_pattern):
        """
        Return True if this path matches the given pattern.
        """
        cf = self._flavour.casefold
        path_pattern = cf(path_pattern)
        drv, root, pat_parts = self._flavour.parse_parts((path_pattern,))
        if not pat_parts:
            raise ValueError("empty pattern")
        if drv and drv != cf(self._drv):
            return False
        if root and root != cf(self._root):
            return False
        parts = self._cparts
        if drv or root:
            if len(pat_parts) != len(parts):
                return False
            pat_parts = pat_parts[1:]
        elif len(pat_parts) > len(parts):
            return False
        for part, pat in zip(reversed(parts), reversed(pat_parts)):
            if not fnmatch.fnmatchcase(part, pat):
                return False
        return True
项目:stor    作者:counsyl    | 项目源码 | 文件源码
def fnmatch(self, pattern, normcase=None):
        """Return ``True`` if :attr:`name` matches the given ``pattern``.

        .. seealso:: :func:`fnmatch.fnmatch`

        Args:
            pattern (str): A filename pattern with wildcards,
                for example ``'*.py'``. If the pattern contains a `normcase`
                attribute, it is applied to the name and path prior to comparison.
            normcase (func, optional): A function used to normalize the pattern and
                filename before matching. Defaults to :meth:`self.module`, which defaults
                to :meth:`os.path.normcase`.

        """
        default_normcase = getattr(pattern, 'normcase', self.path_module.normcase)
        normcase = normcase or default_normcase
        name = normcase(self.name)
        pattern = normcase(pattern)
        return fnmatch.fnmatchcase(name, pattern)
项目:Marty    作者:NaPs    | 项目源码 | 文件源码
def list_backups(self, pattern=None, since=None, until=None):
        labels = self.list_labels()
        for label in labels:
            if pattern is not None and not fnmatch.fnmatchcase(label, pattern):
                continue  # Ignore non matching labels

            try:
                backup = self.get_backup(label)
            except MartyObjectDecodeError:
                continue  # Ignore non-backup labels

            if since is not None and backup.start_date < since:
                continue  # Ignore backups before since date

            if until is not None and backup.start_date > until:
                continue  # Ignore backups before until date

            yield label, backup
项目:eclcli    作者:nttcom    | 项目源码 | 文件源码
def clear_wildcard_hooks(hc, stack_id, stack_patterns, hook_type,
                         resource_pattern):
    if stack_patterns:
        for resource in hc.resources.list(stack_id):
            res_name = resource.resource_name
            if fnmatch.fnmatchcase(res_name, stack_patterns[0]):
                nested_stack = hc.resources.get(
                    stack_id=stack_id,
                    resource_name=res_name)
                clear_wildcard_hooks(
                    hc,
                    nested_stack.physical_resource_id,
                    stack_patterns[1:], hook_type, resource_pattern)
    else:
        for resource in hc.resources.list(stack_id):
            res_name = resource.resource_name
            if fnmatch.fnmatchcase(res_name, resource_pattern):
                clear_hook(hc, stack_id, res_name, hook_type)
项目:click-configfile    作者:jenisys    | 项目源码 | 文件源码
def fnmatch(self, pattern, normcase=None):
        """ Return ``True`` if `self.name` matches the given `pattern`.

        `pattern` - A filename pattern with wildcards,
            for example ``'*.py'``. If the pattern contains a `normcase`
            attribute, it is applied to the name and path prior to comparison.

        `normcase` - (optional) A function used to normalize the pattern and
            filename before matching. Defaults to :meth:`self.module`, which defaults
            to :meth:`os.path.normcase`.

        .. seealso:: :func:`fnmatch.fnmatch`
        """
        default_normcase = getattr(pattern, 'normcase', self.module.normcase)
        normcase = normcase or default_normcase
        name = normcase(self.name)
        pattern = normcase(pattern)
        return fnmatch.fnmatchcase(name, pattern)
项目:click-configfile    作者:jenisys    | 项目源码 | 文件源码
def match(self, path_pattern):
        """
        Return True if this path matches the given pattern.
        """
        cf = self._flavour.casefold
        path_pattern = cf(path_pattern)
        drv, root, pat_parts = self._flavour.parse_parts((path_pattern,))
        if not pat_parts:
            raise ValueError("empty pattern")
        if drv and drv != cf(self._drv):
            return False
        if root and root != cf(self._root):
            return False
        parts = self._cparts
        if drv or root:
            if len(pat_parts) != len(parts):
                return False
            pat_parts = pat_parts[1:]
        elif len(pat_parts) > len(parts):
            return False
        for part, pat in zip(reversed(parts), reversed(pat_parts)):
            if not fnmatch.fnmatchcase(part, pat):
                return False
        return True
项目:dymo-m10-python    作者:pbrf    | 项目源码 | 文件源码
def find_packages(where='.', exclude=()):
    """Return a list all Python packages found within directory 'where'

    'where' should be supplied as a "cross-platform" (i.e. URL-style) path; it
    will be converted to the appropriate local path syntax.  'exclude' is a
    sequence of package names to exclude; '*' can be used as a wildcard in the
    names, such that 'foo.*' will exclude all subpackages of 'foo' (but not
    'foo' itself).
    """
    out = []
    stack=[(convert_path(where), '')]
    while stack:
        where,prefix = stack.pop(0)
        for name in os.listdir(where):
            fn = os.path.join(where,name)
            if ('.' not in name and os.path.isdir(fn) and
                os.path.isfile(os.path.join(fn,'__init__.py'))
            ):
                out.append(prefix+name); stack.append((fn,prefix+name+'.'))
    for pat in list(exclude)+['ez_setup']:
        from fnmatch import fnmatchcase
        out = [item for item in out if not fnmatchcase(item,pat)]
    return out
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def match(self, path_pattern):
        """
        Return True if this path matches the given pattern.
        """
        cf = self._flavour.casefold
        path_pattern = cf(path_pattern)
        drv, root, pat_parts = self._flavour.parse_parts((path_pattern,))
        if not pat_parts:
            raise ValueError("empty pattern")
        if drv and drv != cf(self._drv):
            return False
        if root and root != cf(self._root):
            return False
        parts = self._cparts
        if drv or root:
            if len(pat_parts) != len(parts):
                return False
            pat_parts = pat_parts[1:]
        elif len(pat_parts) > len(parts):
            return False
        for part, pat in zip(reversed(parts), reversed(pat_parts)):
            if not fnmatch.fnmatchcase(part, pat):
                return False
        return True
项目:iampoliciesgonewild    作者:monkeysecurity    | 项目源码 | 文件源码
def _expand_wildcard_action(action):
    """
    :param action: 'autoscaling:*'
    :return: A list of all autoscaling permissions matching the wildcard
    """
    if isinstance(action, list):
        expanded_actions = []
        for item in action:
            expanded_actions.extend(_expand_wildcard_action(item))
        return expanded_actions

    else:
        if '*' in action:
            expanded = [
                expanded_action.lower() for expanded_action in all_permissions if fnmatch.fnmatchcase(
                    expanded_action.lower(), action.lower()
                )
            ]

            # if we get a wildcard for a tech we've never heard of, just return the wildcard
            if not expanded:
                return [action.lower()]

            return expanded
        return [action.lower()]
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def _build_filter(*patterns):
        """
        Given a list of patterns, return a callable that will be true only if
        the input matches at least one of the patterns.
        """
        return lambda name: any(fnmatchcase(name, pat=pat) for pat in patterns)
项目:my-first-blog    作者:AnkurBegining    | 项目源码 | 文件源码
def _build_filter(*patterns):
        """
        Given a list of patterns, return a callable that will be true only if
        the input matches at least one of the patterns.
        """
        return lambda name: any(fnmatchcase(name, pat=pat) for pat in patterns)
项目:bob    作者:BobBuildTool    | 项目源码 | 文件源码
def funMatchScm(args, **options):
    if len(args) != 2: raise ParseError("matchScm expects two arguments")
    name = args[0]
    val = args[1]
    try:
        pkg = options['package']
    except KeyError:
        raise ParseError('matchScm can only be used for queries')

    for scm in pkg.getCheckoutStep().getScmList():
        for props in scm.getProperties():
            if fnmatch.fnmatchcase(props.get(name), val): return "true"

    return "false"
项目:bob    作者:BobBuildTool    | 项目源码 | 文件源码
def evalForward(self, nodes, valid):
        """Evaluate the axis, name test and predicate

        Despite the result set returns whether we possibly made multiple hops
        in the dendency graph, i.e.  evaluated a 'descendant' axis. In this
        caste it is the responsibility of the caller to calculate all possible
        paths that lead to the result set.
        """
        search = None
        if self.__axis == "child":
            nodes = self.__evalAxisChild(nodes, True)
        elif self.__axis == "descendant":
            nodes = self.__evalAxisDescendant(nodes, True)
            search = True
        elif self.__axis == "descendant-or-self":
            nodes = self.__evalAxisDescendant(nodes, True) | nodes
            search = True
        elif self.__axis == "direct-child":
            nodes = self.__evalAxisChild(nodes, False)
        elif self.__axis == "direct-descendant":
            nodes = self.__evalAxisDescendant(nodes, False)
            search = False
        elif self.__axis == "direct-descendant-or-self":
            nodes = self.__evalAxisDescendant(nodes, False) | nodes
            search = False
        elif self.__axis == "self":
            pass
        else:
            assert False, "Invalid axis: " + self.__axis

        if self.__test == "*":
            pass
        elif '*' in self.__test:
            nodes = set(i for i in nodes if fnmatchcase(i.getName(), self.__test))
        else:
            nodes = set(i for i in nodes if i.getName() == self.__test)

        if self.__pred:
            nodes = nodes & self.__pred.evalBackward()

        return (nodes, search)
项目:bob    作者:BobBuildTool    | 项目源码 | 文件源码
def evalBackward(self, nodes):
        """Inverse evaluation of location path step."""
        if self.__test == "*":
            pass
        elif '*' in self.__test:
            nodes = set(i for i in nodes if fnmatchcase(i.getName(), self.__test))
        else:
            nodes = set(i for i in nodes if i.getName() == self.__test)

        if self.__pred:
            nodes = nodes & self.__pred.evalBackward()

        if self.__axis == "child":
            nodes = self.__evalAxisParent(nodes, True)
        elif self.__axis == "descendant":
            nodes = self.__evalAxisAncestor(nodes, True)
        elif self.__axis == "descendant-or-self":
            nodes = self.__evalAxisAncestor(nodes, True) | nodes
        elif self.__axis == "direct-child":
            nodes = self.__evalAxisParent(nodes, False)
        elif self.__axis == "direct-descendant":
            nodes = self.__evalAxisAncestor(nodes, False)
        elif self.__axis == "direct-descendant-or-self":
            nodes = self.__evalAxisAncestor(nodes, False) | nodes
        elif self.__axis == "self":
            pass
        else:
            assert False, "Invalid axis: " + self.__axis

        return nodes
项目:bob    作者:BobBuildTool    | 项目源码 | 文件源码
def __doesMatch(self, scm):
        for (key, value) in self.__match.items():
            if key not in scm: return False
            if not fnmatch.fnmatchcase(scm[key], value): return False
        return True
项目:bob    作者:BobBuildTool    | 项目源码 | 文件源码
def __maybeGlob(pred):
    if pred.startswith("!"):
        pred = pred[1:]
        if any(i in pred for i in '*?[]'):
            return lambda prev, elem: False if fnmatch.fnmatchcase(elem, pred) else prev
        else:
            return lambda prev, elem: False if elem == pred else prev
    else:
        if any(i in pred for i in '*?[]'):
            return lambda prev, elem: True if fnmatch.fnmatchcase(elem, pred) else prev
        else:
            return lambda prev, elem: True if elem == pred else prev
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def find_packages(where='.', exclude=()):
    """Return a list all Python packages found within directory 'where'

    'where' should be supplied as a "cross-platform" (i.e. URL-style) path; it
    will be converted to the appropriate local path syntax.  'exclude' is a
    sequence of package names to exclude; '*' can be used as a wildcard in the
    names, such that 'foo.*' will exclude all subpackages of 'foo' (but not
    'foo' itself).
    """
    out = []
    stack=[(convert_path(where), '')]
    while stack:
        where,prefix = stack.pop(0)
        for name in os.listdir(where):
            fn = os.path.join(where,name)
            looks_like_package = (
                '.' not in name
                and os.path.isdir(fn)
                and os.path.isfile(os.path.join(fn, '__init__.py'))
            )
            if looks_like_package:
                out.append(prefix+name)
                stack.append((fn, prefix+name+'.'))
    for pat in list(exclude)+['ez_setup']:
        from fnmatch import fnmatchcase
        out = [item for item in out if not fnmatchcase(item,pat)]
    return out
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def _build_filter(*patterns):
        """
        Given a list of patterns, return a callable that will be true only if
        the input matches at least one of the patterns.
        """
        return lambda name: any(fnmatchcase(name, pat=pat) for pat in patterns)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def wildcard_match(self, wildcard):
        if hasattr(self, 'nkd_fnmatchcase'):
            fnmatchcase = self.nkd_fnmatchcase
        else:
            from fnmatch import fnmatchcase
            self.nkd_fnmatchcase = fnmatchcase
        return [ x for x in self if fnmatchcase(x, wildcard) ]

    #------------------------------------------------------------------------------
    # [ multi_wildcard_match method ] (list)
    #  returns a list of items that match one or more | separated wildcards passed as string
    #------------------------------------------------------------------------------
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def wildcard_match(self, wildcard):
        from fnmatch import fnmatchcase
        return fnmatchcase(self, wildcard)

    # convert string to normalized UTF-8 in Python 2 and 3 (##TODO: convert to XUnicode with attributes?)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def _build_filter(*patterns):
        """
        Given a list of patterns, return a callable that will be true only if
        the input matches one of the patterns.
        """
        return lambda name: any(fnmatchcase(name, pat=pat) for pat in patterns)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def wildcard_match(self, wildcard):
        if hasattr(self, 'nkd_fnmatchcase'):
            fnmatchcase = self.nkd_fnmatchcase
        else:
            from fnmatch import fnmatchcase
            self.nkd_fnmatchcase = fnmatchcase
        return [ x for x in self if fnmatchcase(x, wildcard) ]

    #------------------------------------------------------------------------------
    # [ multi_wildcard_match method ] (list)
    #  returns a list of items that match one or more | separated wildcards passed as string
    #------------------------------------------------------------------------------
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def wildcard_match(self, wildcard):
        from fnmatch import fnmatchcase
        return fnmatchcase(self, wildcard)

    # convert string to normalized UTF-8 in Python 2 and 3 (##TODO: convert to XUnicode with attributes?)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def _build_filter(*patterns):
        """
        Given a list of patterns, return a callable that will be true only if
        the input matches one of the patterns.
        """
        return lambda name: any(fnmatchcase(name, pat=pat) for pat in patterns)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def _build_filter(*patterns):
        """
        Given a list of patterns, return a callable that will be true only if
        the input matches one of the patterns.
        """
        return lambda name: any(fnmatchcase(name, pat=pat) for pat in patterns)
项目:usefulaaltomap    作者:usefulaaltomap    | 项目源码 | 文件源码
def update_matching(dct, key_pattern, new_dct):
    for key in dct:
        if fnmatch.fnmatchcase(key, key_pattern):
            new_dct[key] = dct[key]
项目:jira_worklog_scanner    作者:pgarneau    | 项目源码 | 文件源码
def _build_filter(*patterns):
        """
        Given a list of patterns, return a callable that will be true only if
        the input matches at least one of the patterns.
        """
        return lambda name: any(fnmatchcase(name, pat=pat) for pat in patterns)
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def matches_patterns(path, patterns=None):
    """
    Return True or False depending on whether the ``path`` should be
    ignored (if it matches any pattern in ``ignore_patterns``).
    """
    if patterns is None:
        patterns = []
    for pattern in patterns:
        if fnmatch.fnmatchcase(path, pattern):
            return True
    return False
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def _build_filter(*patterns):
        """
        Given a list of patterns, return a callable that will be true only if
        the input matches one of the patterns.
        """
        return lambda name: any(fnmatchcase(name, pat=pat) for pat in patterns)
项目:atoolbox    作者:liweitianux    | 项目源码 | 文件源码
def match(self, props):
        """
        Check whether the given props match all the conditions.
        """
        def match_condition(props, cond):
            """
            Check whether the given props match the given condition.
            """
            try:
                prop, op, ref = props[cond[0]], cond[1], cond[2]
            except KeyError:
                return False
            if op == "~":
                return fnmatch.fnmatchcase(prop.lower(), ref.lower())
            elif op == "=":
                return prop == ref
            elif op == ">":
                return prop > ref
            elif op == "<":
                return prop < ref
            else:
                return False
        #
        return functools.reduce(operator.and_,
                                [ match_condition(props, cond) \
                                        for cond in self.conditions ],
                                True)
项目:NarshaTech    作者:KimJangHyeon    | 项目源码 | 文件源码
def matches_patterns(path, patterns=None):
    """
    Return True or False depending on whether the ``path`` should be
    ignored (if it matches any pattern in ``ignore_patterns``).
    """
    if patterns is None:
        patterns = []
    for pattern in patterns:
        if fnmatch.fnmatchcase(path, pattern):
            return True
    return False
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def find_package_modules(package, mask):
    import fnmatch
    if (hasattr(package, "__loader__") and
            hasattr(package.__loader__, '_files')):
        path = package.__name__.replace(".", os.path.sep)
        mask = os.path.join(path, mask)
        for fnm in package.__loader__._files.iterkeys():
            if fnmatch.fnmatchcase(fnm, mask):
                yield os.path.splitext(fnm)[0].replace(os.path.sep, ".")
    else:
        path = package.__path__[0]
        for fnm in os.listdir(path):
            if fnmatch.fnmatchcase(fnm, mask):
                yield "%s.%s" % (package.__name__, os.path.splitext(fnm)[0])
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def _build_filter(*patterns):
        """
        Given a list of patterns, return a callable that will be true only if
        the input matches at least one of the patterns.
        """
        return lambda name: any(fnmatchcase(name, pat=pat) for pat in patterns)
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def _build_filter(*patterns):
        """
        Given a list of patterns, return a callable that will be true only if
        the input matches at least one of the patterns.
        """
        return lambda name: any(fnmatchcase(name, pat=pat) for pat in patterns)
项目:hgvm-builder    作者:BD2KGenomics    | 项目源码 | 文件源码
def copy_everything(job, options):
    """
    Download the file list and copy all the files.

    """

    # Set up the IO stores.
    in_store = IOStore.get(options.in_store)
    out_store = IOStore.get(options.out_store)

    batch_count = 0;

    # List all the files.
    blobs_iterator = in_store.list_input_directory("", recursive=True)

    # Make an iterator that filters them
    filtered_iterator = (x for x in blobs_iterator if
        fnmatch.fnmatchcase(x, options.pattern))

    # Batch them up
    for batch in group(filtered_iterator, options.batch_size):

        # For every batch, strip out any Nones that got put in when grouping
        batch = [x for x in batch if x is not None]

        # Copy everything in that batch
        job.addChildJobFn(copy_batch, options, batch, cores=1, memory="1G",
            disk="10G")

        batch_count += 1

        if batch_count % 10 == 0:

            RealtimeLogger.info("Queued {} batches...".format(
                batch_count))

    RealtimeLogger.info("Queued {} total batches".format(batch_count))
项目:ascii-art-py    作者:blinglnav    | 项目源码 | 文件源码
def _build_filter(*patterns):
        """
        Given a list of patterns, return a callable that will be true only if
        the input matches at least one of the patterns.
        """
        return lambda name: any(fnmatchcase(name, pat=pat) for pat in patterns)
项目:Scrum    作者:prakharchoudhary    | 项目源码 | 文件源码
def matches_patterns(path, patterns=None):
    """
    Return True or False depending on whether the ``path`` should be
    ignored (if it matches any pattern in ``ignore_patterns``).
    """
    if patterns is None:
        patterns = []
    for pattern in patterns:
        if fnmatch.fnmatchcase(path, pattern):
            return True
    return False
项目:deb-oslo.utils    作者:openstack    | 项目源码 | 文件源码
def fnmatchcase(filename, pattern):
        cached_pattern = _get_cached_pattern(pattern)
        return cached_pattern.match(filename) is not None
项目:deb-oslo.utils    作者:openstack    | 项目源码 | 文件源码
def fnmatch(filename, pattern):
        filename = os.path.normcase(filename)
        pattern = os.path.normcase(pattern)
        return fnmatchcase(filename, pattern)
项目:ivaochdoc    作者:ivaoch    | 项目源码 | 文件源码
def _build_filter(*patterns):
        """
        Given a list of patterns, return a callable that will be true only if
        the input matches at least one of the patterns.
        """
        return lambda name: any(fnmatchcase(name, pat=pat) for pat in patterns)