コード例 #1
0
ファイル: filters.py プロジェクト: fermat618/pida
 def validate(self):
     pattern = self.entry.get_text()
     pattern = fnmatch.translate(pattern).rstrip('$')
     try:
         self.regex = re.compile(pattern, re.IGNORECASE)
     except sre_constants.error, e:
         raise ValidationError(_('Invalid Regex'))
コード例 #2
0
ファイル: filters.py プロジェクト: xmonader/pida
 def validate(self):
     pattern = self.entry.get_text()
     pattern = fnmatch.translate(pattern).rstrip('$')
     try:
         self.regex = re.compile(pattern, re.IGNORECASE)
     except sre_constants.error, e:
         raise ValidationError(_('Invalid Regex'))
コード例 #3
0
ファイル: fs.py プロジェクト: xXxrAinZyian/xrootdpyfs
    def _ilistdir_helper(self,
                         path,
                         entries,
                         wildcard=None,
                         full=False,
                         absolute=False,
                         dirs_only=False,
                         files_only=False):
        """A helper method called by ilistdir method that applies filtering.

        Given the path to a directory and a list of the names of entries within
        that directory, this method applies the semantics of the ilistdir()
        keyword arguments. An appropriately modified and filtered list of
        directory entries is returned.
        """
        path = normpath(path)

        if dirs_only and files_only:
            raise ValueError("dirs_only and files_only cannot both be True")

        if wildcard is not None:
            if not callable(wildcard):
                wildcard_re = re.compile(fnmatch.translate(wildcard))

                def wildcard(fn):
                    return bool(wildcard_re.match(fn))

            entries = (p for p in entries if wildcard(p.name))

        if dirs_only:
            entries = (p for p in entries
                       if self.isdir(p.name, _statobj=p.statinfo))
        elif files_only:
            entries = (p for p in entries
                       if self.isfile(p.name, _statobj=p.statinfo))

        if full:
            entries = (pathcombine(path, p.name) for p in entries)
        elif absolute:
            path = self._p(path)
            entries = ((pathcombine(path, p.name)) for p in entries)
        else:
            entries = (p.name for p in entries)

        return entries
コード例 #4
0
ファイル: fs.py プロジェクト: otron/xrootdfs
    def _ilistdir_helper(self, path, entries, wildcard=None, full=False,
                         absolute=False, dirs_only=False, files_only=False):
        """A helper method called by ilistdir method that applies filtering.

        Given the path to a directory and a list of the names of entries within
        that directory, this method applies the semantics of the ilistdir()
        keyword arguments. An appropriately modified and filtered list of
        directory entries is returned.
        """
        path = normpath(path)

        if dirs_only and files_only:
            raise ValueError("dirs_only and files_only cannot both be True")

        if wildcard is not None:
            if not callable(wildcard):
                wildcard_re = re.compile(fnmatch.translate(wildcard))

                def wildcard(fn):
                    return bool(wildcard_re.match(fn))

            entries = (p for p in entries if wildcard(p.name))

        if dirs_only:
            entries = (
                p for p in entries if self.isdir(p.name, _statobj=p.statinfo)
            )
        elif files_only:
            entries = (
                p for p in entries if self.isfile(p.name, _statobj=p.statinfo)
            )

        if full:
            entries = (pathcombine(path, p.name) for p in entries)
        elif absolute:
            path = self._p(path)
            entries = ((pathcombine(path, p.name)) for p in entries)
        else:
            entries = (p.name for p in entries)

        return entries
コード例 #5
0
ファイル: fileutil.py プロジェクト: mic159/par2ools
signatures = {
    'par2': 'PAR2\x00',
    'zip': 'PK\x03\x04',  # empty is \x05\x06, multi-vol is \x07\x08
    'rar': 'Rar!\x1A\x07\x00',
    '7zip': '7z\xbc\xaf\x27\x1c',
    'bzip2': 'BZh',
    'gzip': '\x1f\x8b\x08',
}

lscolors = filter(None, os.environ.get('LS_COLORS', '').split(':'))
dircolormap = dict([x.split('=') for x in lscolors])
colorremap = {}
for k, v in dircolormap.iteritems():
    if '*' not in k: continue
    colorremap.setdefault(v, []).append(fnmatch.translate(k))
for k, v in colorremap.items():
    colorremap[k] = re.compile('(%s)' % '|'.join(v))


def baseglob(pat, base):
    """Given a pattern and a base, return files that match the glob pattern
    and also contain the base."""
    return [f for f in glob(pat) if f.startswith(base)]


def cibaseglob(pat, base):
    """Case insensitive baseglob.  Note that it's not *actually* case
    insensitive, since glob is insensitive or not based on local semantics.
    Instead, it tries the original version, an upper() version, a lower()
    version, and a swapcase() version of the glob."""
コード例 #6
0
 def _translate_glob(self, glob):
     # ensure we dont just match the end of the string
     return fnmatch.translate(glob).rstrip('$').replace(r'\Z', '')
コード例 #7
0
ファイル: grepper.py プロジェクト: fermat618/pida
 def _translate_glob(self, glob):
     # ensure we dont just match the end of the string
     return fnmatch.translate(glob).rstrip('$').replace(r'\Z', '')
コード例 #8
0
ファイル: fileutil.py プロジェクト: jmoiron/par2ools
signatures = {
    'par2': 'PAR2\x00',
    'zip': 'PK\x03\x04', # empty is \x05\x06, multi-vol is \x07\x08
    'rar': 'Rar!\x1A\x07\x00',
    '7zip': '7z\xbc\xaf\x27\x1c',
    'bzip2': 'BZh',
    'gzip': '\x1f\x8b\x08',
}

lscolors = filter(None, os.environ.get('LS_COLORS', '').split(':'))
dircolormap = dict([x.split('=') for x in lscolors])
colorremap = {}
for k,v in dircolormap.iteritems():
    if '*' not in k: continue
    colorremap.setdefault(v, []).append(fnmatch.translate(k))
for k,v in colorremap.items():
    colorremap[k] = re.compile('(%s)' % '|'.join(v))

def baseglob(pat, base):
    """Given a pattern and a base, return files that match the glob pattern
    and also contain the base."""
    return [f for f in glob(pat) if f.startswith(base)]

def cibaseglob(pat, base):
    """Case insensitive baseglob.  Note that it's not *actually* case
    insensitive, since glob is insensitive or not based on local semantics.
    Instead, it tries the original version, an upper() version, a lower()
    version, and a swapcase() version of the glob."""
    results = []
    for func in (str, str.upper, str.lower, str.swapcase):