Exemplo n.º 1
0
    def test_get_source_file(self):
        path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "fodder")

        encoding = inspection.get_encoding_file(os.path.join(path, "encoding_ascii.py"))
        self.assertEqual(encoding, "ascii")
        encoding = inspection.get_encoding_file(os.path.join(path, "encoding_latin1.py"))
        self.assertEqual(encoding, "latin1")
        encoding = inspection.get_encoding_file(os.path.join(path, "encoding_utf8.py"))
        self.assertEqual(encoding, "utf-8")
Exemplo n.º 2
0
    def test_get_source_file(self):
        path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            'fodder')

        encoding = inspection.get_encoding_file(
            os.path.join(path, 'encoding_ascii.py'))
        self.assertEqual(encoding, 'ascii')
        encoding = inspection.get_encoding_file(
            os.path.join(path, 'encoding_latin1.py'))
        self.assertEqual(encoding, 'latin1')
        encoding = inspection.get_encoding_file(
            os.path.join(path, 'encoding_utf8.py'))
        self.assertEqual(encoding, 'utf-8')
Exemplo n.º 3
0
    def test_get_source_file(self):
        path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            "fodder")

        encoding = inspection.get_encoding_file(
            os.path.join(path, "encoding_ascii.py"))
        self.assertEqual(encoding, "ascii")
        encoding = inspection.get_encoding_file(
            os.path.join(path, "encoding_latin1.py"))
        self.assertEqual(encoding, "latin1")
        encoding = inspection.get_encoding_file(
            os.path.join(path, "encoding_utf8.py"))
        self.assertEqual(encoding, "utf-8")
Exemplo n.º 4
0
def main(args=None, locals_=None, banner=None):
    translations.init()

    config, options, exec_args = bpargs.parse(
        args, ('curtsies options', None, [
            Option('--log',
                   '-L',
                   action='count',
                   help=_("log debug messages to bpython.log")),
            Option('--paste',
                   '-p',
                   action='store_true',
                   help=_("start by pasting lines of a file into session")),
        ]))
    if options.log is None:
        options.log = 0
    logging_levels = [logging.ERROR, logging.INFO, logging.DEBUG]
    level = logging_levels[min(len(logging_levels) - 1, options.log)]
    logging.getLogger('curtsies').setLevel(level)
    logging.getLogger('bpython').setLevel(level)
    if options.log:
        handler = logging.FileHandler(filename='bpython.log')
        logging.getLogger('curtsies').addHandler(handler)
        logging.getLogger('curtsies').propagate = False
        logging.getLogger('bpython').addHandler(handler)
        logging.getLogger('bpython').propagate = False

    interp = None
    paste = None
    if exec_args:
        if not options:
            raise ValueError("don't pass in exec_args without options")
        exit_value = 0
        if options.paste:
            paste = curtsies.events.PasteEvent()
            encoding = inspection.get_encoding_file(exec_args[0])
            with io.open(exec_args[0], encoding=encoding) as f:
                sourcecode = f.read()
            paste.events.extend(sourcecode)
        else:
            try:
                interp = code.InteractiveInterpreter(locals=locals_)
                bpargs.exec_code(interp, exec_args)
            except SystemExit as e:
                exit_value = e.args
            if not options.interactive:
                raise SystemExit(exit_value)
    else:
        # expected for interactive sessions (vanilla python does it)
        sys.path.insert(0, '')

    print(bpargs.version_banner())
    mainloop(config,
             locals_,
             banner,
             interp,
             paste,
             interactive=(not exec_args))
Exemplo n.º 5
0
 def startup(self):
     """
     Execute PYTHONSTARTUP file if it exits. Call this after front
     end-specific initialisation.
     """
     filename = os.environ.get('PYTHONSTARTUP')
     if filename:
         encoding = inspection.get_encoding_file(filename)
         with io.open(filename, 'rt', encoding=encoding) as f:
             source = f.read()
             if not py3:
                 # Python 2.6 and early 2.7.X need bytes.
                 source = source.encode(encoding)
             self.interp.runsource(source, filename, 'exec', encode=False)
Exemplo n.º 6
0
 def startup(self):
     """
     Execute PYTHONSTARTUP file if it exits. Call this after front
     end-specific initialisation.
     """
     filename = os.environ.get('PYTHONSTARTUP')
     if filename:
         encoding = inspection.get_encoding_file(filename)
         with io.open(filename, 'rt', encoding=encoding) as f:
             source = f.read()
             if not py3:
                 # Python 2.6 and early 2.7.X need bytes.
                 source = source.encode(encoding)
             self.interp.runsource(source, filename, 'exec', encode=False)
