예제 #1
0
 def cache(self, code, *args, **kwargs):
     """Version of cache that compiles Coconut code first."""
     try:
         compiled = memoized_parse_block(code)
     except CoconutException:
         logger.display_exc()
         return None
     else:
         return super(CoconutCompiler,
                      self).cache(compiled, *args, **kwargs)
예제 #2
0
def using_path(path):
    """Removes a path at the beginning and end."""
    if os.path.exists(path):
        rm_path(path)
    try:
        yield
    finally:
        try:
            rm_path(path)
        except OSError:
            logger.display_exc()
예제 #3
0
파일: main_test.py 프로젝트: yggdr/coconut
def remove_when_done(path):
    """Removes a path when done."""
    try:
        yield
    finally:
        try:
            if os.path.isdir(path):
                shutil.rmtree(path)
            elif os.path.isfile(path):
                os.remove(path)
        except OSError as err:
            logger.display_exc()
예제 #4
0
파일: main_test.py 프로젝트: evhub/coconut
def remove_when_done(path):
    """Removes a path when done."""
    try:
        yield
    finally:
        try:
            if os.path.isdir(path):
                shutil.rmtree(path)
            elif os.path.isfile(path):
                os.remove(path)
        except OSError as err:
            logger.display_exc()
예제 #5
0
 def handling_exceptions(self):
     """Perform proper exception handling."""
     try:
         with handling_broken_process_pool():
             yield
     except SystemExit as err:
         self.register_error(err.code)
     except BaseException as err:
         if isinstance(err, CoconutException):
             logger.display_exc()
         elif not isinstance(err, KeyboardInterrupt):
             traceback.print_exc()
             printerr(report_this_text)
         self.register_error(errmsg=err.__class__.__name__)
예제 #6
0
def using_dest():
    """Makes and removes the dest folder."""
    try:
        os.mkdir(dest)
    except Exception:
        shutil.rmtree(dest)
        os.mkdir(dest)
    try:
        yield
    finally:
        try:
            rm_path(dest)
        except OSError:
            logger.display_exc()
예제 #7
0
파일: __init__.py 프로젝트: yggdr/coconut
 def magic(line, cell=None):
     """Provides %coconut and %%coconut magics."""
     try:
         if cell is None:
             code = line
         else:
             # first line in block is cmd, rest is code
             line = line.strip()
             if line:
                 cmd(line)
             code = cell
         compiled = parse(code)
     except CoconutException:
         logger.display_exc()
     else:
         ipython.run_cell(compiled, shell_futures=False)
예제 #8
0
파일: __init__.py 프로젝트: evhub/coconut
 def magic(line, cell=None):
     """Provides %coconut and %%coconut magics."""
     try:
         if cell is None:
             code = line
         else:
             # first line in block is cmd, rest is code
             line = line.strip()
             if line:
                 cmd(line, interact=False)
             code = cell
         compiled = parse(code)
     except CoconutException:
         logger.display_exc()
     else:
         ipython.run_cell(compiled, shell_futures=False)
예제 #9
0
파일: command.py 프로젝트: evhub/coconut
 def handling_exceptions(self):
     """Perform proper exception handling."""
     try:
         if self.using_jobs:
             with handling_broken_process_pool():
                 yield
         else:
             yield
     except SystemExit as err:
         self.register_error(err.code)
     except BaseException as err:
         if isinstance(err, CoconutException):
             logger.display_exc()
         elif not isinstance(err, KeyboardInterrupt):
             traceback.print_exc()
             printerr(report_this_text)
         self.register_error(errmsg=err.__class__.__name__)
예제 #10
0
파일: util.py 프로젝트: zhenyulin/coconut
 def input(self, more=False):
     """Prompt for code input."""
     sys.stdout.flush()
     if more:
         msg = more_prompt
     else:
         msg = main_prompt
     if self.style is not None:
         internal_assert(prompt_toolkit is not None, "without prompt_toolkit cannot highlight style", self.style)
         try:
             return self.prompt(msg)
         except EOFError:
             raise  # issubclass(EOFError, Exception), so we have to do this
         except (Exception, AssertionError):
             logger.display_exc()
             logger.show_sig("Syntax highlighting failed; switching to --style none.")
             self.style = None
     return input(msg)
예제 #11
0
 def handle_input(self, code):
     """Compile Coconut interpreter input."""
     if not self.prompt.multiline:
         if not should_indent(code):
             try:
                 return self.comp.parse_block(code)
             except CoconutException:
                 pass
         while True:
             line = self.get_input(more=True)
             if line is None:
                 return None
             elif line:
                 code += "\n" + line
             else:
                 break
     try:
         return self.comp.parse_block(code)
     except CoconutException:
         logger.display_exc()
     return None
예제 #12
0
파일: command.py 프로젝트: evhub/coconut
 def handle_input(self, code):
     """Compile Coconut interpreter input."""
     if not self.prompt.multiline:
         if not should_indent(code):
             try:
                 return self.comp.parse_block(code)
             except CoconutException:
                 pass
         while True:
             line = self.get_input(more=True)
             if line is None:
                 return None
             elif line:
                 code += "\n" + line
             else:
                 break
     try:
         return self.comp.parse_block(code)
     except CoconutException:
         logger.display_exc()
     return None