From 0e15ec0385b3e5938b158a17e0efe98764512af0 Mon Sep 17 00:00:00 2001 From: adam j hartz Date: Thu, 2 Apr 2015 21:37:23 -0400 Subject: [PATCH] more formatting --- xonsh/ast.py | 2 +- xonsh/openpy.py | 29 +++++++++++++++-------------- xonsh/pyghooks.py | 2 +- xonsh/shell.py | 9 ++++++--- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/xonsh/ast.py b/xonsh/ast.py index 0866d658e..2307887f7 100644 --- a/xonsh/ast.py +++ b/xonsh/ast.py @@ -42,7 +42,7 @@ def leftmostname(node): class CtxAwareTransformer(NodeTransformer): - """Transforms a xonsh AST based to use subprocess calls when + """Transforms a xonsh AST based to use subprocess calls when the first name in an expression statement is not known in the context. This assumes that the expression statement is instead parseable as a subprocess. diff --git a/xonsh/openpy.py b/xonsh/openpy.py index c1be16fcf..fdbd093b1 100644 --- a/xonsh/openpy.py +++ b/xonsh/openpy.py @@ -1,6 +1,6 @@ """ -Tools to open .py files as Unicode, using the encoding specified within the file, -as per PEP 263. +Tools to open .py files as Unicode, using the encoding specified within the +file, as per PEP 263. Much of the code is taken from the tokenize module in Python 3.2. @@ -44,20 +44,21 @@ except ImportError: # Copied from Python 3.2 tokenize def detect_encoding(readline): """ - The detect_encoding() function is used to detect the encoding that should - be used to decode a Python source file. It requires one argment, readline, - in the same way as the tokenize() generator. + The detect_encoding() function is used to detect the encoding that + should be used to decode a Python source file. It requires one + argment, readline, in the same way as the tokenize() generator. It will call readline a maximum of twice, and return the encoding used (as a string) and a list of any lines (left as bytes) it has read in. It detects the encoding from the presence of a utf-8 bom or an encoding - cookie as specified in pep-0263. If both a bom and a cookie are present, - but disagree, a SyntaxError will be raised. If the encoding cookie is an - invalid charset, raise a SyntaxError. Note that if a utf-8 bom is found, - 'utf-8-sig' is returned. + cookie as specified in pep-0263. If both a bom and a cookie are + present, but disagree, a SyntaxError will be raised. If the encoding + cookie is an invalid charset, raise a SyntaxError. Note that if a + utf-8 bom is found, 'utf-8-sig' is returned. - If no encoding is specified, then the default of 'utf-8' will be returned. + If no encoding is specified, then the default of 'utf-8' will be + returned. """ bom_found = False encoding = None @@ -180,7 +181,7 @@ def strip_encoding_cookie(filelike): def read_py_file(filename, skip_encoding_cookie=True): """Read a Python file, using the encoding declared inside the file. - + Parameters ---------- filename : str @@ -189,7 +190,7 @@ def read_py_file(filename, skip_encoding_cookie=True): If True (the default), and the encoding declaration is found in the first two lines, that line will be excluded from the output - compiling a unicode string with an encoding declaration is a SyntaxError in Python 2. - + Returns ------- A unicode string containing the contents of the file. @@ -203,7 +204,7 @@ def read_py_file(filename, skip_encoding_cookie=True): def read_py_url(url, errors='replace', skip_encoding_cookie=True): """Read a Python file from a URL, using the encoding declared inside the file. - + Parameters ---------- url : str @@ -215,7 +216,7 @@ def read_py_url(url, errors='replace', skip_encoding_cookie=True): If True (the default), and the encoding declaration is found in the first two lines, that line will be excluded from the output - compiling a unicode string with an encoding declaration is a SyntaxError in Python 2. - + Returns ------- A unicode string containing the contents of the file. diff --git a/xonsh/pyghooks.py b/xonsh/pyghooks.py index 96dc419ef..a6b9c7033 100644 --- a/xonsh/pyghooks.py +++ b/xonsh/pyghooks.py @@ -58,7 +58,7 @@ class XonshConsoleLexer(PythonLexer): 'root': [(r'^(>>>|\.\.\.) ', Generic.Prompt), (r'\n(>>>|\.\.\.)', Generic.Prompt), (r'\n(?![>.][>.][>.] )([^\n]*)', Generic.Output), - (r'\n(?![>.][>.][>.] )(.*?)$', Generic.Output), ] + ROOT_TOKENS, + (r'\n(?![>.][>.][>.] )(.*?)$', Generic.Output)] + ROOT_TOKENS, 'pymode': PYMODE_TOKENS, 'subproc': SUBPROC_TOKENS, } diff --git a/xonsh/shell.py b/xonsh/shell.py index d8a7ab071..aa4e174e2 100644 --- a/xonsh/shell.py +++ b/xonsh/shell.py @@ -93,8 +93,11 @@ class Shell(Cmd): stdout=stdout) self.execer = Execer() env = builtins.__xonsh_env__ - self.ctx = ctx if ctx is not None else \ - xonshrc_context(rcfile=env.get('XONSHRC', None), execer=self.execer) + if ctx is not None: + self.ctx = ctx + else: + rc = env.get('XONSHRC', None) + self.ctx = xonshrc_context(rcfile=rc, execer=self.execer) self.ctx['__name__'] = '__main__' self.completer = Completer() self.buffer = [] @@ -131,7 +134,7 @@ class Shell(Cmd): return True def push(self, line): - """Pushes a line onto the buffer and compiles the code in a way that + """Pushes a line onto the buffer and compiles the code in a way that enables multiline input. """ code = None