Skip to content

Commit

Permalink
Clean up;
Browse files Browse the repository at this point in the history
  • Loading branch information
annihilator708 committed Aug 31, 2018
1 parent bc2dd7d commit 0c44a6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
3 changes: 3 additions & 0 deletions nx/utils/terminal.py
Expand Up @@ -218,6 +218,9 @@ def main(self):
# Start to fetch the data
self.input = self.utils.import_url(url)
else:
# Append result to history
self.input += "\n"
self.cli_history.append(self.input)
# Execute user command
self.input = self.python.repl(self.input)
# total character limit on screen
Expand Down
13 changes: 5 additions & 8 deletions nx/utils/terminal_src/python.py
Expand Up @@ -16,12 +16,9 @@ def cleanup_code(self, content):
return content.strip('\n')

def get_syntax_error(self, e):
try:
if e.text is None:
return '{0.__class__.__name__}: {0}'.format(e)
return '{0.text}{1:>{0.offset}}\n{2}: {0}'.format(e, '^', type(e).__name__)
except:
if e.text is None:
return '{0.__class__.__name__}: {0}'.format(e)
return '{0.text}{1:>{0.offset}}\n{2}: {0}'.format(e, '^', type(e).__name__)

def repl(self, raw_code):
variables = {
Expand All @@ -32,10 +29,10 @@ def repl(self, raw_code):
cleaned = self.cleanup_code(raw_code)
if cleaned in ('quit', 'exit', 'exit()'):
pass # TODO quit terminal
self.logger.info(cleaned)

executor = exec
# if there are no new lines this is protentional a one liner
if cleaned.count('\n') == 0:
if raw_code.count('\n') == 0:
try:
code = compile(cleaned, '<repl session>', 'eval')
except SyntaxError:
Expand All @@ -58,7 +55,7 @@ def repl(self, raw_code):
if inspect.iscode(result):
result = result
except Exception as e:
return str(self.get_syntax_error(e))
return '{0.__class__.__name__}: {0}'.format(e)
else:
value = stdout.getvalue()
if result is not None:
Expand Down

0 comments on commit 0c44a6c

Please sign in to comment.