Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/python2....
File: glob.py
"""Filename globbing utility."""
[0] Fix | Delete
[1] Fix | Delete
import sys
[2] Fix | Delete
import os
[3] Fix | Delete
import re
[4] Fix | Delete
import fnmatch
[5] Fix | Delete
[6] Fix | Delete
try:
[7] Fix | Delete
_unicode = unicode
[8] Fix | Delete
except NameError:
[9] Fix | Delete
# If Python is built without Unicode support, the unicode type
[10] Fix | Delete
# will not exist. Fake one.
[11] Fix | Delete
class _unicode(object):
[12] Fix | Delete
pass
[13] Fix | Delete
[14] Fix | Delete
__all__ = ["glob", "iglob"]
[15] Fix | Delete
[16] Fix | Delete
def glob(pathname):
[17] Fix | Delete
"""Return a list of paths matching a pathname pattern.
[18] Fix | Delete
[19] Fix | Delete
The pattern may contain simple shell-style wildcards a la
[20] Fix | Delete
fnmatch. However, unlike fnmatch, filenames starting with a
[21] Fix | Delete
dot are special cases that are not matched by '*' and '?'
[22] Fix | Delete
patterns.
[23] Fix | Delete
[24] Fix | Delete
"""
[25] Fix | Delete
return list(iglob(pathname))
[26] Fix | Delete
[27] Fix | Delete
def iglob(pathname):
[28] Fix | Delete
"""Return an iterator which yields the paths matching a pathname pattern.
[29] Fix | Delete
[30] Fix | Delete
The pattern may contain simple shell-style wildcards a la
[31] Fix | Delete
fnmatch. However, unlike fnmatch, filenames starting with a
[32] Fix | Delete
dot are special cases that are not matched by '*' and '?'
[33] Fix | Delete
patterns.
[34] Fix | Delete
[35] Fix | Delete
"""
[36] Fix | Delete
dirname, basename = os.path.split(pathname)
[37] Fix | Delete
if not has_magic(pathname):
[38] Fix | Delete
if basename:
[39] Fix | Delete
if os.path.lexists(pathname):
[40] Fix | Delete
yield pathname
[41] Fix | Delete
else:
[42] Fix | Delete
# Patterns ending with a slash should match only directories
[43] Fix | Delete
if os.path.isdir(dirname):
[44] Fix | Delete
yield pathname
[45] Fix | Delete
return
[46] Fix | Delete
if not dirname:
[47] Fix | Delete
for name in glob1(os.curdir, basename):
[48] Fix | Delete
yield name
[49] Fix | Delete
return
[50] Fix | Delete
# `os.path.split()` returns the argument itself as a dirname if it is a
[51] Fix | Delete
# drive or UNC path. Prevent an infinite recursion if a drive or UNC path
[52] Fix | Delete
# contains magic characters (i.e. r'\\?\C:').
[53] Fix | Delete
if dirname != pathname and has_magic(dirname):
[54] Fix | Delete
dirs = iglob(dirname)
[55] Fix | Delete
else:
[56] Fix | Delete
dirs = [dirname]
[57] Fix | Delete
if has_magic(basename):
[58] Fix | Delete
glob_in_dir = glob1
[59] Fix | Delete
else:
[60] Fix | Delete
glob_in_dir = glob0
[61] Fix | Delete
for dirname in dirs:
[62] Fix | Delete
for name in glob_in_dir(dirname, basename):
[63] Fix | Delete
yield os.path.join(dirname, name)
[64] Fix | Delete
[65] Fix | Delete
# These 2 helper functions non-recursively glob inside a literal directory.
[66] Fix | Delete
# They return a list of basenames. `glob1` accepts a pattern while `glob0`
[67] Fix | Delete
# takes a literal basename (so it only has to check for its existence).
[68] Fix | Delete
[69] Fix | Delete
def glob1(dirname, pattern):
[70] Fix | Delete
if not dirname:
[71] Fix | Delete
dirname = os.curdir
[72] Fix | Delete
if isinstance(pattern, _unicode) and not isinstance(dirname, unicode):
[73] Fix | Delete
dirname = unicode(dirname, sys.getfilesystemencoding() or
[74] Fix | Delete
sys.getdefaultencoding())
[75] Fix | Delete
try:
[76] Fix | Delete
names = os.listdir(dirname)
[77] Fix | Delete
except os.error:
[78] Fix | Delete
return []
[79] Fix | Delete
if pattern[0] != '.':
[80] Fix | Delete
names = filter(lambda x: x[0] != '.', names)
[81] Fix | Delete
return fnmatch.filter(names, pattern)
[82] Fix | Delete
[83] Fix | Delete
def glob0(dirname, basename):
[84] Fix | Delete
if basename == '':
[85] Fix | Delete
# `os.path.split()` returns an empty basename for paths ending with a
[86] Fix | Delete
# directory separator. 'q*x/' should match only directories.
[87] Fix | Delete
if os.path.isdir(dirname):
[88] Fix | Delete
return [basename]
[89] Fix | Delete
else:
[90] Fix | Delete
if os.path.lexists(os.path.join(dirname, basename)):
[91] Fix | Delete
return [basename]
[92] Fix | Delete
return []
[93] Fix | Delete
[94] Fix | Delete
[95] Fix | Delete
magic_check = re.compile('[*?[]')
[96] Fix | Delete
[97] Fix | Delete
def has_magic(s):
[98] Fix | Delete
return magic_check.search(s) is not None
[99] Fix | Delete
[100] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function