How to use the pgcli.encodingutils.text_type function in pgcli

To help you get started, we’ve selected a few pgcli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dbcli / pgcli / pgcli / main.py View on Github external
def format_array(val):
        if val is None:
            return settings.missingval
        if not isinstance(val, list):
            return val
        return '{' + ','.join(text_type(format_array(e)) for e in val) + '}'
github dbcli / pgcli / pgcli / main.py View on Github external
def format_array(val):
        if val is None:
            return settings.missingval
        if not isinstance(val, list):
            return val
        return "{" + ",".join(text_type(format_array(e)) for e in val) + "}"
github dbcli / pgcli / pgcli / main.py View on Github external
column_types = None
        if hasattr(cur, "description"):
            column_types = []
            for d in cur.description:
                if (
                    d[1] in psycopg2.extensions.DECIMAL.values
                    or d[1] in psycopg2.extensions.FLOAT.values
                ):
                    column_types.append(float)
                if (
                    d[1] == psycopg2.extensions.INTEGER.values
                    or d[1] in psycopg2.extensions.LONGINTEGER.values
                ):
                    column_types.append(int)
                else:
                    column_types.append(text_type)

        formatted = formatter.format_output(cur, headers, **output_kwargs)
        if isinstance(formatted, (text_type)):
            formatted = iter(formatted.splitlines())
        first_line = next(formatted)
        formatted = itertools.chain([first_line], formatted)
        if not expanded and max_width and len(first_line) > max_width and headers:
            formatted = formatter.format_output(
                cur, headers, format_name="vertical", column_types=None, **output_kwargs
            )
            if isinstance(formatted, (text_type)):
                formatted = iter(formatted.splitlines())

        output = itertools.chain(output, formatted)

    if status:  # Only print the status if it's not None.
github dbcli / pgcli / pgcli / main.py View on Github external
column_types.append(float)
                if d[1] == psycopg2.extensions.INTEGER.values or \
                        d[1] in psycopg2.extensions.LONGINTEGER.values:
                    column_types.append(int)
                else:
                    column_types.append(text_type)
        formatted = formatter.format_output(cur, headers, **output_kwargs)
        if isinstance(formatted, (text_type)):
            formatted = iter(formatted.splitlines())
        first_line = next(formatted)
        formatted = itertools.chain([first_line], formatted)

        if (not expanded and max_width and len(first_line) > max_width and headers):
            formatted = formatter.format_output(
                cur, headers, format_name='vertical', column_types=None, **output_kwargs)
            if isinstance(formatted, (text_type)):
                formatted = iter(formatted.splitlines())

        output = itertools.chain(output, formatted)

    if status:  # Only print the status if it's not None.
        output = itertools.chain(output, [status])

    return output
github dbcli / pgcli / pgcli / main.py View on Github external
if max_width is not None:
            cur = list(cur)
        column_types = None
        if hasattr(cur, 'description'):
            column_types = []
            for d in cur.description:
                if d[1] in psycopg2.extensions.DECIMAL.values or \
                        d[1] in psycopg2.extensions.FLOAT.values:
                    column_types.append(float)
                if d[1] == psycopg2.extensions.INTEGER.values or \
                        d[1] in psycopg2.extensions.LONGINTEGER.values:
                    column_types.append(int)
                else:
                    column_types.append(text_type)
        formatted = formatter.format_output(cur, headers, **output_kwargs)
        if isinstance(formatted, (text_type)):
            formatted = iter(formatted.splitlines())
        first_line = next(formatted)
        formatted = itertools.chain([first_line], formatted)

        if (not expanded and max_width and len(first_line) > max_width and headers):
            formatted = formatter.format_output(
                cur, headers, format_name='vertical', column_types=None, **output_kwargs)
            if isinstance(formatted, (text_type)):
                formatted = iter(formatted.splitlines())

        output = itertools.chain(output, formatted)

    if status:  # Only print the status if it's not None.
        output = itertools.chain(output, [status])

    return output
github dbcli / pgcli / pgcli / main.py View on Github external
for d in cur.description:
                if (
                    d[1] in psycopg2.extensions.DECIMAL.values
                    or d[1] in psycopg2.extensions.FLOAT.values
                ):
                    column_types.append(float)
                if (
                    d[1] == psycopg2.extensions.INTEGER.values
                    or d[1] in psycopg2.extensions.LONGINTEGER.values
                ):
                    column_types.append(int)
                else:
                    column_types.append(text_type)

        formatted = formatter.format_output(cur, headers, **output_kwargs)
        if isinstance(formatted, (text_type)):
            formatted = iter(formatted.splitlines())
        first_line = next(formatted)
        formatted = itertools.chain([first_line], formatted)
        if not expanded and max_width and len(first_line) > max_width and headers:
            formatted = formatter.format_output(
                cur, headers, format_name="vertical", column_types=None, **output_kwargs
            )
            if isinstance(formatted, (text_type)):
                formatted = iter(formatted.splitlines())

        output = itertools.chain(output, formatted)

    if status:  # Only print the status if it's not None.
        output = itertools.chain(output, [status])

    return output
github dbcli / pgcli / pgcli / main.py View on Github external
if cur:
        headers = [case_function(utf8tounicode(x)) for x in headers]
        if max_width is not None:
            cur = list(cur)
        column_types = None
        if hasattr(cur, 'description'):
            column_types = []
            for d in cur.description:
                if d[1] in psycopg2.extensions.DECIMAL.values or \
                        d[1] in psycopg2.extensions.FLOAT.values:
                    column_types.append(float)
                if d[1] == psycopg2.extensions.INTEGER.values or \
                        d[1] in psycopg2.extensions.LONGINTEGER.values:
                    column_types.append(int)
                else:
                    column_types.append(text_type)
        formatted = formatter.format_output(cur, headers, **output_kwargs)
        if isinstance(formatted, (text_type)):
            formatted = iter(formatted.splitlines())
        first_line = next(formatted)
        formatted = itertools.chain([first_line], formatted)

        if (not expanded and max_width and len(first_line) > max_width and headers):
            formatted = formatter.format_output(
                cur, headers, format_name='vertical', column_types=None, **output_kwargs)
            if isinstance(formatted, (text_type)):
                formatted = iter(formatted.splitlines())

        output = itertools.chain(output, formatted)

    if status:  # Only print the status if it's not None.
        output = itertools.chain(output, [status])