postgresql-access 2.0.1__tar.gz → 2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. {postgresql_access-2.0.1/src/postgresql_access.egg-info → postgresql_access-2.2}/PKG-INFO +1 -1
  2. {postgresql_access-2.0.1 → postgresql_access-2.2}/pyproject.toml +1 -1
  3. {postgresql_access-2.0.1 → postgresql_access-2.2}/src/postgresql_access/database.py +48 -22
  4. {postgresql_access-2.0.1 → postgresql_access-2.2/src/postgresql_access.egg-info}/PKG-INFO +1 -1
  5. {postgresql_access-2.0.1 → postgresql_access-2.2}/src/postgresql_access.egg-info/SOURCES.txt +2 -1
  6. postgresql_access-2.2/src/tests/schematest.py +45 -0
  7. {postgresql_access-2.0.1 → postgresql_access-2.2}/LICENSE +0 -0
  8. {postgresql_access-2.0.1 → postgresql_access-2.2}/README.md +0 -0
  9. {postgresql_access-2.0.1 → postgresql_access-2.2}/setup.cfg +0 -0
  10. {postgresql_access-2.0.1 → postgresql_access-2.2}/src/alchemy/satest.py +0 -0
  11. {postgresql_access-2.0.1 → postgresql_access-2.2}/src/postgresql_access/__init__.py +0 -0
  12. {postgresql_access-2.0.1 → postgresql_access-2.2}/src/postgresql_access/certificatedatabase.py +0 -0
  13. {postgresql_access-2.0.1 → postgresql_access-2.2}/src/postgresql_access/main.py +0 -0
  14. {postgresql_access-2.0.1 → postgresql_access-2.2}/src/postgresql_access.egg-info/dependency_links.txt +0 -0
  15. {postgresql_access-2.0.1 → postgresql_access-2.2}/src/postgresql_access.egg-info/entry_points.txt +0 -0
  16. {postgresql_access-2.0.1 → postgresql_access-2.2}/src/postgresql_access.egg-info/requires.txt +0 -0
  17. {postgresql_access-2.0.1 → postgresql_access-2.2}/src/postgresql_access.egg-info/top_level.txt +0 -0
  18. {postgresql_access-2.0.1 → postgresql_access-2.2}/src/tests/atest.py +0 -0
  19. {postgresql_access-2.0.1 → postgresql_access-2.2}/src/tests/grouptest.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: postgresql_access
3
- Version: 2.0.1
3
+ Version: 2.2
4
4
  Author-email: Gerard <gweatherby@uchc.edu>
5
5
  License: MIT
6
6
  Requires-Python: >=3.8
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "postgresql_access"
3
- version = "2.0.1"
3
+ version = "2.2"
4
4
  dependencies = [
5
5
  "keyring"
6
6
  ]
@@ -6,23 +6,20 @@ import os
6
6
  import pwd
7
7
  from abc import ABC, abstractmethod
8
8
  from typing import Mapping, Any
9
-
10
9
  import keyring
11
10
 
12
11
  # Compatibility layer for psycopg2 and psycopg3
13
12
  try:
14
13
  import psycopg
15
14
  psycopg_module = 'psycopg3'
16
- connect = psycopg.connect
17
- OperationalError = psycopg.OperationalError
18
- readonly = 'read_only'
15
+ _IS_3 = True
19
16
  except ImportError:
20
17
  import psycopg2 as psycopg
21
18
  psycopg_module = 'psycopg2'
22
- connect = psycopg.connect
23
- OperationalError = psycopg.OperationalError
24
- readonly = 'readonly'
19
+ _IS_3 = False
25
20
 
21
+ connect = psycopg.connect
22
+ OperationalError = psycopg.OperationalError
26
23
 
27
24
  class AbstractDatabase(ABC):
28
25
  __DATABASE = 'database'
@@ -79,6 +76,7 @@ class AbstractDatabase(ABC):
79
76
  dbname = database_name or self.database_name()
80
77
  user = self.user()
81
78
  password = self.password()
79
+ sch = schema is schema is not None or self.schema
82
80
 
83
81
  try:
84
82
  conn = connect(**self.build_connection_kwargs(dbname, user, password), **kwargs)
@@ -87,9 +85,9 @@ class AbstractDatabase(ABC):
87
85
  self.connect_fail(dbname, user, password, schema)
88
86
  raise
89
87
 
90
- if schema:
88
+ if sch is not None:
91
89
  with conn.cursor() as cursor:
92
- cursor.execute(f"SET search_path TO {schema}")
90
+ cursor.execute(f"SET search_path TO {sch}")
93
91
  conn.commit()
94
92
 
95
93
  return conn
@@ -162,16 +160,34 @@ class ReadOnlyCursor:
162
160
  self._conn = conn
163
161
  self._factory = cursor_factory
164
162
 
