Python fnmatch.fnmatchcase() Examples
The following are 30
code examples of fnmatch.fnmatchcase().
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
fnmatch
, or try the search function
.
Example #1
Source File: linedef.py From TheVGLC with MIT License | 6 votes |
def find_std(desc): """Search the standard (non-generalized) triggers. A list of matches is returned. All terms must match. Wildcards are allowed. Example: find_std("CEIL UP S?") should return: ['CEIL S1 UP SLOW HNC', 'CEIL SR UP SLOW HNC']""" terms = desc.split() matches = [] for dsc in num2desc.values(): d = dsc.split() matchedterms = 0 for term in terms: for key in d: if fnmatchcase(key, term): matchedterms += 1 if matchedterms == len(terms): matches.append(dsc) return matches
Example #2
Source File: _util.py From bugatsinho.github.io with GNU General Public License v3.0 | 6 votes |
def dict_match(d, key, default=None): """Like __getitem__ but works as if the keys() are all filename patterns. Returns the value of any dict key that matches the passed key. Args: d (dict): A dict with filename patterns as keys key (str): A key potentially matching any of the keys default (object): The object to return if no pattern matched the passed in key Returns: object: The dict value where the dict key matched the passed in key. Or default if there was no match. """ if key in d and "[" not in key: return d[key] else: for pattern, value in iteritems(d): if fnmatchcase(key, pattern): return value return default
Example #3
Source File: mods.py From fac with MIT License | 6 votes |
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
Example #4
Source File: bfu_Utils.py From Blender-For-UnrealEngine-Addons with GNU General Public License v3.0 | 6 votes |
def UpdateNameHierarchy(list = None): #Updates hierarchy names if list is not None: objs = list else: objs = GetAllCollisionAndSocketsObj() for obj in objs: if fnmatch.fnmatchcase(obj.name, "UBX*"): UpdateUe4Name("Box", [obj]) if fnmatch.fnmatchcase(obj.name, "UCP*"): UpdateUe4Name("Capsule", [obj]) if fnmatch.fnmatchcase(obj.name, "USP*"): UpdateUe4Name("Sphere", [obj]) if fnmatch.fnmatchcase(obj.name, "UCX*"): UpdateUe4Name("Convex", [obj]) if fnmatch.fnmatchcase(obj.name, "SOCKET*"): UpdateUe4Name("Socket", [obj])
Example #5
Source File: bfu_Utils.py From Blender-For-UnrealEngine-Addons with GNU General Public License v3.0 | 6 votes |
def SelectParentAndDesiredChilds(obj): #Selects only all child objects that must be exported with parent object selectedObjs = [] bpy.ops.object.select_all(action='DESELECT') for selectObj in GetExportDesiredChilds(obj): if selectObj.name in bpy.context.view_layer.objects: if GetAssetType(obj) == "SkeletalMesh": #With skeletal mesh the socket must be not exported, ue4 read it like a bone if not fnmatch.fnmatchcase(selectObj.name, "SOCKET*"): selectObj.select_set(True) selectedObjs.append(selectObj) else: selectObj.select_set(True) selectedObjs.append(selectObj) obj.select_set(True) if obj.ExportAsProxy == True: if obj.ExportProxyChild is not None: obj.ExportProxyChild.select_set(True) selectedObjs.append(obj) bpy.context.view_layer.objects.active = obj return selectedObjs
Example #6
Source File: Database.py From WebPocket with GNU General Public License v3.0 | 6 votes |
def db_rebuild(self): self.delete_table() self.create_table() for directory_name, directories, filenames in os.walk('modules/'): for filename in filenames: if filename not in ['__init__.py']\ and not fnmatchcase(filename, "*.pyc")\ and fnmatchcase(filename, "*.py"): full_name = "{directory}/{filename}".format(directory=directory_name, filename=filename) module_name = name_convert(full_name) module_class = import_module("modules.{module_name}".format( module_name=module_name.replace("/", ".") )) module_instance = module_class.Exploit() module_info = module_instance.get_info() module_info['module_name'] = module_name try: getattr(module_instance, 'check') module_info['check'] = 'True' except AttributeError: module_info['check'] = 'False' self.insert_module(module_info)
Example #7
Source File: hook_utils.py From eclcli with Apache License 2.0 | 6 votes |
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)
Example #8
Source File: pathlib.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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
Example #9
Source File: __main__.py From CDTB with GNU Lesser General Public License v3.0 | 6 votes |
def command_wad_extract(parser, args): if not os.path.isfile(args.wad): parser.error("WAD file does not exist") if not args.output: args.output = os.path.splitext(args.wad)[0] if os.path.exists(args.output) and not os.path.isdir(args.output): parser.error("output is not a directory") if args.hashes is None: hashfile = default_hashfile(args.wad) else: hashfile = HashFile(args.hashes) wad = Wad(args.wad, hashes=hashfile.load()) if args.unknown == 'yes': pass # don't filter elif args.unknown == 'only': wad.files = [wf for wf in wad.files if wf.path is None] elif args.unknown == 'no': wad.files = [wf for wf in wad.files if wf.path is not None] if args.pattern: wad.files = [wf for wf in wad.files if any(wf.path is not None and fnmatch.fnmatchcase(wf.path, p) for p in args.pattern)] wad.guess_extensions() wad.extract(args.output, overwrite=not args.lazy)
Example #10
Source File: urlmatch.py From qutebrowser with GNU General Public License v3.0 | 6 votes |
def _matches_path(self, path: str) -> bool: """Match the URL's path. Deviations from Chromium: - Chromium only matches <all_urls> with "javascript:" (pathless); but we also match *://*/* and friends. """ if self._path is None: return True # Match 'google.com' with 'google.com/' if path + '/*' == self._path: return True # FIXME Chromium seems to have a more optimized glob matching which # doesn't rely on regexes. Do we need that too? return fnmatch.fnmatchcase(path, self._path)
Example #11
Source File: expander_minimizer.py From policyuniverse with Apache License 2.0 | 6 votes |
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()]
Example #12
Source File: ttree_lex.py From moltemplate with MIT License | 6 votes |
def MatchesPattern(s, pattern): if type(pattern) is str: # old code: # if ((len(s) > 1) and (s[0] == '/') and (s[-1] == '/'): # re_string = p[1:-1] # strip off the slashes '/' and '/' # if not re.search(re_string, s): # return False # new code: # uses precompiled regular expressions (See "pattern.search" below) if HasWildcard(pattern): if not fnmatch.fnmatchcase(s, pattern): return False elif s != pattern: return False else: #assert(type(p) is _sre.SRE_Match) # I assume pattern = re.compile(some_reg_expr) if not pattern.search(s): return False return True
Example #13
Source File: endpoints.py From afkak with Apache License 2.0 | 5 votes |
def accept(self, host_pattern): """ Accept a pending connection request. :param str host_pattern: :func:`fnmatch.fnmatchcase` pattern against which the connection request must match. :returns: `KafkaConnection` """ host, port, protocolFactory, d = self._match(host_pattern) peerAddress = _DebugAddress(host, port) client_protocol = protocolFactory.buildProtocol(peerAddress) assert client_protocol is not None server_protocol = KafkaBrokerProtocol() client_transport = iosim.FakeTransport(client_protocol, isServer=False, peerAddress=peerAddress) server_transport = iosim.FakeTransport(server_protocol, isServer=True) pump = iosim.connect(server_protocol, server_transport, client_protocol, client_transport) self._pumps.append(pump) d.callback(client_protocol) return KafkaConnection( server=server_protocol, client=client_protocol, pump=pump, )
Example #14
Source File: github_auth.py From datasette-auth-github with Apache License 2.0 | 5 votes |
def do_not_redirect(self, scope): return any( fnmatch.fnmatchcase(scope["path"], pat) for pat in self.redirect_path_blacklist )
Example #15
Source File: test_langserver.py From python-langserver with MIT License | 5 votes |
def test_hover_stdlib(): h = hover('/b.py', 5, 23) assert h == { 'contents': [{ 'language': 'python', 'value': 'def fnmatchcase(param name, param pat)' }, "Test whether FILENAME matches PATTERN, including case.\n" "\nThis is a version of fnmatch() which doesn't case-normalize\n" "its arguments." ] }
Example #16
Source File: __init__.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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)
Example #17
Source File: systemctl3.py From vanilla-docker with MIT License | 5 votes |
def get_preset(self, unit): for line in self._lines: m = re.match(r"(enable|disable)\s+(\S+)", line) if m: status, pattern = m.group(1), m.group(2) if fnmatch.fnmatchcase(unit, pattern): logg.debug("%s %s => %s [%s]", status, pattern, unit, self.filename()) return status return None ## with waitlock(conf): self.start()
Example #18
Source File: __init__.py From pex with Apache License 2.0 | 5 votes |
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)
Example #19
Source File: __init__.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
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)
Example #20
Source File: __init__.py From anpr with Creative Commons Attribution 4.0 International | 5 votes |
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)
Example #21
Source File: __init__.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
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)
Example #22
Source File: utils.py From bioforum with MIT License | 5 votes |
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
Example #23
Source File: endpoints.py From afkak with Apache License 2.0 | 5 votes |
def fail(self, host_pattern, reason): """ Fail a pending connection request. :param str host_pattern: :func:`fnmatch.fnmatchcase` pattern against which the connection request must match. :param reason: `twisted.python.failure.Failure` """ host, port, protocolFactory, d = self._match(host_pattern) d.errback(reason)
Example #24
Source File: object.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def execute(self, context): import fnmatch if self.case_sensitive: pattern_match = fnmatch.fnmatchcase else: pattern_match = (lambda a, b: fnmatch.fnmatchcase(a.upper(), b.upper())) is_ebone = False obj = context.object if obj and obj.mode == 'POSE': items = obj.data.bones if not self.extend: bpy.ops.pose.select_all(action='DESELECT') elif obj and obj.type == 'ARMATURE' and obj.mode == 'EDIT': items = obj.data.edit_bones if not self.extend: bpy.ops.armature.select_all(action='DESELECT') is_ebone = True else: items = context.visible_objects if not self.extend: bpy.ops.object.select_all(action='DESELECT') # Can be pose bones or objects for item in items: if pattern_match(item.name, self.pattern): item.select = True # hrmf, perhaps there should be a utility function for this. if is_ebone: item.select_head = True item.select_tail = True if item.use_connect: item_parent = item.parent if item_parent is not None: item_parent.select_tail = True return {'FINISHED'}
Example #25
Source File: endpoints.py From afkak with Apache License 2.0 | 5 votes |
def _match(self, host_pattern): for index in range(len(self.connects)): host = self.connects[index][0] if fnmatchcase(host, host_pattern): break else: raise AssertionError('No match for host pattern {!r}. Searched: {}'.format( host_pattern, pformat(self.connects))) return self.connects.pop(index)
Example #26
Source File: test_fnmatch.py From oss-ftp with MIT License | 5 votes |
def test_fnmatchcase(self): check = self.check_match check('AbC', 'abc', 0, fnmatchcase) check('abc', 'AbC', 0, fnmatchcase)
Example #27
Source File: __init__.py From oss-ftp with MIT License | 5 votes |
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)
Example #28
Source File: __init__.py From oss-ftp with MIT License | 5 votes |
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])
Example #29
Source File: test_fnmatch.py From BinderFilter with MIT License | 5 votes |
def test_fnmatchcase(self): check = self.check_match check('AbC', 'abc', 0, fnmatchcase) check('abc', 'AbC', 0, fnmatchcase)
Example #30
Source File: __init__.py From BinderFilter with MIT License | 5 votes |
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])