Exemplo n.º 1
0
def get_entrypoints(filename):
    if not os.path.exists(filename):
        return {}, {}

    # This is done because you can pass a string to entry_points wrappers which
    # means that they may or may not be valid INI files. The attempt here is to
    # strip leading and trailing whitespace in order to make them valid INI
    # files.
    with open(filename) as fp:
        data = StringIO()
        for line in fp:
            data.write(line.strip())
            data.write("\n")
        data.seek(0)

    cp = ConfigParser.RawConfigParser()
    cp.readfp(data)

    console = {}
    gui = {}
    if cp.has_section('console_scripts'):
        console = dict(cp.items('console_scripts'))
    if cp.has_section('gui_scripts'):
        gui = dict(cp.items('gui_scripts'))
    return console, gui
Exemplo n.º 2
0
def test_log_no_extra_line_break():
    """
    Confirm that multiple `.write()` consumers doesn't result in additional '\n's per write
    """
    consumer1 = StringIO()
    consumer2 = StringIO()
    logger = Logger()
    logger.add_consumers(
            (logger.NOTIFY, consumer1),
            (logger.NOTIFY, consumer2)
            )
    logger.notify("one line")
    # splitlines(True) will detect empty line-breaks
    assert 1 == len(consumer1.getvalue().splitlines(True))
    assert 1 == len(consumer2.getvalue().splitlines(True))
Exemplo n.º 3
0
def get_entrypoints(filename):
    if not os.path.exists(filename):
        return {}, {}

    # This is done because you can pass a string to entry_points wrappers which
    # means that they may or may not be valid INI files. The attempt here is to
    # strip leading and trailing whitespace in order to make them valid INI
    # files.
    with open(filename) as fp:
        data = StringIO()
        for line in fp:
            data.write(line.strip())
            data.write("\n")
        data.seek(0)

    cp = ConfigParser.RawConfigParser()
    cp.readfp(data)

    console = {}
    gui = {}
    if cp.has_section('console_scripts'):
        console = dict(cp.items('console_scripts'))
    if cp.has_section('gui_scripts'):
        gui = dict(cp.items('gui_scripts'))
    return console, gui
Exemplo n.º 4
0
def get_entrypoints(filename):
    if not os.path.exists(filename):
        return {}, {}

    # This is done because you can pass a string to entry_points wrappers which
    # means that they may or may not be valid INI files. The attempt here is to
    # strip leading and trailing whitespace in order to make them valid INI
    # files.
    with open(filename) as fp:
        data = StringIO()
        for line in fp:
            data.write(line.strip())
            data.write("\n")
        data.seek(0)
Exemplo n.º 5
0
def test_log_no_extra_line_break():
    """
    Confirm that multiple `.write()` consumers doesn't result in additional '\n's per write
    """
    consumer1 = StringIO()
    consumer2 = StringIO()
    logger = Logger()
    logger.add_consumers((logger.NOTIFY, consumer1),
                         (logger.NOTIFY, consumer2))
    logger.notify("one line")
    # splitlines(True) will detect empty line-breaks
    assert 1 == len(consumer1.getvalue().splitlines(True))
    assert 1 == len(consumer2.getvalue().splitlines(True))
Exemplo n.º 6
0
def format_exc(exc_info=None):
    if exc_info is None:
        exc_info = sys.exc_info()
    out = StringIO()
    traceback.print_exception(*exc_info, **dict(file=out))
    return out.getvalue()
Exemplo n.º 7
0
def format_exc(exc_info=None):
    if exc_info is None:
        exc_info = sys.exc_info()
    out = StringIO()
    traceback.print_exception(*exc_info, **dict(file=out))
    return out.getvalue()