本文整理汇总了Python中glob.escape方法的典型用法代码示例。如果您正苦于以下问题:Python glob.escape方法的具体用法?Python glob.escape怎么用?Python glob.escape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类glob
的用法示例。
在下文中一共展示了glob.escape方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _load
# 需要导入模块: import glob [as 别名]
# 或者: from glob import escape [as 别名]
def _load(self):
"""Load text to memory"""
corpus_directory = glob.escape(self.corpus_directory)
file_list = sorted(glob.glob(os.path.join(corpus_directory, "*.txt")))
for path in file_list:
with open(path, "r", encoding="utf8") as text:
# Read content from text file
content = text.read()
# Preprocessing
content = self._preprocessing(content)
# Create text instance
text = Text(path, os.path.basename(path), content)
# Add text to corpus
self.__corpus.append(text)
示例2: percentparse
# 需要导入模块: import glob [as 别名]
# 或者: from glob import escape [as 别名]
def percentparse(s: str, format: str, table: Dict[str, str]) -> Optional[Dict[str, str]]:
table = {key: '(?P<{}>{})'.format(key, value) for key, value in table.items()}
used = set() # type: Set[str]
pattern = ''
for token in percentsplit(re.escape(format).replace('\\%', '%')):
if token.startswith('%'):
c = token[1]
if c not in used:
pattern += table[c]
used.add(c)
else:
pattern += r'(?P={})'.format(c)
else:
pattern += token
m = re.match(pattern, s)
if not m:
return None
return m.groupdict()
示例3: check_escape
# 需要导入模块: import glob [as 别名]
# 或者: from glob import escape [as 别名]
def check_escape(self, arg, expected):
self.assertEqual(glob.escape(arg), expected)
self.assertEqual(glob.escape(os.fsencode(arg)), os.fsencode(expected))
示例4: __excludes2string
# 需要导入模块: import glob [as 别名]
# 或者: from glob import escape [as 别名]
def __excludes2string(self):
if 'rclone_excludes' not in self.config:
return ''
return ' '.join(
"--exclude=%s" % (
cmd_quote(glob.escape(value) if value.startswith(os.path.sep) else value) if isinstance(value,
str) else value)
for value in
self.config['rclone_excludes']).replace('=None', '').strip()
示例5: glob_escape
# 需要导入模块: import glob [as 别名]
# 或者: from glob import escape [as 别名]
def glob_escape(pathname):
"""
Escape all special characters.
"""
drive, pathname = os.path.splitdrive(pathname)
pathname = _magic_check.sub(r'[\1]', pathname)
return drive + pathname
示例6: check_dimension
# 需要导入模块: import glob [as 别名]
# 或者: from glob import escape [as 别名]
def check_dimension(self):
if os.path.getsize(self.file_name) > 50 * 1024 * 1023:
os.system('split -b 49M "{0}" "{1}"'.format(self.file_name, self.file_name))
os.remove(self.file_name)
return glob(escape(self.file_name) + '*')
示例7: _preprocessing
# 需要导入模块: import glob [as 别名]
# 或者: from glob import escape [as 别名]
def _preprocessing(self, content):
"""Text preprocessing"""
# Remove new line
content = re.sub(r"(\r\n|\r|\n)+", r"", content)
# Convert one or multiple non-breaking space to space
content = re.sub(r"(\xa0)+", r"\s", content)
# Convert multiple spaces to only one space
content = re.sub(r"\s{2,}", r"\s", content)
# Trim whitespace from starting and ending of text
content = content.strip(string.whitespace)
if self.word_delimiter and self.tag_delimiter:
# Trim word delimiter from starting and ending of text
content = content.strip(self.word_delimiter)
# Convert special characters (word and tag delimiter)
# in text's content to escape character
find = "{0}{0}{1}".format(re.escape(self.word_delimiter),
re.escape(self.tag_delimiter))
replace = "{0}{2}{1}".format(re.escape(self.word_delimiter),
re.escape(self.tag_delimiter),
re.escape(constant.ESCAPE_WORD_DELIMITER))
content = re.sub(find, replace, content)
find = "{0}{0}".format(re.escape(self.tag_delimiter))
replace = "{1}{0}".format(re.escape(self.tag_delimiter),
re.escape(constant.ESCAPE_TAG_DELIMITER))
content = re.sub(find, replace, content)
# Replace distinct quotation mark into standard quotation
content = re.sub(r"\u2018|\u2019", r"\'", content)
content = re.sub(r"\u201c|\u201d", r"\"", content)
return content
示例8: get_token_list
# 需要导入模块: import glob [as 别名]
# 或者: from glob import escape [as 别名]
def get_token_list(self, index):
"""Get list of (word, tag) pair"""
if not self.word_delimiter or not self.tag_delimiter:
return list()
# Get content by index
content = self.__corpus[index].content
# Empty file
if not content:
return list()
# Split each word by word delimiter
token_list = content.split(self.word_delimiter)
for idx, token in enumerate(token_list):
# Empty or Spacebar
if token == "" or token == constant.SPACEBAR:
word = constant.SPACEBAR
tag = constant.PAD_TAG_INDEX
# Word
else:
# Split word and tag by tag delimiter
datum = token.split(self.tag_delimiter)
word = datum[0]
tag = datum[-2]
# Replace escape character to proper character
word = word.replace(constant.ESCAPE_WORD_DELIMITER, self.word_delimiter)
tag = tag.replace(constant.ESCAPE_TAG_DELIMITER, self.tag_delimiter)
# Replace token with word and tag pair
token_list[idx] = (word, tag)
return token_list
示例9: find_data_files
# 需要导入模块: import glob [as 别名]
# 或者: from glob import escape [as 别名]
def find_data_files():
"""Setuptools package_data globbing is stupid, so make this work ourselves."""
data_files = []
for pathname in glob.glob("antismash/**/*", recursive=True):
if pathname.endswith('.pyc'):
continue
if pathname.endswith('.py'):
continue
if '__pycache__' in pathname:
continue
if pathname[:-1].endswith('.hmm.h3'):
continue
if pathname.endswith('bgc_seeds.hmm'):
continue
pathname = glob.escape(pathname)
pathname = pathname[10:]
data_files.append(pathname)
if "HARDCODE_ANTISMASH_GIT_VERSION" in os.environ:
version_file = os.path.join('antismash', 'git_hash')
with open(version_file, 'wt') as handle:
try:
git_version = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'],
universal_newlines=True).strip()
changes = subprocess.check_output(['git', 'status', '--porcelain'],
universal_newlines=True).splitlines()
if len(changes) != 0:
git_version += "(changed)"
handle.write(git_version)
except (OSError, subprocess.CalledProcessError):
pass
data_files.append(version_file)
return data_files
示例10: _make_glob_patterns
# 需要导入模块: import glob [as 别名]
# 或者: from glob import escape [as 别名]
def _make_glob_patterns(path):
formatter = string.Formatter()
tokens = formatter.parse(path)
escaped = "".join(glob.escape(text) + "*" * (name is not None) for text, name, *_ in tokens)
root, ext = os.path.splitext(escaped)
if not ext:
return [escaped, escaped + ".*"]
return [escaped, escaped + ".*", root + ".*" + ext, root + ".*" + ext + ".*"]
示例11: glob_with_format
# 需要导入模块: import glob [as 别名]
# 或者: from glob import escape [as 别名]
def glob_with_format(directory: pathlib.Path, format: str) -> List[pathlib.Path]:
if os.name == 'nt':
format = format.replace('/', '\\')
table = {}
table['s'] = '*'
table['e'] = '*'
pattern = (glob.escape(str(directory) + os.path.sep) + percentformat(glob.escape(format).replace(glob.escape('%'), '%'), table))
paths = list(map(pathlib.Path, glob.glob(pattern)))
for path in paths:
log.debug('testcase globbed: %s', path)
return paths
示例12: match_with_format
# 需要导入模块: import glob [as 别名]
# 或者: from glob import escape [as 别名]
def match_with_format(directory: pathlib.Path, format: str, path: pathlib.Path) -> Optional[Match[str]]:
if os.name == 'nt':
format = format.replace('/', '\\')
table = {}
table['s'] = '(?P<name>.+)'
table['e'] = '(?P<ext>in|out)'
pattern = re.compile(re.escape(str(directory.resolve()) + os.path.sep) + percentformat(re.escape(format).replace(re.escape('%'), '%'), table))
return pattern.match(str(path.resolve()))
示例13: get_proton_installations
# 需要导入模块: import glob [as 别名]
# 或者: from glob import escape [as 别名]
def get_proton_installations(compat_tool_dir):
"""
Return a list of custom Proton installations as a list of SteamApp objects
"""
if not os.path.isdir(compat_tool_dir):
return []
comptool_files = glob.glob(
os.path.join(
glob.escape(compat_tool_dir), "*", "compatibilitytool.vdf"
)
)
comptool_files += glob.glob(
os.path.join(glob.escape(compat_tool_dir), "compatibilitytool.vdf")
)
custom_proton_apps = []
for vdf_path in comptool_files:
with open(vdf_path, "r") as f:
content = f.read()
vdf_data = vdf.loads(content)
internal_name = list(
vdf_data["compatibilitytools"]["compat_tools"].keys())[0]
tool_info = vdf_data["compatibilitytools"]["compat_tools"][
internal_name]
install_path = tool_info["install_path"]
from_oslist = tool_info["from_oslist"]
to_oslist = tool_info["to_oslist"]
if from_oslist != "windows" or to_oslist != "linux":
continue
# Installation path can be relative if the VDF was in
# 'compatibilitytools.d/'
# or '.' if the VDF was in 'compatibilitytools.d/TOOL_NAME'
if install_path == ".":
install_path = os.path.dirname(vdf_path)
else:
install_path = os.path.join(compat_tool_dir, install_path)
custom_proton_apps.append(
SteamApp(name=internal_name, install_path=install_path)
)
return custom_proton_apps
示例14: get_steam_apps
# 需要导入模块: import glob [as 别名]
# 或者: from glob import escape [as 别名]
def get_steam_apps(steam_root, steam_path, steam_lib_paths):
"""
Find all the installed Steam apps and return them as a list of SteamApp
objects
"""
steam_apps = []
for path in steam_lib_paths:
appmanifest_paths = []
is_lowercase = os.path.isdir(os.path.join(path, "steamapps"))
is_mixedcase = os.path.isdir(os.path.join(path, "SteamApps"))
if is_lowercase:
appmanifest_paths = glob.glob(
os.path.join(
glob.escape(path), "steamapps", "appmanifest_*.acf"
)
)
elif is_mixedcase:
appmanifest_paths = glob.glob(
os.path.join(
glob.escape(path), "SteamApps", "appmanifest_*.acf"
)
)
if is_lowercase and is_mixedcase:
# Log a warning if both 'steamapps' and 'SteamApps' directories
# exist, as both Protontricks and Steam client have problems
# dealing with it (see issue #51)
logger.warning(
"Both 'steamapps' and 'SteamApps' directories were found at "
"%s. 'SteamApps' directory should be removed to prevent "
"issues with app and Proton discovery.",
path
)
for manifest_path in appmanifest_paths:
steam_app = SteamApp.from_appmanifest(
manifest_path, steam_lib_paths=steam_lib_paths
)
if steam_app:
steam_apps.append(steam_app)
# Get the custom Proton installations and non-Steam shortcuts as well
steam_apps += get_custom_proton_installations(steam_root=steam_root)
steam_apps += get_custom_windows_shortcuts(steam_path=steam_path)
# Exclude games that haven't been launched yet
steam_apps = [
app for app in steam_apps if app.prefix_path_exists or app.is_proton
]
# Sort the apps by their names
steam_apps.sort(key=lambda app: app.name)
return steam_apps