Exemplo n.º 7
0
def main(args=None, locals_=None, banner=None, welcome_message=None):
    """
    banner is displayed directly after the version information.
    welcome_message is passed on to Repl and displayed in the statusbar.
    """
    translations.init()

    config, options, exec_args = bpargs.parse(args, (
        'curtsies options', None, [
            Option('--log', '-L', action='count',
                   help=_("log debug messages to bpython.log")),
            Option('--paste', '-p', action='store_true',
                   help=_("start by pasting lines of a file into session")),
            ]))
    if options.log is None:
        options.log = 0
    logging_levels = [logging.ERROR, logging.INFO, logging.DEBUG]
    level = logging_levels[min(len(logging_levels) - 1, options.log)]
    logging.getLogger('curtsies').setLevel(level)
    logging.getLogger('bpython').setLevel(level)
    if options.log:
        handler = logging.FileHandler(filename='bpython.log')
        logging.getLogger('curtsies').addHandler(handler)
        logging.getLogger('curtsies').propagate = False
        logging.getLogger('bpython').addHandler(handler)
        logging.getLogger('bpython').propagate = False

    interp = None
    paste = None
    if exec_args:
        if not options:
            raise ValueError("don't pass in exec_args without options")
        exit_value = ()
        if options.paste:
            paste = curtsies.events.PasteEvent()
            encoding = inspection.get_encoding_file(exec_args[0])
            with io.open(exec_args[0], encoding=encoding) as f:
                sourcecode = f.read()
            paste.events.extend(sourcecode)
        else:
            try:
                interp = Interp(locals=locals_)
                bpargs.exec_code(interp, exec_args)
            except SystemExit as e:
                exit_value = e.args
            if not options.interactive:
                return extract_exit_value(exit_value)
    else:
        # expected for interactive sessions (vanilla python does it)
        sys.path.insert(0, '')

    if not options.quiet:
        print(bpargs.version_banner())
    if banner is not None:
        print(banner)
    global repl
    repl = FullCurtsiesRepl(config, locals_, welcome_message, interp, paste)
    try:
        with repl.input_generator:
            with repl.window as win:
                with repl:
                    repl.height, repl.width = win.t.height, win.t.width
                    exit_value = repl.mainloop()
    except (SystemExitFromCodeGreenlet, SystemExit) as e:
        exit_value = e.args
    return extract_exit_value(exit_value)
Exemplo n.º 8
0
def main(args=None, locals_=None, banner=None, welcome_message=None):
    """
    banner is displayed directly after the version information.
    welcome_message is passed on to Repl and displayed in the statusbar.
    """
    translations.init()

    config, options, exec_args = bpargs.parse(
        args, ('curtsies options', None, [
            Option('--log',
                   '-L',
                   action='count',
                   help=_("log debug messages to bpython.log")),
            Option('--paste',
                   '-p',
                   action='store_true',
                   help=_("start by pasting lines of a file into session")),
        ]))
    if options.log is None:
        options.log = 0
    logging_levels = [logging.ERROR, logging.INFO, logging.DEBUG]
    level = logging_levels[min(len(logging_levels) - 1, options.log)]
    logging.getLogger('curtsies').setLevel(level)
    logging.getLogger('bpython').setLevel(level)
    if options.log:
        handler = logging.FileHandler(filename='bpython.log')
        logging.getLogger('curtsies').addHandler(handler)
        logging.getLogger('curtsies').propagate = False
        logging.getLogger('bpython').addHandler(handler)
        logging.getLogger('bpython').propagate = False

    interp = None
    paste = None
    if exec_args:
        if not options:
            raise ValueError("don't pass in exec_args without options")
        exit_value = ()
        if options.paste:
            paste = curtsies.events.PasteEvent()
            encoding = inspection.get_encoding_file(exec_args[0])
            with io.open(exec_args[0], encoding=encoding) as f:
                sourcecode = f.read()
            paste.events.extend(sourcecode)
        else:
            try:
                interp = Interp(locals=locals_)
                bpargs.exec_code(interp, exec_args)
            except SystemExit as e:
                exit_value = e.args
            if not options.interactive:
                return extract_exit_value(exit_value)
    else:
        # expected for interactive sessions (vanilla python does it)
        sys.path.insert(0, '')

    if not options.quiet:
        print(bpargs.version_banner())
    if banner is not None:
        print(banner)
    global repl
    repl = FullCurtsiesRepl(config, locals_, welcome_message, interp, paste)
    try:
        with repl.input_generator:
            with repl.window as win:
                with repl:
                    repl.height, repl.width = win.t.height, win.t.width
                    exit_value = repl.mainloop()
    except (SystemExitFromCodeGreenlet, SystemExit) as e:
        exit_value = e.args
    return extract_exit_value(exit_value)