Skip to content

Commit 5b0e8b1

Browse files
committed
chore: removed python2 libraries support and updated pg8000 lib
1 parent 60dd239 commit 5b0e8b1

File tree

13 files changed

+714
-1573
lines changed

13 files changed

+714
-1573
lines changed

mamonsu/lib/config.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
from mamonsu.plugins.pgsql.driver.checks import is_conn_to_db
1111
from mamonsu.lib.default_config import DefaultConfig
1212

13-
if platform.PY2:
14-
import ConfigParser as configparser
15-
else:
16-
import configparser
13+
14+
import configparser
1715

1816

1917
class Config(DefaultConfig):
@@ -76,7 +74,7 @@ def __init__(self, cfg_file=None, plugin_directories=None):
7674
sys.exit(1)
7775
else:
7876
if cfg_file is not None:
79-
self.config.readfp(open(cfg_file))
77+
self.config.read_file(open(cfg_file))
8078

8179
plugins = self.fetch('plugins', 'directory', str)
8280
if plugins is not None:

mamonsu/lib/const.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from collections import namedtuple
22

33
from mamonsu import __version__
4-
import mamonsu.lib.platform as platform
54

65

76
class _template(object):
@@ -27,20 +26,11 @@ class _template(object):
2726

2827
class _api(object):
2928

30-
if platform.PY2:
31-
UNKNOWN_VERSION = 'UNKNOWN_API_VERSION\n'
32-
else:
33-
UNKNOWN_VERSION = b'UNKNOWN_API_VERSION\n'
29+
UNKNOWN_VERSION = b'UNKNOWN_API_VERSION\n'
3430

35-
if platform.PY2:
36-
METRIC_NOT_FOUND = 'METRIC_NOT_FOUND\n'
37-
else:
38-
METRIC_NOT_FOUND = b'METRIC_NOT_FOUND\n'
31+
METRIC_NOT_FOUND = b'METRIC_NOT_FOUND\n'
3932

40-
if platform.PY2:
41-
VERSION = '{0}'.format(__version__)
42-
else:
43-
VERSION = bytearray('{0}'.format(__version__), 'utf-8')
33+
VERSION = bytearray('{0}'.format(__version__), 'utf-8')
4434

4535
METRIC_LIST_URLS = ['/list', '/list/']
4636
METRIC_GET_URLS = ['/get', '/get/']

mamonsu/lib/platform.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,4 @@
44
WINDOWS = (sys.platform == 'win32' or sys.platform == 'win64')
55
FREEBSD = ('freebsd' in sys.platform)
66
UNIX = LINUX or FREEBSD
7-
8-
PY2 = (sys.version_info[0] == 2)
9-
PY3 = (sys.version_info[0] == 3)
10-
11-
if PY2:
12-
INTEGER_TYPES = (int, long)
13-
if PY3:
14-
INTEGER_TYPES = int,
7+
INTEGER_TYPES = int,

mamonsu/plugins/pgsql/driver/pg8000/__init__.py

100644100755
Lines changed: 31 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
from .core import (
2-
Warning, Bytea, DataError, DatabaseError, InterfaceError, ProgrammingError,
1+
from pg8000.core import (
2+
Warning, DataError, DatabaseError, InterfaceError, ProgrammingError,
33
Error, OperationalError, IntegrityError, InternalError, NotSupportedError,
4-
ArrayContentNotHomogenousError, ArrayContentEmptyError,
5-
ArrayDimensionsNotConsistentError, ArrayContentNotSupportedError, utc,
6-
Connection, Cursor, Binary, Date, DateFromTicks, Time, TimeFromTicks,
7-
Timestamp, TimestampFromTicks, BINARY, Interval)
4+
ArrayContentNotHomogenousError, ArrayDimensionsNotConsistentError,
5+
ArrayContentNotSupportedError, Connection, Cursor, Binary, Date,
6+
DateFromTicks, Time, TimeFromTicks, Timestamp, TimestampFromTicks, BINARY,
7+
Interval, PGEnum, PGJson, PGJsonb, PGTsvector, PGText, PGVarchar)
8+
from ._version import get_versions
9+
__version__ = get_versions()['version']
10+
del get_versions
811

912
# Copyright (c) 2007-2009, Mathieu Fenniak
13+
# Copyright (c) The Contributors
1014
# All rights reserved.
1115
#
1216
# Redistribution and use in source and binary forms, with or without
@@ -37,69 +41,19 @@
3741

3842

