本文整理汇总了Python中xonsh.tools.get_sep函数的典型用法代码示例。如果您正苦于以下问题:Python get_sep函数的具体用法?Python get_sep怎么用?Python get_sep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_sep函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _joinpath
def _joinpath(path):
# convert our tuple representation back into a string representing a path
if path is None:
return ''
elif len(path) == 0:
return ''
elif path == ('',):
return get_sep()
elif path[0] == '':
return get_sep() + _normpath(os.path.join(*path))
else:
return _normpath(os.path.join(*path))
开发者ID:DangerOnTheRanger,项目名称:xonsh,代码行数:12,代码来源:path.py
示例2: _quote_paths
def _quote_paths(paths, start, end):
expand_path = builtins.__xonsh_expand_path__
out = set()
space = ' '
backslash = '\\'
double_backslash = '\\\\'
slash = xt.get_sep()
orig_start = start
orig_end = end
for s in paths:
start = orig_start
end = orig_end
if (start == '' and
(re.search(PATTERN_NEED_QUOTES, s) is not None or
(backslash in s and slash != backslash))):
start = end = _quote_to_use(s)
if os.path.isdir(expand_path(s)):
_tail = slash
elif end == '':
_tail = space
else:
_tail = ''
if start != '' and 'r' not in start and backslash in s:
start = 'r%s' % start
s = s + _tail
if end != '':
if "r" not in start.lower():
s = s.replace(backslash, double_backslash)
if s.endswith(backslash) and not s.endswith(double_backslash):
s += backslash
if end in s:
s = s.replace(end, ''.join('\\%s' % i for i in end))
out.add(start + s + end)
return out
开发者ID:Carreau,项目名称:xonsh,代码行数:34,代码来源:path.py
示例3: _quote_paths
def _quote_paths(self, paths, start, end):
out = set()
space = ' '
backslash = '\\'
double_backslash = '\\\\'
slash = get_sep()
orig_start = start
orig_end = end
for s in paths:
start = orig_start
end = orig_end
if (start == '' and
(any(i in s for i in CHARACTERS_NEED_QUOTES) or
(backslash in s and slash != backslash))):
start = end = self._quote_to_use(s)
if os.path.isdir(expand_path(s)):
_tail = slash
elif end == '':
_tail = space
else:
_tail = ''
s = s + _tail
if end != '':
if "r" not in start.lower():
s = s.replace(backslash, double_backslash)
elif s.endswith(backslash):
s += backslash
if end in s:
s = s.replace(end, ''.join('\\%s' % i for i in end))
out.add(start + s + end)
return out
开发者ID:mwiebe,项目名称:xonsh,代码行数:31,代码来源:completer.py
示例4: _quote_paths
def _quote_paths(paths, start, end):
expand_path = builtins.__xonsh_expand_path__
out = set()
space = " "
backslash = "\\"
double_backslash = "\\\\"
slash = get_sep()
orig_start = start
orig_end = end
for s in paths:
start = orig_start
end = orig_end
if start == "" and (any(i in s for i in CHARACTERS_NEED_QUOTES) or (backslash in s and slash != backslash)):
start = end = _quote_to_use(s)
if os.path.isdir(expand_path(s)):
_tail = slash
elif end == "":
_tail = space
else:
_tail = ""
if start != "" and "r" not in start and backslash in s:
start = "r%s" % start
s = s + _tail
if end != "":
if "r" not in start.lower():
s = s.replace(backslash, double_backslash)
if s.endswith(backslash) and not s.endswith(double_backslash):
s += backslash
if end in s:
s = s.replace(end, "".join("\\%s" % i for i in end))
out.add(start + s + end)
return out
开发者ID:asmeurer,项目名称:xonsh,代码行数:32,代码来源:path.py
示例5: _collapsed_pwd
def _collapsed_pwd():
sep = get_sep()
pwd = _replace_home_cwd().split(sep)
l = len(pwd)
leader = sep if l>0 and len(pwd[0])==0 else ''
base = [i[0] if ix != l-1 else i for ix,i in enumerate(pwd) if len(i) > 0]
return leader + sep.join(base)
开发者ID:eskhool,项目名称:xonsh,代码行数:7,代码来源:environ.py
示例6: _quote_paths
def _quote_paths(self, paths, start, end):
out = set()
space = ' '
backslash = '\\'
double_backslash = '\\\\'
slash = get_sep()
for s in paths:
if (start == '' and
(space in s or (backslash in s and slash != backslash))):
start = "'"
end = "'"
if os.path.isdir(expand_path(s)):
_tail = slash
elif end == '':
_tail = space
else:
_tail = ''
s = s + _tail
if end != '':
if "r" not in start.lower():
s = s.replace(backslash, double_backslash)
elif s.endswith(backslash):
s += backslash
out.add(start + s + end)
return out
开发者ID:eskhool,项目名称:xonsh,代码行数:25,代码来源:completer.py
示例7: _change_working_directory
def _change_working_directory(newdir, follow_symlinks=False):
env = builtins.__xonsh_env__
old = env['PWD']
new = os.path.join(old, newdir)
absnew = os.path.abspath(new)
if follow_symlinks:
absnew = os.path.realpath(absnew)
try:
os.chdir(absnew)
except (OSError, FileNotFoundError):
if new.endswith(get_sep()):
new = new[:-1]
if os.path.basename(new) == '..':
env['PWD'] = new
else:
if old is not None:
env['OLDPWD'] = old
if new is not None:
env['PWD'] = absnew
# Fire event if the path actually changed
if old != env['PWD']:
events.on_chdir.fire(olddir=old, newdir=env['PWD'])
开发者ID:laerus,项目名称:xonsh,代码行数:25,代码来源:dirstack.py
示例8: _splitpath_helper
def _splitpath_helper(path, sofar=()):
folder, path = os.path.split(path)
if path:
sofar = sofar + (path, )
if (not folder or folder == xt.get_sep() or
(xp.ON_WINDOWS and os.path.splitdrive(path)[0])):
return sofar[::-1]
return _splitpath_helper(folder, sofar)
开发者ID:Carreau,项目名称:xonsh,代码行数:8,代码来源:path.py
示例9: _splitpath
def _splitpath(path):
# convert a path into an intermediate tuple representation
# if this tuple starts with '', it means that the path was an absolute path
path = _normpath(path)
if path.startswith(get_sep()):
pre = ('', )
else:
pre = ()
return pre + _splitpath_helper(path, ())
开发者ID:DangerOnTheRanger,项目名称:xonsh,代码行数:9,代码来源:path.py
示例10: _dots
def _dots(prefix):
slash = xt.get_sep()
if slash == "\\":
slash = ""
if prefix in {"", "."}:
return ("." + slash, ".." + slash)
elif prefix == "..":
return (".." + slash,)
else:
return ()
开发者ID:donnemartin,项目名称:gitsome,代码行数:10,代码来源:path.py
示例11: _dots
def _dots(prefix):
slash = get_sep()
if slash == '\\':
slash = ''
if prefix in {'', '.'}:
return ('.'+slash, '..'+slash)
elif prefix == '..':
return ('..'+slash,)
else:
return ()
开发者ID:DangerOnTheRanger,项目名称:xonsh,代码行数:10,代码来源:path.py
示例12: completionwrap
def completionwrap(s):
""" Returns the repr of input string s if that string contains
a 'problem' token that will confuse the xonsh parser
"""
space = ' '
slash = get_sep()
return (_normpath(repr(s + (slash if os.path.isdir(s) else '')))
if COMPLETION_WRAP_TOKENS.intersection(s) else
s + space
if s[-1:].isalnum() else
s)
开发者ID:lmmx,项目名称:xonsh,代码行数:11,代码来源:completer.py
示例13: _splitpath_helper
def _splitpath_helper(path, sofar=()):
folder, path = os.path.split(path)
if path:
sofar = sofar + (path, )
if not folder or folder == xt.get_sep():
return sofar[::-1]
elif xp.ON_WINDOWS and not path:
return os.path.splitdrive(folder)[:1] + sofar[::-1]
elif xp.ON_WINDOWS and os.path.splitdrive(path)[0]:
return sofar[::-1]
return _splitpath_helper(folder, sofar)
开发者ID:VHarisop,项目名称:xonsh,代码行数:11,代码来源:path.py
示例14: _change_working_directory
def _change_working_directory(newdir):
env = builtins.__xonsh_env__
old = env['PWD']
new = os.path.join(old, newdir)
try:
os.chdir(os.path.abspath(new))
except (OSError, FileNotFoundError):
if new.endswith(get_sep()):
new = new[:-1]
if os.path.basename(new) == '..':
env['PWD'] = new
return
if old is not None:
env['OLDPWD'] = old
if new is not None:
env['PWD'] = os.path.abspath(new)
开发者ID:BlaXpirit,项目名称:xonsh,代码行数:16,代码来源:dirstack.py
示例15: _dynamically_collapsed_pwd
def _dynamically_collapsed_pwd():
"""Return the compact current working directory. It respects the
environment variable DYNAMIC_CWD_WIDTH.
"""
original_path = _replace_home_cwd()
target_width, units = builtins.__xonsh__.env["DYNAMIC_CWD_WIDTH"]
elision_char = builtins.__xonsh__.env["DYNAMIC_CWD_ELISION_CHAR"]
if target_width == float("inf"):
return original_path
if units == "%":
cols, _ = shutil.get_terminal_size()
target_width = (cols * target_width) // 100
sep = xt.get_sep()
pwd = original_path.split(sep)
last = pwd.pop()
remaining_space = target_width - len(last)
# Reserve space for separators
remaining_space_for_text = remaining_space - len(pwd)
parts = []
for i in range(len(pwd)):
part = pwd[i]
part_len = int(
min(len(part), max(1, remaining_space_for_text // (len(pwd) - i)))
)
remaining_space_for_text -= part_len
if len(part) > part_len:
reduced_part = part[0 : part_len - len(elision_char)] + elision_char
parts.append(reduced_part)
else:
parts.append(part)
parts.append(last)
full = sep.join(parts)
truncature_char = elision_char if elision_char else "..."
# If even if displaying one letter per dir we are too long
if len(full) > target_width:
# We truncate the left most part
full = truncature_char + full[int(-target_width) + len(truncature_char) :]
# if there is not even a single separator we still
# want to display at least the beginning of the directory
if full.find(sep) == -1:
full = (truncature_char + sep + last)[
0 : int(target_width) - len(truncature_char)
] + truncature_char
return full
开发者ID:ericmharris,项目名称:xonsh,代码行数:44,代码来源:cwd.py
示例16: _quote_paths
def _quote_paths(paths, start, end, append_end=True):
expand_path = builtins.__xonsh_expand_path__
out = set()
space = ' '
backslash = '\\'
double_backslash = '\\\\'
slash = xt.get_sep()
orig_start = start
orig_end = end
# quote on all or none, to make readline completes to max prefix
need_quotes = any(
re.search(PATTERN_NEED_QUOTES, x) or
(backslash in x and slash != backslash)
for x in paths)
for s in paths:
start = orig_start
end = orig_end
if start == '' and need_quotes:
start = end = _quote_to_use(s)
if os.path.isdir(expand_path(s)):
_tail = slash
elif end == '':
_tail = space
else:
_tail = ''
if start != '' and 'r' not in start and backslash in s:
start = 'r%s' % start
s = s + _tail
if end != '':
if "r" not in start.lower():
s = s.replace(backslash, double_backslash)
if s.endswith(backslash) and not s.endswith(double_backslash):
s += backslash
if end in s:
s = s.replace(end, ''.join('\\%s' % i for i in end))
s = start + s + end if append_end else start + s
out.add(s)
return out, need_quotes
开发者ID:VHarisop,项目名称:xonsh,代码行数:39,代码来源:path.py
示例17: _dynamically_collapsed_pwd
def _dynamically_collapsed_pwd():
"""Return the compact current working directory. It respects the
environment variable DYNAMIC_CWD_WIDTH.
"""
originial_path = _replace_home_cwd()
target_width, units = builtins.__xonsh_env__['DYNAMIC_CWD_WIDTH']
if target_width == float('inf'):
return originial_path
if (units == '%'):
cols, _ = shutil.get_terminal_size()
target_width = (cols * target_width) // 100
sep = xt.get_sep()
pwd = originial_path.split(sep)
last = pwd.pop()
remaining_space = target_width - len(last)
# Reserve space for separators
remaining_space_for_text = remaining_space - len(pwd)
parts = []
for i in range(len(pwd)):
part = pwd[i]
part_len = int(min(len(part),
max(1, remaining_space_for_text // (len(pwd) - i))))
remaining_space_for_text -= part_len
reduced_part = part[0:part_len]
parts.append(reduced_part)
parts.append(last)
full = sep.join(parts)
# If even if displaying one letter per dir we are too long
if (len(full) > target_width):
# We truncate the left most part
full = "..." + full[int(-target_width) + 3:]
# if there is not even a single separator we still
# want to display at least the beginning of the directory
if full.find(sep) == -1:
full = ("..." + sep + last)[0:int(target_width)]
return full
开发者ID:astronouth7303,项目名称:xonsh,代码行数:36,代码来源:cwd.py
注:本文中的xonsh.tools.get_sep函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论