コード例 #1
0
ファイル: test_expanded.py プロジェクト: zengchunyun/mycli
def test_expanded_table_renders():
    results = [('hello', text_type(123)), ('world', text_type(456))]

    expected = dedent("""\
        ***************************[ 1. row ]***************************
        name | hello
        age  | 123
        ***************************[ 2. row ]***************************
        name | world
        age  | 456
        """)
    assert expected == expanded_table(results, ('name', 'age'))
コード例 #2
0
ファイル: preprocessors.py プロジェクト: zengchunyun/mycli
def align_decimals(data, headers, **_):
    """Align decimals to decimal point."""
    pointpos = len(headers) * [0]
    for row in data:
        for i, v in enumerate(row):
            if isinstance(v, Decimal):
                v = encodingutils.text_type(v)
                pointpos[i] = max(intlen(v), pointpos[i])
    results = []
    for row in data:
        result = []
        for i, v in enumerate(row):
            if isinstance(v, Decimal):
                v = encodingutils.text_type(v)
                result.append((pointpos[i] - intlen(v)) * " " + v)
            else:
                result.append(v)
        results.append(result)
    return results, headers
コード例 #3
0
ファイル: filepaths.py プロジェクト: zxgdhd/mycli
def suggest_path(root_dir):
    """List all files and subdirectories in a directory.

    If the directory is not specified, suggest root directory,
    user directory, current and parent directory.

    :param root_dir: string: directory to list
    :return: list

    """
    if not root_dir:
        return [text_type(os.path.abspath(os.sep)), text_type('~'), text_type(os.curdir), text_type(os.pardir)]

    if '~' in root_dir:
        root_dir = text_type(os.path.expanduser(root_dir))

    if not os.path.exists(root_dir):
        root_dir, _ = os.path.split(root_dir)

    return list_path(root_dir)
コード例 #4
0
ファイル: preprocessors.py プロジェクト: zengchunyun/mycli
def quote_whitespaces(data, headers, quotestyle="'", **_):
    """Quote leading/trailing whitespace."""
    quote = len(headers) * [False]
    for row in data:
        for i, v in enumerate(row):
            v = encodingutils.text_type(v)
            if v.startswith(' ') or v.endswith(' '):
                quote[i] = True

    results = []
    for row in data:
        result = []
        for i, v in enumerate(row):
            quotation = quotestyle if quote[i] else ''
            result.append('{quotestyle}{value}{quotestyle}'.format(
                quotestyle=quotation, value=v))
        results.append(result)
    return results, headers
コード例 #5
0
ファイル: preprocessors.py プロジェクト: zengchunyun/mycli
def to_string(value):
    """Convert *value* to a string."""
    if isinstance(value, encodingutils.binary_type):
        return encodingutils.bytes_to_string(value)
    else:
        return encodingutils.text_type(value)