mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 02:26:53 -07:00
Update vendored windows libs
This commit is contained in:
parent
f61c211655
commit
b1cefa94e5
226 changed files with 33472 additions and 11882 deletions
59
libs/win/path/matchers.py
Normal file
59
libs/win/path/matchers.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
import ntpath
|
||||
import fnmatch
|
||||
|
||||
|
||||
def load(param):
|
||||
"""
|
||||
If the supplied parameter is a string, assume it's a simple
|
||||
pattern.
|
||||
"""
|
||||
return (
|
||||
Pattern(param)
|
||||
if isinstance(param, str)
|
||||
else param
|
||||
if param is not None
|
||||
else Null()
|
||||
)
|
||||
|
||||
|
||||
class Base:
|
||||
pass
|
||||
|
||||
|
||||
class Null(Base):
|
||||
def __call__(self, path):
|
||||
return True
|
||||
|
||||
|
||||
class Pattern(Base):
|
||||
def __init__(self, pattern):
|
||||
self.pattern = pattern
|
||||
|
||||
def get_pattern(self, normcase):
|
||||
try:
|
||||
return self._pattern
|
||||
except AttributeError:
|
||||
pass
|
||||
self._pattern = normcase(self.pattern)
|
||||
return self._pattern
|
||||
|
||||
def __call__(self, path):
|
||||
normcase = getattr(self, 'normcase', path.module.normcase)
|
||||
pattern = self.get_pattern(normcase)
|
||||
return fnmatch.fnmatchcase(normcase(path.name), pattern)
|
||||
|
||||
|
||||
class CaseInsensitive(Pattern):
|
||||
"""
|
||||
A Pattern with a ``'normcase'`` property, suitable for passing to
|
||||
:meth:`listdir`, :meth:`dirs`, :meth:`files`, :meth:`walk`,
|
||||
:meth:`walkdirs`, or :meth:`walkfiles` to match case-insensitive.
|
||||
|
||||
For example, to get all files ending in .py, .Py, .pY, or .PY in the
|
||||
current directory::
|
||||
|
||||
from path import Path, matchers
|
||||
Path('.').files(matchers.CaseInsensitive('*.py'))
|
||||
"""
|
||||
|
||||
normcase = staticmethod(ntpath.normcase)
|
Loading…
Add table
Add a link
Reference in a new issue