1
0
Fork 0

removed py2-related stuff

This commit is contained in:
Georgy Frolov 2020-03-12 15:01:19 +03:00 committed by 赖信涛
parent 0f3d4602ef
commit 61c81b05f5
38 changed files with 13 additions and 136 deletions

View File

@ -26,12 +26,7 @@ def load_config(usr_cfg, def_cfg=None):
def ensure_dir_exists(path):
parent_dir = expanduser(dirname(path))
try:
os.makedirs(parent_dir)
except OSError as exc:
# ignore existing destination (py2 has no exist_ok arg to makedirs)
if exc.errno != errno.EEXIST:
raise
os.makedirs(parent_dir, exist_ok=True)
def write_default_config(source, destination, overwrite=False):

View File

@ -1,28 +0,0 @@
import sys
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
text_type = unicode if PY2 else str
def unicode2utf8(arg):
"""
Only in Python 2. Psycopg2 expects the args as bytes not unicode.
In Python 3 the args are expected as unicode.
"""
if PY2 and isinstance(arg, unicode):
return arg.encode("utf-8")
return arg
def utf8tounicode(arg):
"""
Only in Python 2. Psycopg2 returns the error message as utf-8.
In Python 3 the errors are returned as unicode.
"""
if PY2 and isinstance(arg, str):
return arg.decode("utf-8")
return arg

View File

@ -1,5 +1,3 @@
from __future__ import unicode_literals
import logging
from prompt_toolkit.enums import EditingMode
from prompt_toolkit.key_binding import KeyBindings

View File

@ -1,6 +1,3 @@
from __future__ import print_function
from __future__ import unicode_literals
import warnings
from pgspecial.namedqueries import NamedQueries
@ -63,8 +60,6 @@ from .config import (
get_config,
)
from .key_bindings import pgcli_bindings
from .encodingutils import utf8tounicode
from .encodingutils import text_type
from .packages.prompt_utils import confirm_destructive_query
from .__init__ import __version__
@ -538,7 +533,7 @@ class PGCli(object):
# fails. Don't prompt if the -w flag is supplied
if self.never_passwd_prompt:
return False
error_msg = utf8tounicode(exc.args[0])
error_msg = exc.args[0]
if "no password supplied" in error_msg:
return True
if "password authentication failed" in error_msg:
@ -1365,7 +1360,7 @@ def is_select(status):
def exception_formatter(e):
return click.style(utf8tounicode(str(e)), fg="red")
return click.style(str(e), fg="red")
def format_output(title, cur, headers, status, settings):
@ -1381,7 +1376,7 @@ def format_output(title, cur, headers, status, settings):
return settings.missingval
if not isinstance(val, list):
return val
return "{" + ",".join(text_type(format_array(e)) for e in val) + "}"
return "{" + ",".join(str(format_array(e)) for e in val) + "}"
def format_arrays(data, headers, **_):
data = list(data)
@ -1411,7 +1406,7 @@ def format_output(title, cur, headers, status, settings):
output.append(title)
if cur:
headers = [case_function(utf8tounicode(x)) for x in headers]
headers = [case_function(x) for x in headers]
if max_width is not None:
cur = list(cur)
column_types = None
@ -1429,10 +1424,10 @@ def format_output(title, cur, headers, status, settings):
):
column_types.append(int)
else:
column_types.append(text_type)
column_types.append(str)
formatted = formatter.format_output(cur, headers, **output_kwargs)
if isinstance(formatted, (text_type)):
if isinstance(formatted, str):
formatted = iter(formatted.splitlines())
first_line = next(formatted)
formatted = itertools.chain([first_line], formatted)
@ -1440,7 +1435,7 @@ def format_output(title, cur, headers, status, settings):
formatted = formatter.format_output(
cur, headers, format_name="vertical", column_types=None, **output_kwargs
)
if isinstance(formatted, (text_type)):
if isinstance(formatted, str):
formatted = iter(formatted.splitlines())
output = itertools.chain(output, formatted)