165
- def __enter__(self):
166
- self.existing_readonly = getattr(self._conn,readonly)
167
- setattr(self._conn,readonly, True)
168
- self._curs = self._conn.cursor(cursor_factory=self._factory)
169
- return self._curs
170
-
171
- def __exit__(self, exc_type, exc_val, exc_tb):
172
- self._curs.close()
173
- self._conn.rollback()
174
- setattr(self._conn,readonly, self.existing_readonly)
163
+ if _IS_3:
164
+ def __enter__(self):
165
+ self.existing_readonly = self._conn.read_only
166
+ self._conn.read_only = True
167
+ if self._factory:
168
+ self._curs = self._conn.cursor(row_factory=self._factory)
169
+ else:
170
+ self._curs = self._conn.cursor()
171
+ return self._curs
172
+
173
+ def __exit__(self, exc_type, exc_val, exc_tb):
174
+ self._curs.close()
175
+ self._conn.rollback()
176
+ self._conn.read_only = self.existing_readonly
177
+ else:
178
+ def __enter__(self):
179
+ self.existing_readonly = self._conn.readonly
180
+ self._conn.readonly = True
181
+ if self._factory:
182
+ self._curs = self._conn.cursor(cursor_factory=self._factory)
183
+ else:
184
+ self._curs = self._conn.cursor()
185
+ return self._curs
186
+
187
+ def __exit__(self, exc_type, exc_val, exc_tb):
188
+ self._curs.close()
189
+ self._conn.rollback()
190
+ self._conn.readonly = self.existing_readonly
175
191
 
176
192
  @property
177
193
  def connection(self): return self._conn
@@ -181,9 +197,17 @@ class NewTransactionCursor:
181
197
  self._conn = conn
182
198
  self._factory = cursor_factory
183
199
 
184
- def __enter__(self):
185
- self._conn.rollback()
186
- return self._conn.cursor(cursor_factory=self._factory)
200
+ if _IS_3:
201
+ def __enter__(self):
202
+ self._conn.rollback()
203
+ if self._factory:
204
+ return self._conn.cursor(row_factory=self._factory)
205
+ else:
206
+ return self._conn.cursor()
207
+ else:
208
+ def __enter__(self):
209
+ self._conn.rollback()
210
+ return self._conn.cursor(cursor_factory=self._factory)
187
211
 
188
212
  def __exit__(self, exc_type, exc_val, exc_tb):
189
213
  if exc_type is not None:
@@ -236,3 +260,5 @@ def row_estimate(connection, table: str) -> int:
236
260
  row = curs.fetchone()
237
261
  return int(row[0])
238
262
 
263
+ del _IS_3
264
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: postgresql_access
3
- Version: 2.0.1
3
+ Version: 2.2
4
4
  Author-email: Gerard <gweatherby@uchc.edu>
5
5
  License: MIT
6
6
  Requires-Python: >=3.8
@@ -13,4 +13,5 @@ src/postgresql_access.egg-info/entry_points.txt
13
13
  src/postgresql_access.egg-info/requires.txt
14
14
  src/postgresql_access.egg-info/top_level.txt
15
15
  src/tests/atest.py
16
- src/tests/grouptest.py
16
+ src/tests/grouptest.py
17
+ src/tests/schematest.py
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env python3
2
+ import argparse
3
+ import configparser
4
+ import logging
5
+
6
+ import keyring
7
+ from keyring import backend
8
+
9
+ from postgresql_access import postgresql_access_logger
10
+ from postgresql_access.database import DatabaseConfig, ReadOnlyCursor
11
+
12
+
13
+ def main():
14
+ # for kr in backend.get_all_keyring():
15
+ # print(kr)
16
+ kr = keyring.get_keyring()
17
+ print(kr)
18
+ logging.basicConfig()
19
+ parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
20
+ parser.add_argument('-l', '--loglevel', default='WARN', help="Python logging level")
21
+ parser.add_argument('config',help="ini style config")
22
+
23
+ args = parser.parse_args()
24
+ postgresql_access_logger.setLevel(getattr(logging,args.loglevel))
25
+ cp = configparser.ConfigParser()
26
+ with open(args.config) as f:
27
+ cp.read_file(f)
28
+
29
+ db = DatabaseConfig(config=cp)
30
+ db.schema = 'usage'
31
+
32
+ c = db.connect(application_name="access test")
33
+ with c.cursor() as cursor:
34
+ cursor.execute("""select schemaname, tablename from pg_tables
35
+ where schemaname not in ('information_schema','pg_catalog')""")
36
+ # for r in cursor.fetchall():
37
+ # print(r)
38
+ cursor.execute('select count(*) from virtual_machine')
39
+ for r in cursor.fetchall():
40
+ print(r)
41
+ c.rollback()
42
+
43
+
44
+ if __name__ == "__main__":
45
+ main()