Remove Python2 references from the source code.

refs #5443

Initial patch: Neel Patel
This commit is contained in:
Akshay Joshi 2020-04-30 17:22:48 +05:30
parent 7dd00a1494
commit ad80217593
48 changed files with 143 additions and 537 deletions

View File

@ -1,11 +1,7 @@
import os
import sys
import inspect
if sys.version_info[0] >= 3:
import builtins
else:
import __builtin__ as builtins
import builtins
# Ensure the global server mode is set.
builtins.SERVER_MODE = None

View File

@ -14,11 +14,7 @@
import os
import sys
if sys.version_info[0] >= 3:
import builtins
else:
import __builtin__ as builtins
import builtins
# Ensure the global server mode is set.
builtins.SERVER_MODE = None

View File

@ -4,7 +4,7 @@
To generate a pgAdmin 4 installer for Windows bit, the following packages must be installed:
1. Python installation
- Python 2.7 or 3.4+ or above from https://www.python.org/
- Python 3.4+ or above from https://www.python.org/
2. QT installation
- Qt 4.6 through 5.5 from http://www.qt.io/
@ -21,8 +21,8 @@ Building: Depending upon the archicture of the OS(x86|amd64) set then environmen
1. Set the PYTHON environment variable to the Python root installation directory, e.g. for x86
SET "PYTHON_HOME=C:\Python27"
SET "PYTHON_DLL=C:\Windows\System32\python27.dll"
SET "PYTHON_HOME=C:\Python38"
SET "PYTHON_DLL=C:\Windows\System32\python38.dll"
2. Set the QTDIR environment variable to the QT root installation directory, e.g. for x86

View File

@ -52,10 +52,7 @@ def get_python_deps():
"/../requirements.txt")
with open(req_file, 'r') as req_file_p:
if sys.version_info[0] >= 3:
required = req_file_p.read().splitlines()
else:
required = req_file_p.read().decode("utf-8").splitlines()
required = req_file_p.read().splitlines()
# Get the package info from the requirements file
requirements = pkg_resources.parse_requirements(required)

View File

@ -9,16 +9,12 @@
import os
import sys
import builtins
root = os.path.dirname(os.path.realpath(__file__))
if sys.path[0] != root:
sys.path.insert(0, root)
if sys.version_info[0] >= 3:
import builtins
else:
import __builtin__ as builtins
# Ensure the global server mode is set.
builtins.SERVER_MODE = True

View File

@ -43,12 +43,9 @@ from pgadmin import authenticate
# If script is running under python3, it will not have the xrange function
# defined
winreg = None
if sys.version_info[0] >= 3:
xrange = range
if os.name == 'nt':
import winreg
elif os.name == 'nt':
import _winreg as winreg
xrange = range
if os.name == 'nt':
import winreg
class PgAdmin(Flask):

View File