3943
def connect(
40-
user=None, host='localhost', unix_sock=None, port=5432, database=None,
41-
password=None, ssl=False, timeout=None,
42-
application_name=None, **kwargs):
43-
"""Creates a connection to a PostgreSQL database.
44-
45-
This function is part of the `DBAPI 2.0 specification
46-
<http://www.python.org/dev/peps/pep-0249/>`_; however, the arguments of the
47-
function are not defined by the specification.
48-
49-
:param user:
50-
The username to connect to the PostgreSQL server with. If this is not
51-
provided, pg8000 looks first for the PGUSER then the USER environment
52-
variables.
53-
54-
If your server character encoding is not ``ascii`` or ``utf8``, then
55-
you need to provide ``user`` as bytes, eg.
56-
``"my_name".encode('EUC-JP')``.
57-
58-
:keyword host:
59-
The hostname of the PostgreSQL server to connect with. Providing this
60-
parameter is necessary for TCP/IP connections. One of either ``host``
61-
or ``unix_sock`` must be provided. The default is ``localhost``.
62-
63-
:keyword unix_sock:
64-
The path to the UNIX socket to access the database through, for
65-
example, ``'/tmp/.s.PGSQL.5432'``. One of either ``host`` or
66-
``unix_sock`` must be provided.
67-
68-
:keyword port:
69-
The TCP/IP port of the PostgreSQL server instance. This parameter
70-
defaults to ``5432``, the registered common port of PostgreSQL TCP/IP
71-
servers.
72-
73-
:keyword database:
74-
The name of the database instance to connect with. This parameter is
75-
optional; if omitted, the PostgreSQL server will assume the database
76-
name is the same as the username.
77-
78-
If your server character encoding is not ``ascii`` or ``utf8``, then
79-
you need to provide ``database`` as bytes, eg.
80-
``"my_db".encode('EUC-JP')``.
81-
82-
:keyword password:
83-
The user password to connect to the server with. This parameter is
84-
optional; if omitted and the database server requests password-based
85-
authentication, the connection will fail to open. If this parameter
86-
is provided but not requested by the server, no error will occur.
87-
88-
:keyword ssl:
89-
Use SSL encryption for TCP/IP sockets if ``True``. Defaults to
90-
``False``.
91-
92-
:keyword timeout:
93-
Only used with Python 3, this is the time in seconds before the
94-
connection to the database will time out. The default is ``None`` which
95-
means no timeout.
96-
97-
:rtype:
98-
A :class:`Connection` object.
99-
"""
44+
user, host='localhost', database=None, port=5432, password=None,
45+
source_address=None, unix_sock=None, ssl_context=None, timeout=None,
46+
max_prepared_statements=1000, tcp_keepalive=True,
47+
application_name=None, replication=None):
48+
10049
return Connection(
101-
user, host, unix_sock, port, database,
102-
password, ssl, timeout, application_name)
50+
user, host=host, database=database, port=port, password=password,
51+
source_address=source_address, unix_sock=unix_sock,
52+
ssl_context=ssl_context, timeout=timeout,
53+
max_prepared_statements=max_prepared_statements,
54+
tcp_keepalive=tcp_keepalive, application_name=application_name,
55+
replication=replication)
56+
10357

10458
apilevel = "2.0"
10559
"""The DBAPI level supported, currently "2.0".
@@ -108,37 +62,17 @@ def connect(
10862
<http://www.python.org/dev/peps/pep-0249/>`_.
10963
"""
11064

111-
threadsafety = 3
65+
threadsafety = 1
11266
"""Integer constant stating the level of thread safety the DBAPI interface
113-
supports. This DBAPI module supports sharing the module, connections, and
114-
cursors, resulting in a threadsafety value of 3.
67+
supports. This DBAPI module supports sharing of the module only. Connections
68+
and cursors my not be shared between threads. This gives pg8000 a threadsafety
69+
value of 1.
11570
11671
This property is part of the `DBAPI 2.0 specification
11772
<http://www.python.org/dev/peps/pep-0249/>`_.
11873
"""
11974

12075
paramstyle = 'format'
121-
"""String property stating the type of parameter marker formatting expected by
122-
the interface. This value defaults to "format", in which parameters are
123-
marked in this format: "WHERE name=%s".
124-
125-
This property is part of the `DBAPI 2.0 specification
126-
<http://www.python.org/dev/peps/pep-0249/>`_.
127-
128-
As an extension to the DBAPI specification, this value is not constant; it
129-
can be changed to any of the following values:
130-
131-
qmark
132-
Question mark style, eg. ``WHERE name=?``
133-
numeric
134-
Numeric positional style, eg. ``WHERE name=:1``
135-
named
136-
Named style, eg. ``WHERE name=:paramname``
137-
format
138-
printf format codes, eg. ``WHERE name=%s``
139-
pyformat
140-
Python format codes, eg. ``WHERE name=%(paramname)s``
141-
"""
14276

14377
# I have no idea what this would be used for by a client app. Should it be
14478
# TEXT, VARCHAR, CHAR? It will only compare against row_description's
@@ -159,12 +93,13 @@ def connect(
15993
"""ROWID type oid"""
16094

16195
__all__ = [
162-
Warning, Bytea, DataError, DatabaseError, connect, InterfaceError,
96+
Warning, DataError, DatabaseError, connect, InterfaceError,
16397
ProgrammingError, Error, OperationalError, IntegrityError, InternalError,
164-
NotSupportedError, ArrayContentNotHomogenousError, ArrayContentEmptyError,
165-
ArrayDimensionsNotConsistentError, ArrayContentNotSupportedError, utc,
98+
NotSupportedError, ArrayContentNotHomogenousError,
99+
ArrayDimensionsNotConsistentError, ArrayContentNotSupportedError,
166100
Connection, Cursor, Binary, Date, DateFromTicks, Time, TimeFromTicks,
167-
Timestamp, TimestampFromTicks, BINARY, Interval]
101+
Timestamp, TimestampFromTicks, BINARY, Interval, PGEnum, PGJson, PGJsonb,
102+
PGTsvector, PGText, PGVarchar]
168103

169104
"""Version string for pg8000.
170105
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
# This file was generated by 'versioneer.py' (0.15) from
3+
# revision-control system data, or from the parent directory name of an
4+
# unpacked source archive. Distribution tarballs contain a pre-generated copy
5+
# of this file.
6+
7+
import json
8+
import sys
9+
10+
version_json = '''
11+
{
12+
"dirty": false,
13+
"error": null,
14+
"full-revisionid": "91062e7d4a05b76ab38b8146427a54987d6d1269",
15+
"version": "1.15.3"
16+
}
17+
''' # END VERSION_JSON
18+
19+
20+
def get_versions():
21+
return json.loads(version_json)

0 commit comments

Comments
 (0)