mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
pep8 changes
This commit is contained in:
parent
a8cc361aa4
commit
a6fe0dc4fb
3 changed files with 17 additions and 13 deletions
|
@ -177,7 +177,6 @@ def reglob(path, parts=None, i=None):
|
|||
return paths
|
||||
|
||||
|
||||
|
||||
def regexpath(s):
|
||||
"""Takes a regular expression string and returns a list of file
|
||||
paths that match the regex.
|
||||
|
|
|
@ -40,12 +40,12 @@ def locale_convert(key):
|
|||
return lc_converter
|
||||
|
||||
Ensurer = namedtuple('Ensurer', ['validate', 'convert', 'detype'])
|
||||
Ensurer.__doc__ = """Named tuples whose elements are functions that
|
||||
Ensurer.__doc__ = """Named tuples whose elements are functions that
|
||||
represent environment variable validation, conversion, detyping.
|
||||
"""
|
||||
|
||||
DEFAULT_ENSURERS = {
|
||||
re.compile('\w*PATH'): (is_env_path, str_to_env_path, env_path_to_str),
|
||||
re.compile('\w*PATH'): (is_env_path, str_to_env_path, env_path_to_str),
|
||||
'LC_CTYPE': (always_false, locale_convert('LC_CTYPE'), ensure_string),
|
||||
'LC_MESSAGES': (always_false, locale_convert('LC_MESSAGES'), ensure_string),
|
||||
'LC_COLLATE': (always_false, locale_convert('LC_COLLATE'), ensure_string),
|
||||
|
@ -116,8 +116,8 @@ class Env(MutableMapping):
|
|||
os.environ.update(self._orig_env)
|
||||
self._orig_env = None
|
||||
|
||||
def get_ensurer(self, key,
|
||||
default=Ensurer(always_true, None, ensure_string)):
|
||||
def get_ensurer(self, key,
|
||||
default=Ensurer(always_true, None, ensure_string)):
|
||||
"""Gets an ensurer for the given key."""
|
||||
if key in self.ensurers:
|
||||
return self.ensurers[key]
|
||||
|
@ -129,7 +129,7 @@ class Env(MutableMapping):
|
|||
ens = ensurer
|
||||
break
|
||||
else:
|
||||
ens = default
|
||||
ens = default
|
||||
self.ensurers[key] = ens
|
||||
return ens
|
||||
|
||||
|
@ -176,8 +176,6 @@ class Env(MutableMapping):
|
|||
self.__class__.__name__, self._d)
|
||||
|
||||
|
||||
|
||||
|
||||
def ensure_git(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
|
@ -274,10 +272,10 @@ DEFAULT_PROMPT = ('{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} '
|
|||
DEFAULT_TITLE = '{user}@{hostname}: {cwd} | xonsh'
|
||||
|
||||
|
||||
|
||||
def _replace_home(x):
|
||||
if ON_WINDOWS:
|
||||
home = builtins.__xonsh_env__['HOMEDRIVE'] + builtins.__xonsh_env__['HOMEPATH'][0]
|
||||
home = (builtins.__xonsh_env__['HOMEDRIVE'] +
|
||||
builtins.__xonsh_env__['HOMEPATH'][0])
|
||||
return x.replace(home, '~')
|
||||
else:
|
||||
return x.replace(builtins.__xonsh_env__['HOME'], '~')
|
||||
|
@ -433,7 +431,6 @@ def default_env(env=None):
|
|||
|
||||
ctx['PWD'] = _get_cwd()
|
||||
|
||||
|
||||
if env is not None:
|
||||
ctx.update(env)
|
||||
return ctx
|
||||
|
|
|
@ -372,8 +372,9 @@ def suggestion_sort_helper(x, y):
|
|||
iny = len([i for i in y if i not in x])
|
||||
return lendiff + inx + iny
|
||||
|
||||
|
||||
def escape_windows_title_string(s):
|
||||
"""Returns a string that is usable by the Windows cmd.exe title
|
||||
"""Returns a string that is usable by the Windows cmd.exe title
|
||||
builtin. The escaping is based on details here and emperical testing:
|
||||
http://www.robvanderwoude.com/escapechars.php
|
||||
"""
|
||||
|
@ -387,18 +388,22 @@ def escape_windows_title_string(s):
|
|||
# Validators and contervers
|
||||
#
|
||||
|
||||
|
||||
def is_int(x):
|
||||
"""Tests if something is an integer"""
|
||||
return isinstance(x, int)
|
||||
|
||||
|
||||
def always_true(x):
|
||||
"""Returns True"""
|
||||
return True
|
||||
|
||||
|
||||
def always_false(x):
|
||||
"""Returns False"""
|
||||
return False
|
||||
|
||||
|
||||
def ensure_string(x):
|
||||
"""Returns a string if x is not a string, and x if it alread is."""
|
||||
if isinstance(x, string_types):
|
||||
|
@ -406,6 +411,7 @@ def ensure_string(x):
|
|||
else:
|
||||
return str(x)
|
||||
|
||||
|
||||
def is_env_path(x):
|
||||
"""This tests if something is an environment path, ie a list of strings."""
|
||||
if isinstance(x, string_types):
|
||||
|
@ -414,12 +420,14 @@ def is_env_path(x):
|
|||
return isinstance(x, Sequence) and \
|
||||
all([isinstance(a, string_types) for a in x])
|
||||
|
||||
|
||||
def str_to_env_path(x):
|
||||
"""Converts a string to an environment path, ie a list of strings,
|
||||
"""Converts a string to an environment path, ie a list of strings,
|
||||
splitting on the OS separator.
|
||||
"""
|
||||
return x.split(os.pathsep)
|
||||
|
||||
|
||||
def env_path_to_str(x):
|
||||
"""Converts an environment path to a string by joining on the OS separator.
|
||||
"""
|
||||
|
|
Loading…
Add table
Reference in a new issue