View File

@ -1,5 +1,3 @@
from __future__ import unicode_literals
from sqlparse import parse
from sqlparse.tokens import Keyword, CTE, DML
from sqlparse.sql import Identifier, IdentifierList, Parenthesis

View File

@ -1,4 +1,3 @@
from __future__ import unicode_literals
from collections import namedtuple
_ColumnMetadata = namedtuple(

View File

@ -1,5 +1,3 @@
from __future__ import print_function, unicode_literals
import sqlparse
from collections import namedtuple
from sqlparse.sql import IdentifierList, Identifier, Function

View File

@ -1,4 +1,3 @@
from __future__ import print_function
import re
import sqlparse
from sqlparse.sql import Identifier

View File

@ -1,5 +1,3 @@
from __future__ import unicode_literals
import re
import sqlparse
from sqlparse.tokens import Name

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import sys
import click
from .parseutils import is_destructive

View File

@ -1,5 +1,3 @@
from __future__ import print_function, unicode_literals
import sys
import re
import sqlparse
@ -10,14 +8,6 @@ from .parseutils.tables import extract_tables
from .parseutils.ctes import isolate_query_ctes
from pgspecial.main import parse_special_command
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
if PY3:
string_types = str
else:
string_types = basestring
Special = namedtuple("Special", [])
Database = namedtuple("Database", [])
@ -301,7 +291,7 @@ def suggest_special(text):
def suggest_based_on_last_token(token, stmt):
if isinstance(token, string_types):
if isinstance(token, str):
token_v = token.lower()
elif isinstance(token, Comparison):
# If 'token' is a Comparison type such as

View File

@ -1,4 +1,3 @@
from __future__ import unicode_literals
import logging
from prompt_toolkit.enums import DEFAULT_BUFFER

View File

@ -1,4 +1,3 @@
from __future__ import print_function, unicode_literals
import logging
import re
from itertools import count, repeat, chain

View File

@ -9,7 +9,6 @@ import pgspecial as special
import select
from psycopg2.extensions import POLL_OK, POLL_READ, POLL_WRITE, make_dsn
from .packages.parseutils.meta import FunctionMetadata, ForeignKey
from .encodingutils import unicode2utf8, PY2, utf8tounicode
_logger = logging.getLogger(__name__)
@ -250,7 +249,7 @@ class PGExecute(object):
new_params["dsn"], password=new_params.pop("password")
)
conn_params.update({k: unicode2utf8(v) for k, v in new_params.items() if v})
conn_params.update({k: v for k, v in new_params.items() if v})
conn = psycopg2.connect(**conn_params)
cursor = conn.cursor()
@ -333,10 +332,7 @@ class PGExecute(object):
See http://initd.org/psycopg/docs/connection.html#connection.encoding
"""
if PY2:
return json_data.decode(self.conn.encoding)
else:
return json_data
return json_data
def failed_transaction(self):
status = self.conn.get_transaction_status()
@ -450,7 +446,7 @@ class PGExecute(object):
# conn.notices persist between queies, we use pop to clear out the list
title = ""
while len(self.conn.notices) > 0:
title = utf8tounicode(self.conn.notices.pop()) + title
title = self.conn.notices.pop() + title
# cur.description will be None for operations that do not return
# rows.

View File

@ -1,5 +1,3 @@
from __future__ import unicode_literals
import logging
import pygments.styles

View File

@ -1,5 +1,3 @@
from __future__ import unicode_literals
from prompt_toolkit.key_binding.vi_state import InputMode
from prompt_toolkit.application import get_app

View File

@ -1,7 +1,6 @@
#!/usr/bin/env python
"""A script to publish a release of pgcli to PyPI."""
from __future__ import print_function
import io
from optparse import OptionParser
import re

View File

@ -1,5 +1,3 @@
from __future__ import print_function
import os
import pytest
from utils import (

View File

@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import print_function
from psycopg2 import connect
from psycopg2.extensions import AsIs

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function
import copy
import os
import sys

View File

@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import print_function
import os
import codecs

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8
from __future__ import unicode_literals, print_function
from textwrap import dedent
from behave import then, when
import wrappers

View File

@ -1,10 +1,8 @@
# -*- coding: utf-8
"""
Steps for behavioral style tests are defined in this module.
Each step is defined by the string decorating it.
This string is used to call the step in "*.feature" file.
"""
from __future__ import unicode_literals, print_function
import pexpect
import subprocess

View File

@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-
"""
Steps for behavioral style tests are defined in this module.
Each step is defined by the string decorating it.
This string is used to call the step in "*.feature" file.
"""
from __future__ import unicode_literals, print_function
import pexpect
from behave import when, then

View File

@ -1,10 +1,8 @@
# -*- coding: utf-8
"""
Steps for behavioral style tests are defined in this module.
Each step is defined by the string decorating it.
This string is used to call the step in "*.feature" file.
"""
from __future__ import unicode_literals, print_function
from behave import when, then
from textwrap import dedent

View File

@ -1,11 +1,9 @@
# -*- coding: utf-8
"""Steps for behavioral style tests are defined in this module.
Each step is defined by the string decorating it. This string is used
to call the step in "*.feature" file.
"""
from __future__ import unicode_literals, print_function
from behave import when, then
from textwrap import dedent

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8
from __future__ import unicode_literals, print_function
import os
import os.path

View File

@ -1,10 +1,8 @@
# -*- coding: utf-8
"""
Steps for behavioral style tests are defined in this module.
Each step is defined by the string decorating it.
This string is used to call the step in "*.feature" file.
"""
from __future__ import unicode_literals, print_function
from behave import when, then
import wrappers

View File

@ -1,10 +1,8 @@
# -*- coding: utf-8
"""
Steps for behavioral style tests are defined in this module.
Each step is defined by the string decorating it.
This string is used to call the step in "*.feature" file.
"""
from __future__ import unicode_literals, print_function
from behave import when, then
import wrappers

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8
from __future__ import unicode_literals
import re
import pexpect
from pgcli.main import COLOR_CODE_REGEX

View File

@ -1,12 +1,9 @@
from __future__ import unicode_literals
from functools import partial
from itertools import product
from pgcli.packages.parseutils.meta import FunctionMetadata, ForeignKey
from prompt_toolkit.completion import Completion
from prompt_toolkit.document import Document
from mock import Mock
from six import iteritems
import pytest
parametrize = pytest.mark.parametrize
@ -78,7 +75,7 @@ class MetaData(object):
def specials(self, pos=0):
return [
Completion(text=k, start_position=pos, display_meta=v.description)
for k, v in iteritems(self.completer.pgspecial.commands)
for k, v in self.completer.pgspecial.commands.items()
]
def columns(self, tbl, parent="public", typ="tables", pos=0):

View File

@ -1,4 +1,3 @@
from __future__ import unicode_literals
import pytest

View File

@ -1,5 +1,3 @@
# coding=utf-8
from __future__ import unicode_literals, print_function
import os
import platform
import mock

View File

@ -1,4 +1,3 @@
from __future__ import unicode_literals
import pytest
from prompt_toolkit.completion import Completion
from prompt_toolkit.document import Document

View File

@ -1,6 +1,3 @@
# coding=UTF-8
from __future__ import print_function
from textwrap import dedent
import psycopg2

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
import click
from pgcli.packages.prompt_utils import confirm_destructive_query

View File

@ -1,5 +1,3 @@
from __future__ import unicode_literals, print_function
import itertools
from metadata import (
MetaData,

View File

@ -1,5 +1,3 @@
from __future__ import unicode_literals, print_function
from metadata import (
MetaData,
alias,