@ -21,10 +21,6 @@ from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class CastModule(CollectionNodeModule):
@ -424,7 +420,7 @@ class CastView(PGChildNodeView):
try:
sql, name = self.get_sql(gid, sid, did, data, cid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
status, res = self.conn.execute_scalar(sql)
if not status:
@ -521,7 +517,7 @@ class CastView(PGChildNodeView):
data = request.args
sql, name = self.get_sql(gid, sid, did, data, cid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':

View File

@ -20,10 +20,6 @@ from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class EventTriggerModule(CollectionNodeModule):
@ -446,7 +442,7 @@ class EventTriggerView(PGChildNodeView):
try:
sql = self.get_sql(data, etid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
if sql != "":
@ -573,7 +569,7 @@ class EventTriggerView(PGChildNodeView):
try:
sql = self.get_sql(data, etid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
sql = re.sub('\n{2,}', '\n\n', sql)

View File

@ -22,27 +22,6 @@ from pgadmin.utils.ajax import make_json_response, \
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
# As unicode type is not available in python3
# If we check a variable is "isinstance(variable, str)
# it breaks in python 3 as variable type is not string its unicode.
# We assign basestring as str type if it is python3, unicode
# if it is python2.
try:
unicode = unicode
except NameError:
# 'unicode' is undefined, must be Python 3
str = str
unicode = str
bytes = bytes
basestring = (str, bytes)
else:
# 'unicode' exists, must be Python 2
str = str
unicode = unicode
bytes = str
basestring = basestring
class ExtensionModule(CollectionNodeModule):
"""
@ -315,7 +294,7 @@ class ExtensionView(PGChildNodeView):
try:
SQL, name = self.getSQL(gid, sid, data, did, eid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_dict(SQL)
@ -393,7 +372,7 @@ class ExtensionView(PGChildNodeView):
try:
SQL, name = self.getSQL(gid, sid, data, did, eid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
if SQL == '':

View File

@ -23,10 +23,6 @@ from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class ForeignDataWrapperModule(CollectionNodeModule):
@ -467,7 +463,7 @@ class ForeignDataWrapperView(PGChildNodeView):
try:
sql, name = self.get_sql(gid, sid, data, did, fid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
status, res = self.conn.execute_scalar(sql)
if not status:
@ -575,7 +571,7 @@ class ForeignDataWrapperView(PGChildNodeView):
try:
sql, name = self.get_sql(gid, sid, data, did, fid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
if sql == '':
sql = "--modified SQL"

View File

@ -23,10 +23,6 @@ from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class ForeignServerModule(CollectionNodeModule):
@ -466,7 +462,7 @@ class ForeignServerView(PGChildNodeView):
try:
sql, name = self.get_sql(gid, sid, data, did, fid, fsid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
@ -579,7 +575,7 @@ class ForeignServerView(PGChildNodeView):
try:
sql, name = self.get_sql(gid, sid, data, did, fid, fsid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
if sql == '':
sql = "--modified SQL"

View File

@ -23,10 +23,6 @@ from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class UserMappingModule(CollectionNodeModule):
@ -473,7 +469,7 @@ class UserMappingView(PGChildNodeView):
try:
sql, name = self.get_sql(gid, sid, data, did, fid, fsid, umid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
@ -599,7 +595,7 @@ class UserMappingView(PGChildNodeView):
try:
sql, name = self.get_sql(gid, sid, data, did, fid, fsid, umid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
if sql == '':
sql = "--modified SQL"

View File

@ -23,10 +23,6 @@ from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class LanguageModule(CollectionNodeModule):
@ -420,7 +416,7 @@ class LanguageView(PGChildNodeView):
try:
sql, name = self.get_sql(data, lid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_dict(sql)
@ -577,7 +573,7 @@ class LanguageView(PGChildNodeView):
try:
sql, name = self.get_sql(data, lid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
if sql == '':
sql = "--modified SQL"

View File

@ -20,7 +20,6 @@ from config import PG_DEFAULT_DRIVER
from pgadmin.browser.server_groups.servers.databases.schemas.utils \
import SchemaChildModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils import IS_PY2
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.compile_template_name import compile_template_path
@ -28,10 +27,6 @@ from pgadmin.utils.driver import get_driver
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
# If we are in Python3
if not IS_PY2:
unicode = str
class CollationModule(SchemaChildModule):
"""
@ -597,7 +592,7 @@ class CollationView(PGChildNodeView, SchemaDiffObjectCompare):
)
SQL, name = self.get_sql(gid, sid, data, scid, coid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
@ -651,7 +646,7 @@ class CollationView(PGChildNodeView, SchemaDiffObjectCompare):
try:
SQL, name = self.get_sql(gid, sid, data, scid, coid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
if SQL == '':
SQL = "--modified SQL"

View File

@ -22,7 +22,6 @@ from pgadmin.browser.server_groups.servers.databases.schemas.utils import \
from pgadmin.browser.server_groups.servers.databases.utils import \
parse_sec_labels_from_db
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils import IS_PY2
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.compile_template_name import compile_template_path
@ -30,10 +29,6 @@ from pgadmin.utils.driver import get_driver
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
# If we are in Python3
if not IS_PY2:
unicode = str
class DomainModule(SchemaChildModule):
"""
@ -554,7 +549,7 @@ AND relkind != 'c'))"""
data = self.request
SQL, name = self.get_sql(gid, sid, data, scid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
status, res = self.conn.execute_scalar(SQL)
@ -670,7 +665,7 @@ AND relkind != 'c'))"""
SQL, name = self.get_sql(gid, sid, self.request, scid, doid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
status, res = self.conn.execute_scalar(SQL)
@ -784,7 +779,7 @@ AND relkind != 'c'))"""
try:
SQL, name = self.get_sql(gid, sid, self.request, scid, doid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
if SQL == '':
SQL = "--modified SQL"

View File

@ -27,7 +27,6 @@ from pgadmin.browser.server_groups.servers.databases.utils import \
from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
parse_priv_to_db
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils import IS_PY2
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.compile_template_name import compile_template_path
@ -35,10 +34,6 @@ from pgadmin.utils.driver import get_driver
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
# If we are in Python3
if not IS_PY2:
unicode = str
class ForeignTableModule(SchemaChildModule):
"""
@ -670,7 +665,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader,
# Get SQL to create Foreign Table
SQL, name = self.get_sql(gid, sid, did, scid, self.request)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
status, res = self.conn.execute_scalar(SQL)
@ -791,7 +786,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader,
try:
SQL, name = self.get_sql(gid, sid, did, scid, self.request, foid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
@ -892,7 +887,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader,
try:
SQL, name = self.get_sql(gid, sid, did, scid, self.request, foid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
if SQL == '':

View File

@ -20,17 +20,12 @@ from config import PG_DEFAULT_DRIVER
from pgadmin.browser.server_groups.servers.databases.schemas.utils \
import SchemaChildModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils import IS_PY2
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
# If we are in Python3
if not IS_PY2:
unicode = str
class FtsConfigurationModule(SchemaChildModule):
"""
@ -506,7 +501,7 @@ class FtsConfigurationView(PGChildNodeView, SchemaDiffObjectCompare):
# Fetch sql query to update fts Configuration
sql, name = self.get_sql(gid, sid, did, scid, data, cfgid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
@ -637,7 +632,7 @@ class FtsConfigurationView(PGChildNodeView, SchemaDiffObjectCompare):
# Fetch sql query for modified data
SQL, name = self.get_sql(gid, sid, did, scid, data, cfgid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
if SQL == '':

View File

@ -20,17 +20,12 @@ from config import PG_DEFAULT_DRIVER
from pgadmin.browser.server_groups.servers.databases.schemas.utils \
import SchemaChildModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils import IS_PY2
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
# If we are in Python3
if not IS_PY2:
unicode = str
class FtsDictionaryModule(SchemaChildModule):
"""
@ -503,7 +498,7 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
# Fetch sql query to update fts dictionary
sql, name = self.get_sql(gid, sid, did, scid, data, dcid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
@ -634,7 +629,7 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
# Fetch sql query for modified data
SQL, name = self.get_sql(gid, sid, did, scid, data, dcid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
if SQL == '':

View File

@ -20,17 +20,12 @@ from pgadmin.browser.server_groups.servers.databases import DatabaseModule
from pgadmin.browser.server_groups.servers.databases.schemas.utils import \
SchemaChildModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils import IS_PY2
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
# If we are in Python3
if not IS_PY2:
unicode = str
class FtsParserModule(SchemaChildModule):
"""
@ -448,7 +443,7 @@ class FtsParserView(PGChildNodeView, SchemaDiffObjectCompare):
# Fetch sql query to update fts parser
sql, name = self.get_sql(gid, sid, did, scid, data, pid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
@ -580,7 +575,7 @@ class FtsParserView(PGChildNodeView, SchemaDiffObjectCompare):
# Fetch sql query for modified data
SQL, name = self.get_sql(gid, sid, did, scid, data, pid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
if SQL == '':
SQL = "--modified SQL"

View File

@ -20,17 +20,12 @@ from pgadmin.browser.server_groups.servers.databases import DatabaseModule
from pgadmin.browser.server_groups.servers.databases.schemas.utils import \
SchemaChildModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils import IS_PY2
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
# If we are in Python3
if not IS_PY2:
unicode = str
class FtsTemplateModule(SchemaChildModule):
"""
@ -421,7 +416,7 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
# Fetch sql query to update fts template
sql, name = self.get_sql(gid, sid, did, scid, data, tid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
@ -539,7 +534,7 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
# Fetch sql query for modified data
SQL, name = self.get_sql(gid, sid, did, scid, data, tid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
if SQL == '':

View File

@ -22,7 +22,6 @@ from pgadmin.browser.server_groups.servers.databases.schemas.utils \
from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
parse_priv_to_db
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils import IS_PY2
from pgadmin.utils.ajax import make_json_response, \
make_response as ajax_response, internal_server_error, \
precondition_required, gone
@ -30,10 +29,6 @@ from pgadmin.utils.driver import get_driver
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
# If we are in Python3
if not IS_PY2:
unicode = str
class PackageModule(SchemaChildModule):
"""
@ -510,7 +505,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
SQL, name = self.getSQL(gid, sid, did, data, scid, pkgid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
@ -565,7 +560,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
SQL, name = self.getSQL(gid, sid, did, data, scid, pkgid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
@ -714,7 +709,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
sql, name = self.getSQL(gid, sid, did, result, scid, pkgid, True,
diff_schema)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')

View File

@ -23,14 +23,9 @@ from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
# If we are in Python3
if not IS_PY2:
unicode = str
class SequenceModule(SchemaChildModule):
"""
@ -533,7 +528,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
)
SQL, name = self.getSQL(gid, sid, did, data, scid, seid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
@ -602,7 +597,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
)
SQL, name = self.getSQL(gid, sid, did, data, scid, seid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
@ -737,7 +732,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
result = self._formatter(result, scid, seid)
SQL, name = self.getSQL(gid, sid, did, result, scid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')

View File

@ -23,14 +23,9 @@ from pgadmin.utils.ajax import make_json_response, \
from pgadmin.utils.ajax import precondition_required
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
# If we are in Python3
if not IS_PY2:
unicode = str
class SynonymModule(SchemaChildModule):
"""
@ -568,7 +563,7 @@ class SynonymView(PGChildNodeView, SchemaDiffObjectCompare):
)
SQL, name = self.get_sql(gid, sid, data, scid, syid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
try:
if SQL and SQL.strip('\n') and SQL.strip(' '):
@ -610,7 +605,7 @@ class SynonymView(PGChildNodeView, SchemaDiffObjectCompare):
try:
SQL, name = self.get_sql(gid, sid, data, scid, syid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
if SQL and SQL.strip('\n') and SQL.strip(' '):
return make_json_response(

View File

@ -27,13 +27,8 @@ from pgadmin.browser.server_groups.servers.databases.schemas.tables.\
columns import utils as column_utils
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
from pgadmin.utils.ajax import ColParamsJSONDecoder
# If we are in Python3
if not IS_PY2:
unicode = str
class ColumnsModule(CollectionNodeModule):
"""
@ -530,7 +525,7 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
column_utils.type_formatter(data['cltype'])
SQL, name = self.get_sql(scid, tid, clid, data)
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
@ -574,7 +569,7 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
try:
SQL, name = self.get_sql(scid, tid, clid, data)
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
@ -723,7 +718,7 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
data, [])
SQL, name = self.get_sql(scid, tid, None, data, is_sql=True)
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
sql_header = u"-- Column: {0}\n\n-- ".format(

View File

@ -25,7 +25,6 @@ from pgadmin.browser.server_groups.servers.databases.schemas.utils \
import trigger_definition
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
from pgadmin.utils.compile_template_name import compile_template_path
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
@ -33,11 +32,6 @@ from pgadmin.tools.schema_diff.directory_compare import directory_diff,\
parse_acl
# If we are in Python3
if not IS_PY2:
unicode = str
class CompoundTriggerModule(CollectionNodeModule):
"""
class CompoundTriggerModule(CollectionNodeModule)
@ -645,7 +639,7 @@ class CompoundTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
SQL, name = compound_trigger_utils.get_sql(
self.conn, data, tid, trid, self.datlastsysoid)
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
@ -725,7 +719,7 @@ class CompoundTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
try:
sql, name = compound_trigger_utils.get_sql(
self.conn, data, tid, trid, self.datlastsysoid)
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
@ -885,7 +879,7 @@ class CompoundTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
data,
tid, oid,
self.datlastsysoid)
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
else:

View File

@ -24,10 +24,6 @@ from pgadmin.browser.server_groups.servers.databases.schemas.tables.\
constraints.exclusion_constraint import utils as exclusion_utils
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class ExclusionConstraintModule(ConstraintTypeModule):
@ -608,7 +604,7 @@ class ExclusionConstraintView(PGChildNodeView):
data['table'] = self.table
sql, name = \
exclusion_utils.get_sql(self.conn, data, did, tid, exid)
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
@ -740,7 +736,7 @@ class ExclusionConstraintView(PGChildNodeView):
try:
sql, name = \
exclusion_utils.get_sql(self.conn, data, did, tid, exid)
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':

View File

@ -24,11 +24,6 @@ from pgadmin.browser.server_groups.servers.databases.schemas.tables.\
constraints.foreign_key import utils as fkey_utils
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
FOREIGN_KEY_NOT_FOUND = gettext("Could not find the foreign key.")
@ -650,7 +645,7 @@ class ForeignKeyConstraintView(PGChildNodeView):
data['schema'] = self.schema
data['table'] = self.table
sql, name = fkey_utils.get_sql(self.conn, data, tid, fkid)
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
@ -786,7 +781,7 @@ class ForeignKeyConstraintView(PGChildNodeView):
data['table'] = self.table
try:
sql, name = fkey_utils.get_sql(self.conn, data, tid, fkid)
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':

View File

@ -24,10 +24,6 @@ from pgadmin.browser.server_groups.servers.databases.schemas.tables.\
constraints.index_constraint import utils as idxcons_utils
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class IndexConstraintModule(ConstraintTypeModule):
@ -651,7 +647,7 @@ class IndexConstraintView(PGChildNodeView):
data['table'] = self.table
sql, name = idxcons_utils.get_sql(self.conn, data, did, tid,
self.constraint_type, cid)
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
@ -792,7 +788,7 @@ class IndexConstraintView(PGChildNodeView):
try:
sql, name = idxcons_utils.get_sql(self.conn, data, did, tid,
self.constraint_type, cid)
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':

View File

@ -14,10 +14,6 @@ from flask_babelex import gettext as _
from pgadmin.utils.ajax import internal_server_error
from pgadmin.utils.exception import ObjectGone
from functools import wraps
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
def get_template_path(f):
@ -218,7 +214,7 @@ def get_sql(conn, data, did, tid, ctype, cid=None, template_path=None):
]
def is_key_str(key, data):
return isinstance(data[key], (str, unicode)) and data[key] != ""
return isinstance(data[key], str) and data[key] != ""
def is_key_list(key, data):
return isinstance(data[key], list) and len(data[param]) > 0

View File

@ -24,17 +24,12 @@ from pgadmin.utils.ajax import make_json_response, internal_server_error, \
from pgadmin.utils.compile_template_name import compile_template_path
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.directory_compare import directory_diff
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
from pgadmin.browser.server_groups.servers.databases.schemas. \
tables.indexes import utils as index_utils
# If we are in Python3
if not IS_PY2:
unicode = str
class IndexesModule(CollectionNodeModule):
"""
@ -741,7 +736,7 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare):
try:
SQL, name = index_utils.get_sql(
self.conn, data, did, tid, idx, self.datlastsysoid)
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
@ -792,7 +787,7 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare):
sql, name = index_utils.get_sql(
self.conn, data, did, tid, idx, self.datlastsysoid,
mode='create')
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':

View File

@ -25,16 +25,11 @@ from pgadmin.utils.ajax import make_json_response, internal_server_error, \
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.compile_template_name import compile_template_path
from pgadmin.utils import IS_PY2
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
from pgadmin.tools.schema_diff.directory_compare import directory_diff,\
parse_acl
# If we are in Python3
if not IS_PY2:
unicode = str
class RuleModule(CollectionNodeModule):
"""
@ -379,7 +374,7 @@ class RuleView(PGChildNodeView, SchemaDiffObjectCompare):
)
try:
SQL, name = self.getSQL(gid, sid, data, tid, rid)
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
@ -461,7 +456,7 @@ class RuleView(PGChildNodeView, SchemaDiffObjectCompare):
"""
data = request.args
sql, name = self.getSQL(gid, sid, data, tid, rid)
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')

View File

@ -26,16 +26,11 @@ from pgadmin.browser.server_groups.servers.databases.schemas.utils \
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.compile_template_name import compile_template_path
from pgadmin.utils import IS_PY2
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
from pgadmin.tools.schema_diff.directory_compare import directory_diff,\
parse_acl
# If we are in Python3
if not IS_PY2:
unicode = str
class TriggerModule(CollectionNodeModule):
"""
@ -675,7 +670,7 @@ class TriggerView(PGChildNodeView, SchemaDiffObjectCompare):
self.conn, data, tid, trid, self.datlastsysoid,
self.blueprint.show_system_objects)
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
@ -756,7 +751,7 @@ class TriggerView(PGChildNodeView, SchemaDiffObjectCompare):
sql, name = trigger_utils.get_sql(
self.conn, data, tid, trid, self.datlastsysoid,
self.blueprint.show_system_objects)
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
@ -798,7 +793,7 @@ class TriggerView(PGChildNodeView, SchemaDiffObjectCompare):
self.datlastsysoid,
self.blueprint.show_system_objects, True)
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
else:

View File

@ -25,7 +25,6 @@ from pgadmin.browser.server_groups.servers.databases.schemas.utils \
from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
parse_priv_to_db
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils import IS_PY2
from pgadmin.utils.compile_template_name import compile_template_path
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
@ -753,14 +752,9 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
Returns:
Updated data dict
"""
# For Python2, it can be int, long, float
if IS_PY2 and hasattr(str, 'decode'):
if isinstance(data['name'], (int, long, float)):
data['name'] = str(data['name'])
else:
# For Python3, it can be int, float
if isinstance(data['name'], (int, float)):
data['name'] = str(data['name'])
if isinstance(data['name'], (int, float)):
data['name'] = str(data['name'])
return data
def get_sql(self, did, scid, tid, data, res):

View File

@ -22,17 +22,12 @@ from pgadmin.browser.server_groups.servers.databases.schemas.utils \
from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
parse_priv_to_db
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils import IS_PY2
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
# If we are in Python3
if not IS_PY2:
unicode = str
class TypeModule(SchemaChildModule):
"""
@ -1046,7 +1041,7 @@ class TypeView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
try:
SQL, name = self.get_sql(gid, sid, data, scid, tid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
@ -1177,7 +1172,7 @@ class TypeView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
try:
sql, name = self.get_sql(gid, sid, data, scid, tid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')
@ -1414,7 +1409,7 @@ class TypeView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
SQL, name = self.get_sql(gid, sid, data, scid, tid=None, is_sql=True)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
# We are appending headers here for sql panel
sql_header = u"-- Type: {0}\n\n-- ".format(data['name'])

View File

@ -22,10 +22,6 @@ from pgadmin.utils.ajax import make_json_response, \
from pgadmin.utils.ajax import precondition_required
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class ResourceGroupModule(CollectionNodeModule):
@ -563,7 +559,7 @@ class ResourceGroupView(NodeView):
sql, name = self.get_sql(data, rg_id)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')

View File

@ -22,10 +22,6 @@ from pgadmin.utils.ajax import make_json_response, \
from pgadmin.utils.ajax import precondition_required
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class TablespaceModule(CollectionNodeModule):
@ -365,7 +361,7 @@ class TablespaceView(PGChildNodeView):
try:
SQL, name = self.get_sql(gid, sid, data, tsid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
if not isinstance(SQL, str):
return SQL
SQL = SQL.strip('\n').strip(' ')
@ -460,7 +456,7 @@ class TablespaceView(PGChildNodeView):
sql, name = self.get_sql(gid, sid, data, tsid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
if not isinstance(sql, str):
return sql
sql = sql.strip('\n').strip(' ')

View File

@ -40,7 +40,6 @@ from threading import Thread
import signal
_IS_WIN = (os.name == 'nt')
_IS_PY2 = (sys.version_info[0] == 2)
_ZERO = timedelta(0)
_sys_encoding = None
_fs_encoding = None
@ -48,16 +47,12 @@ _u = None
_out_dir = None
_log_file = None
if _IS_PY2:
def _log(msg):
with open(_log_file, 'a') as fp:
fp.write(('INFO:: %s\n' % str(msg)))
else:
def _log(msg):
with open(_log_file, 'a') as fp:
fp.write(
('INFO:: %s\n' % msg.encode('ascii', 'xmlcharrefreplace'))
)
def _log(msg):
with open(_log_file, 'a') as fp:
fp.write(
('INFO:: %s\n' % msg.encode('ascii', 'xmlcharrefreplace'))
)
def unescape_dquotes_process_arg(arg):
@ -193,61 +188,32 @@ class ProcessLogger(Thread):
self.process = process
self.stream = stream
if not _IS_PY2:
def log(self, msg):
"""
This function will update log file
def log(self, msg):
"""
This function will update log file
Args:
msg: message
Args:
msg: message
Returns:
None
"""
# Write into log file
if self.logger:
if msg:
self.logger.write(
get_current_time(
format='%y%m%d%H%M%S%f'
).encode('utf-8')
)
self.logger.write(b',')
self.logger.write(
msg.lstrip(b'\r\n' if _IS_WIN else b'\n')
)
self.logger.write(os.linesep.encode('utf-8'))
Returns:
None
"""
# Write into log file
if self.logger:
if msg:
self.logger.write(
get_current_time(
format='%y%m%d%H%M%S%f'
).encode('utf-8')
)
self.logger.write(b',')
self.logger.write(
msg.lstrip(b'\r\n' if _IS_WIN else b'\n')
)
self.logger.write(os.linesep.encode('utf-8'))
return True
return False
else:
def log(self, msg):
"""
This function will update log file
Args:
msg: message
Returns:
None
"""
# Write into log file
if self.logger:
if msg:
self.logger.write(
b'{0},{1}{2}'.format(
get_current_time(
format='%y%m%d%H%M%S%f'
),
msg.lstrip(
b'\r\n' if _IS_WIN else b'\n'
),
os.linesep
)
)
return True
return False
return True
return False
def run(self):
if self.process and self.stream:
@ -327,11 +293,7 @@ def execute(argv):
kwargs['shell'] = True if _IS_WIN else False
# We need environment variables & values in string
if _IS_PY2:
_log('Converting the environment variable in the bytes format...')
kwargs['env'] = convert_environment_variables(os.environ.copy())
else:
kwargs['env'] = os.environ.copy()
kwargs['env'] = os.environ.copy()
_log('Starting the command execution...')
process = Popen(
@ -454,9 +416,6 @@ if __name__ == '__main__':
_fs_encoding = 'utf-8'
def u(_s, _encoding=_sys_encoding):
if _IS_PY2:
if isinstance(_s, str):
return unicode(_s, _encoding)
return _s
_u = u

View File

@ -21,7 +21,7 @@ from pickle import dumps, loads
from subprocess import Popen, PIPE
import logging
from pgadmin.utils import IS_PY2, u, file_quote, fs_encoding, \
from pgadmin.utils import u, file_quote, fs_encoding, \
get_complete_file_path
import pytz
@ -32,10 +32,7 @@ from flask_security import current_user
import config
from pgadmin.model import Process, db
if IS_PY2:
from StringIO import StringIO
else:
from io import StringIO
from io import StringIO
PROCESS_NOT_STARTED = 0
PROCESS_STARTED = 1
@ -87,15 +84,7 @@ class BatchProcess(object):
_("Could not find a process with the specified ID.")
)
try:
tmp_desc = loads(p.desc.encode('latin-1')) if \
IS_PY2 and hasattr(p.desc, 'encode') else loads(p.desc)
except UnicodeDecodeError:
tmp_desc = loads(p.desc.encode('utf-8')) if \
IS_PY2 and hasattr(p.desc, 'encode') else loads(p.desc)
except Exception as e:
tmp_desc = loads(p.desc.encode('utf-8', 'ignore')) if \
IS_PY2 and hasattr(p.desc, 'encode') else loads(p.desc)
tmp_desc = loads(p.desc)
# ID
self.id = _id
@ -183,33 +172,15 @@ class BatchProcess(object):
csv_writer = csv.writer(
args_csv_io, delimiter=str(','), quoting=csv.QUOTE_MINIMAL
)
if sys.version_info[0] == 2:
csv_writer.writerow(
[
a.encode('utf-8')
if isinstance(a, unicode) else a for a in _args
]
)
else:
csv_writer.writerow(_args)
csv_writer.writerow(_args)
args_val = args_csv_io.getvalue().strip(str('\r\n'))
tmp_desc = dumps(self.desc)
try:
tmp_desc = tmp_desc.decode('utf-8') if \
IS_PY2 and hasattr(tmp_desc, 'decode') else tmp_desc
except UnicodeDecodeError:
tmp_desc = tmp_desc.decode('latin-1') if \
IS_PY2 and hasattr(tmp_desc, 'decode') else tmp_desc
except Exception:
tmp_desc = tmp_desc.decode('utf-8', 'ignore') if \
IS_PY2 and hasattr(tmp_desc, 'decode') else tmp_desc
j = Process(
pid=int(id),
command=_cmd,
arguments=args_val.decode('utf-8', 'replace')
if IS_PY2 and hasattr(args_val, 'decode') else args_val,
arguments=args_val,
logdir=log_dir,
desc=tmp_desc,
user_id=current_user.id
@ -318,24 +289,10 @@ class BatchProcess(object):
]
cmd.extend(self.args)
if os.name == 'nt' and IS_PY2:
command = []
for c in cmd:
command.append(
c.encode('utf-8') if isinstance(c, unicode) else str(c)
)
current_app.logger.info(
u"Executing the process executor with the arguments: %s",
''.join(command)
)
cmd = command
else:
current_app.logger.info(
u"Executing the process executor with the arguments: %s",
str(cmd)
)
current_app.logger.info(
u"Executing the process executor with the arguments: %s",
str(cmd)
)
# Make a copy of environment, and add new variables to support
env = os.environ.copy()
@ -349,10 +306,6 @@ class BatchProcess(object):
if cb is not None:
cb(env)
if IS_PY2:
# We need environment variables & values in string
env = convert_environment_variables(env)
if os.name == 'nt':
DETACHED_PROCESS = 0x00000008
from subprocess import CREATE_NEW_PROCESS_GROUP
@ -602,17 +555,7 @@ class BatchProcess(object):
etime = parser.parse(p.end_time or get_current_time())
execution_time = BatchProcess.total_seconds(etime - stime)
desc = ""
try:
desc = loads(p.desc.encode('latin-1')) if \
IS_PY2 and hasattr(p.desc, 'encode') else loads(p.desc)
except UnicodeDecodeError:
desc = loads(p.desc.encode('utf-8')) if \
IS_PY2 and hasattr(p.desc, 'encode') else loads(p.desc)
except Exception:
desc = loads(p.desc.encode('utf-8', 'ignore')) if \
IS_PY2 and hasattr(p.desc, 'encode') else loads(p.desc)
desc = loads(p.desc)
details = desc
if isinstance(desc, IProcessDesc):

View File

@ -98,9 +98,7 @@ def splitext(path):
def is_folder_hidden(filepath):
if _platform == "win32":
try:
attrs = ctypes.windll.kernel32.GetFileAttributesW(
unicode(filepath) if sys.version_info[0] < 3 else filepath
)
attrs = ctypes.windll.kernel32.GetFileAttributesW(filepath)
assert attrs != -1
result = bool(attrs & 2)
except (AttributeError, AssertionError):

View File

@ -52,11 +52,6 @@ try:
except ImportError:
from urllib.parse import unquote
if sys.version_info[0:2] <= (2, 7):
IS_PY2 = True
else:
IS_PY2 = False
class SqlEditorModule(PgAdminModule):
"""
@ -321,8 +316,7 @@ def extract_sql_from_network_parameters(request_data, request_arguments,
if request_data:
sql_parameters = json.loads(request_data, encoding='utf-8')
if (IS_PY2 and type(sql_parameters) is unicode) \
or type(sql_parameters) is str:
if type(sql_parameters) is str:
return dict(sql=str(sql_parameters), explain_plan=None)
return sql_parameters
else:

View File

@ -1,7 +1,6 @@
from pgadmin.utils.ajax import make_json_response
from pgadmin.model import db, QueryHistoryModel
from config import MAX_QUERY_HIST_STORED
from pgadmin.utils import IS_PY2
class QueryHistory:
@ -15,11 +14,7 @@ class QueryHistory:
QueryHistoryModel.dbname == dbname) \
.all()
# In Python 2.7, rec.query_info has buffer data type. Cast it.
if IS_PY2:
result = [bytes(rec.query_info) for rec in list(result)]
else:
result = [rec.query_info for rec in list(result)]
result = [rec.query_info for rec in list(result)]
return make_json_response(
data={

View File

@ -158,7 +158,6 @@ class PgAdminModule(Blueprint):
return res
IS_PY2 = (sys.version_info[0] == 2)
IS_WIN = (os.name == 'nt')
sys_encoding = sys.getdefaultencoding()
@ -175,16 +174,10 @@ if not fs_encoding or fs_encoding == 'ascii':
def u(_s, _encoding=sys_encoding):
if IS_PY2:
if isinstance(_s, str):
return unicode(_s, _encoding)
return _s
def file_quote(_p):
if IS_PY2:
if isinstance(_p, unicode):
return _p.encode(fs_encoding)
return _p
@ -192,25 +185,10 @@ if IS_WIN:
import ctypes
from ctypes import wintypes
if IS_PY2:
def env(name):
if IS_PY2:
# Make sure string argument is unicode
name = unicode(name)
n = ctypes.windll.kernel32.GetEnvironmentVariableW(name, None, 0)
if n == 0:
return None
buf = ctypes.create_unicode_buffer(u'\0' * n)
ctypes.windll.kernel32.GetEnvironmentVariableW(name, buf, n)
return buf.value
else:
def env(name):
if name in os.environ:
return os.environ[name]
return None
def env(name):
if name in os.environ:
return os.environ[name]
return None
_GetShortPathNameW = ctypes.windll.kernel32.GetShortPathNameW
_GetShortPathNameW.argtypes = [

View File

@ -75,17 +75,10 @@ from csv import (
)
# Stuff needed from six
import sys
PY3 = sys.version_info[0] == 3
if PY3:
string_types = str
text_type = str
binary_type = bytes
unichr = chr
else:
string_types = basestring
text_type = unicode
binary_type = str
string_types = str
text_type = str
binary_type = bytes
unichr = chr
class QuoteStrategy(object):

View File

@ -15,7 +15,6 @@ object.
import random
import select
import sys
import six
import datetime
from collections import deque
@ -39,13 +38,7 @@ from .typecast import register_global_typecasters, \
from .encoding import getEncoding, configureDriverEncodings
from pgadmin.utils import csv
from pgadmin.utils.master_password import get_crypt_key
if sys.version_info < (3,):
from StringIO import StringIO
IS_PY2 = True
else:
from io import StringIO
IS_PY2 = False
from io import StringIO
_ = gettext
@ -692,8 +685,7 @@ WHERE
u"{conn_id} (Query-id: {query_id}):\n{query}".format(
server_id=self.manager.sid,
conn_id=self.conn_id,
query=query.decode(self.python_encoding) if
sys.version_info < (3,) else query,
query=query,
query_id=query_id
)
)
@ -721,33 +713,6 @@ WHERE
return False, \
gettext('The query executed did not return any data.')
def handle_json_data(json_columns, results):
"""
[ This is only for Python2.x]
This function will be useful to handle json data types.
We will dump json data as proper json instead of unicode values
Args:
json_columns: Columns which contains json data
results: Query result
Returns:
results
"""
# Only if Python2 and there are columns with JSON type
if IS_PY2 and len(json_columns) > 0:
temp_results = []
for row in results:
res = dict()
for k, v in row.items():
if k in json_columns:
res[k] = json.dumps(v)
else:
res[k] = v
temp_results.append(res)
results = temp_results
return results
def convert_keys_to_unicode(results, conn_encoding):
"""
[ This is only for Python2.x]
@ -809,15 +774,10 @@ WHERE
for c in cur.ordered_description():
# This is to handle the case in which column name is non-ascii
column_name = c.to_dict()['name']
if IS_PY2:
column_name = column_name.decode(conn_encoding)
header.append(column_name)
if c.to_dict()['type_code'] in ALL_JSON_TYPES:
json_columns.append(column_name)
if IS_PY2:
results = convert_keys_to_unicode(results, conn_encoding)
res_io = StringIO()
if quote == 'strings':
@ -848,7 +808,6 @@ WHERE
)
csv_writer.writeheader()
results = handle_json_data(json_columns, results)
# Replace the null values with given string if configured.
if replace_nulls_with is not None:
results = handle_null_values(results, replace_nulls_with)
@ -872,10 +831,6 @@ WHERE
replace_nulls_with=replace_nulls_with
)
if IS_PY2:
results = convert_keys_to_unicode(results, conn_encoding)
results = handle_json_data(json_columns, results)
# Replace the null values with given string if configured.
if replace_nulls_with is not None:
results = handle_null_values(results, replace_nulls_with)

View File

@ -12,8 +12,6 @@ Typecast various data types so that they can be compatible with Javascript
data types.
"""
import sys
from psycopg2 import STRING as _STRING
import psycopg2
from psycopg2.extensions import encodings
@ -124,10 +122,6 @@ PSYCOPG_SUPPORTED_RANGE_ARRAY_TYPES = (3905, 3927, 3907, 3913, 3909, 3911)
def register_global_typecasters():
if sys.version_info < (3,):
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)
unicode_type_for_record = psycopg2.extensions.new_type(
(2249,),
"RECORD",
@ -186,19 +180,12 @@ def register_string_typecasters(connection):
postgres_encoding, python_encoding, typecast_encoding = \
getEncoding(connection.encoding)
if postgres_encoding != 'UNICODE':
if sys.version_info >= (3,):
def non_ascii_escape(value, cursor):
if value is None:
return None
return bytes(
value, encodings[cursor.connection.encoding]
).decode(typecast_encoding, errors='replace')
else:
def non_ascii_escape(value, cursor):
if value is None:
return None
return value.decode(typecast_encoding, errors='replace')
# return value
def non_ascii_escape(value, cursor):
if value is None:
return None
return bytes(
value, encodings[cursor.connection.encoding]
).decode(typecast_encoding, errors='replace')
unicode_type = psycopg2.extensions.new_type(
# "char", name, text, character, character varying

View File

@ -9,31 +9,20 @@
"""Utilities for HTML"""
from pgadmin.utils import IS_PY2
if IS_PY2:
from cgi import escape as html_escape
else:
from html import escape as html_escape
from html import escape as html_escape
def safe_str(x):
try:
# For Python2, it can be int, long, float
if IS_PY2:
if isinstance(x, (int, long, float)):
x = str(x)
else:
# For Python3, it can be int, float
if isinstance(x, (int, float)):
x = str(x)
# For Python3, it can be int, float
if isinstance(x, (int, float)):
x = str(x)
x = x.encode(
'ascii', 'xmlcharrefreplace'
) if hasattr(x, 'encode') else x
if not IS_PY2:
x = x.decode('utf-8')
x = x.decode('utf-8')
except Exception:
pass
return html_escape(x, False)

View File

@ -9,13 +9,7 @@ from .parseutils.utils import (
from .parseutils.tables import extract_tables
from .parseutils.ctes import isolate_query_ctes
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
if PY3:
string_types = str
else:
string_types = basestring
string_types = str
Special = namedtuple('Special', [])

View File

@ -14,14 +14,10 @@ import argparse
import json
import os
import sys
import builtins
from pgadmin.model import db, User, Version, ServerGroup, Server, \
SCHEMA_VERSION as CURRENT_SCHEMA_VERSION
if sys.version_info[0] >= 3:
import builtins
else:
import __builtin__ as builtins
# Grab the SERVER_MODE if it's been set by the runtime
if 'SERVER_MODE' in globals():
builtins.SERVER_MODE = globals()['SERVER_MODE']