wcp-library 1.5.8__tar.gz → 1.6.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 (25) hide show
  1. {wcp_library-1.5.8 → wcp_library-1.6.2}/PKG-INFO +1 -1
  2. {wcp_library-1.5.8 → wcp_library-1.6.2}/pyproject.toml +1 -1
  3. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/sql/oracle.py +88 -66
  4. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/sql/postgres.py +62 -48
  5. {wcp_library-1.5.8 → wcp_library-1.6.2}/README.md +0 -0
  6. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/__init__.py +0 -0
  7. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/credentials/__init__.py +0 -0
  8. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/credentials/_credential_manager_asynchronous.py +0 -0
  9. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/credentials/_credential_manager_synchronous.py +0 -0
  10. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/credentials/api.py +0 -0
  11. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/credentials/ftp.py +0 -0
  12. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/credentials/internet.py +0 -0
  13. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/credentials/oracle.py +0 -0
  14. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/credentials/postgres.py +0 -0
  15. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/emailing.py +0 -0
  16. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/ftp/__init__.py +0 -0
  17. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/ftp/ftp.py +0 -0
  18. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/ftp/sftp.py +0 -0
  19. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/informatica.py +0 -0
  20. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/logging.py +0 -0
  21. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/selenium/__init__.py +0 -0
  22. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/selenium/_selenium_driver.py +0 -0
  23. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/selenium/selenium_helper.py +0 -0
  24. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/sql/__init__.py +0 -0
  25. {wcp_library-1.5.8 → wcp_library-1.6.2}/wcp_library/time.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: wcp-library
3
- Version: 1.5.8
3
+ Version: 1.6.2
4
4
  Summary: Common utilites for internal development at WCP
5
5
  Author: Mitch-Petersen
6
6
  Author-email: mitch.petersen@wcap.ca
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "wcp-library"
3
- version = "1.5.8"
3
+ version = "1.6.2"
4
4
  description = "Common utilites for internal development at WCP"
5
5
  authors = [{name="Mitch-Petersen", email="mitch.petersen@wcap.ca"}]
6
6
  readme = "README.md"
@@ -191,10 +191,12 @@ class OracleConnection(object):
191
191
  """
192
192
 
193
193
  connection = self._get_connection()
194
- with connection:
195
- cursor = connection.cursor()
196
- cursor.execute(query)
197
- connection.commit()
194
+ cursor = connection.cursor()
195
+ cursor.execute(query)
196
+ connection.commit()
197
+
198
+ if self.use_pool:
199
+ self._session_pool.release(self._connection)
198
200
 
199
201
  @retry
200
202
  def safe_execute(self, query: str, packed_values: dict) -> None:
@@ -207,10 +209,12 @@ class OracleConnection(object):
207
209
  """
208
210
 
209
211
  connection = self._get_connection()
210
- with connection:
211
- cursor = connection.cursor()
212
- cursor.execute(query, packed_values)
213
- connection.commit()
212
+ cursor = connection.cursor()
213
+ cursor.execute(query, packed_values)
214
+ connection.commit()
215
+
216
+ if self.use_pool:
217
+ self._session_pool.release(self._connection)
214
218
 
215
219
  @retry
216
220
  def execute_multiple(self, queries: list[tuple[str, dict]]) -> None:
@@ -222,16 +226,18 @@ class OracleConnection(object):
222
226
  """
223
227
 
224
228
  connection = self._get_connection()
225
- with connection:
226
- cursor = connection.cursor()
227
- for item in queries:
228
- query = item[0]
229
- packed_values = item[1]
230
- if packed_values:
231
- cursor.execute(query, packed_values)
232
- else:
233
- cursor.execute(query)
234
- connection.commit()
229
+ cursor = connection.cursor()
230
+ for item in queries:
231
+ query = item[0]
232
+ packed_values = item[1]
233
+ if packed_values:
234
+ cursor.execute(query, packed_values)
235
+ else:
236
+ cursor.execute(query)
237
+ connection.commit()
238
+
239
+ if self.use_pool:
240
+ self._session_pool.release(self._connection)
235
241
 
236
242
  @retry
237
243
  def execute_many(self, query: str, dictionary: list[dict]) -> None:
@@ -244,10 +250,12 @@ class OracleConnection(object):
244
250
  """
245
251
 
246
252
  connection = self._get_connection()
247
- with connection:
248
- cursor = connection.cursor()
249
- cursor.executemany(query, dictionary)
250
- connection.commit()
253
+ cursor = connection.cursor()
254
+ cursor.executemany(query, dictionary)
255
+ connection.commit()
256
+
257
+ if self.use_pool:
258
+ self._session_pool.release(self._connection)
251
259
 
252
260
  @retry
253
261
  def fetch_data(self, query: str, packed_data=None) -> list:
@@ -260,13 +268,16 @@ class OracleConnection(object):
260
268
  """
261
269
 
262
270
  connection = self._get_connection()
263
- with connection:
264
- cursor = connection.cursor()
265
- if packed_data:
266
- cursor.execute(query, packed_data)
267
- else:
268
- cursor.execute(query)
269
- rows = cursor.fetchall()
271
+ cursor = connection.cursor()
272
+ if packed_data:
273
+ cursor.execute(query, packed_data)
274
+ else:
275
+ cursor.execute(query)
276
+ rows = cursor.fetchall()
277
+ connection.commit()
278
+
279
+ if self.use_pool:
280
+ self._session_pool.release(self._connection)
270
281
  return rows
271
282
 
272
283
  @retry
@@ -290,7 +301,7 @@ class OracleConnection(object):
290
301
  params = param_list[0]
291
302
 
292
303
  main_dict = df.to_dict('records')
293
- query = f"""DELETE FROM {outputTableName} WHERE {params}"""
304
+ query = f"DELETE FROM {outputTableName} WHERE {params}"
294
305
  self.execute_many(query, main_dict)
295
306
 
296
307
  @retry
@@ -315,7 +326,7 @@ class OracleConnection(object):
315
326
  dfObj = dfObj.replace({np.nan: None})
316
327
  main_dict = dfObj.to_dict('records')
317
328
 
318
- query = f"""INSERT INTO {outputTableName} ({col}) VALUES ({bind})"""
329
+ query = f"INSERT INTO {outputTableName} ({col}) VALUES ({bind})"
319
330
  self.execute_many(query, main_dict)
320
331
 
321
332
  @retry
@@ -327,7 +338,7 @@ class OracleConnection(object):
327
338
  :return: None
328
339
  """
329
340
 
330
- truncateQuery = f"""TRUNCATE TABLE {tableName}"""
341
+ truncateQuery = f"TRUNCATE TABLE {tableName}"
331
342
  self.execute(truncateQuery)
332
343
 
333
344
  @retry
@@ -339,7 +350,7 @@ class OracleConnection(object):
339
350
  :return: None
340
351
  """
341
352
 
342
- deleteQuery = f"""DELETE FROM {tableName}"""
353
+ deleteQuery = f"DELETE FROM {tableName}"
343
354
  self.execute(deleteQuery)
344
355
 
345
356
  def __del__(self) -> None:
@@ -460,10 +471,12 @@ class AsyncOracleConnection(object):
460
471
  """
461
472
 
462
473
  connection = await self._get_connection()
463
- async with connection:
464
- with connection.cursor() as cursor:
465
- await cursor.execute(query)
466
- await connection.commit()
474
+ with connection.cursor() as cursor:
475
+ await cursor.execute(query)
476
+ await connection.commit()
477
+
478
+ if self.use_pool:
479
+ await self._session_pool.release(self._connection)
467
480
 
468
481
  @async_retry
469
482
  async def safe_execute(self, query: str, packed_values: dict) -> None:
@@ -476,10 +489,12 @@ class AsyncOracleConnection(object):
476
489
  """
477
490
 
478
491
  connection = await self._get_connection()
479
- async with connection:
480
- with connection.cursor() as cursor:
481
- await cursor.execute(query, packed_values)
482
- await connection.commit()
492
+ with connection.cursor() as cursor:
493
+ await cursor.execute(query, packed_values)
494
+ await connection.commit()
495
+
496
+ if self.use_pool:
497
+ await self._session_pool.release(self._connection)
483
498
 
484
499
  @async_retry
485
500
  async def execute_multiple(self, queries: list[tuple[str, dict]]) -> None:
@@ -491,16 +506,18 @@ class AsyncOracleConnection(object):
491
506
  """
492
507
 
493
508
  connection = await self._get_connection()
494
- async with connection:
495
- with connection.cursor() as cursor:
496
- for item in queries:
497
- query = item[0]
498
- packed_values = item[1]
499
- if packed_values:
500
- await cursor.execute(query, packed_values)
501
- else:
502
- await cursor.execute(query)
503
- await connection.commit()
509
+ with connection.cursor() as cursor:
510
+ for item in queries:
511
+ query = item[0]
512
+ packed_values = item[1]
513
+ if packed_values:
514
+ await cursor.execute(query, packed_values)
515
+ else:
516
+ await cursor.execute(query)
517
+ await connection.commit()
518
+
519
+ if self.use_pool:
520
+ await self._session_pool.release(self._connection)
504
521
 
505
522
  @async_retry
506
523
  async def execute_many(self, query: str, dictionary: list[dict]) -> None:
@@ -513,10 +530,12 @@ class AsyncOracleConnection(object):
513
530
  """
514
531
 
515
532
  connection = await self._get_connection()
516
- async with connection:
517
- with connection.cursor() as cursor:
518
- await cursor.executemany(query, dictionary)
519
- await connection.commit()
533
+ with connection.cursor() as cursor:
534
+ await cursor.executemany(query, dictionary)
535
+ await connection.commit()
536
+
537
+ if self.use_pool:
538
+ await self._session_pool.release(self._connection)
520
539
 
521
540
  @async_retry
522
541
  async def fetch_data(self, query: str, packed_data=None) -> list:
@@ -529,13 +548,16 @@ class AsyncOracleConnection(object):
529
548
  """
530
549
 
531
550
  connection = await self._get_connection()
532
- async with connection:
533
- with connection.cursor() as cursor:
534
- if packed_data:
535
- await cursor.execute(query, packed_data)
536
- else:
537
- await cursor.execute(query)
538
- rows = await cursor.fetchall()
551
+ with connection.cursor() as cursor:
552
+ if packed_data:
553
+ await cursor.execute(query, packed_data)
554
+ else:
555
+ await cursor.execute(query)
556
+ rows = await cursor.fetchall()
557
+ await connection.commit()
558
+
559
+ if self.use_pool:
560
+ await self._session_pool.release(self._connection)
539
561
  return rows
540
562
 
541
563
  @async_retry
@@ -559,7 +581,7 @@ class AsyncOracleConnection(object):
559
581
  params = param_list[0]
560
582
 
561
583
  main_dict = df.to_dict('records')
562
- query = f"""DELETE FROM {outputTableName} WHERE {params}"""
584
+ query = f"DELETE FROM {outputTableName} WHERE {params}"
563
585
  await self.execute_many(query, main_dict)
564
586
 
565
587
  @async_retry
@@ -584,7 +606,7 @@ class AsyncOracleConnection(object):
584
606
  dfObj = dfObj.replace({np.nan: None})
585
607
  main_dict = dfObj.to_dict('records')
586
608
 
587
- query = f"""INSERT INTO {outputTableName} ({col}) VALUES ({bind})"""
609
+ query = f"INSERT INTO {outputTableName} ({col}) VALUES ({bind})"
588
610
  await self.execute_many(query, main_dict)
589
611
 
590
612
  @async_retry
@@ -596,7 +618,7 @@ class AsyncOracleConnection(object):
596
618
  :return: None
597
619
  """
598
620
 
599
- truncateQuery = f"""TRUNCATE TABLE {tableName}"""
621
+ truncateQuery = f"TRUNCATE TABLE {tableName}"
600
622
  await self.execute(truncateQuery)
601
623
 
602
624
  @async_retry
@@ -608,5 +630,5 @@ class AsyncOracleConnection(object):
608
630
  :return: None
609
631
  """
610
632
 
611
- deleteQuery = f"""DELETE FROM {tableName}"""
633
+ deleteQuery = f"DELETE FROM {tableName}"
612
634
  await self.execute(deleteQuery)
@@ -1,6 +1,5 @@
1
1
  import logging
2
- from contextlib import _GeneratorContextManager
3
- from typing import Optional, Any
2
+ from typing import Optional
4
3
 
5
4
  import numpy as np
6
5
  import pandas as pd
@@ -128,7 +127,7 @@ class PostgresConnection(object):
128
127
  else:
129
128
  self._connection = self.connection
130
129
 
131
- def _get_connection(self) -> _GeneratorContextManager[Any] | Connection:
130
+ def _get_connection(self) -> Connection:
132
131
  """
133
132
  Get the connection object
134
133
 
@@ -136,7 +135,7 @@ class PostgresConnection(object):
136
135
  """
137
136
 
138
137
  if self.use_pool:
139
- connection = self._session_pool.connection()
138
+ connection = self._session_pool.getconn()
140
139
  return connection
141
140
  else:
142
141
  if self._connection is None or self._connection.closed:
@@ -183,8 +182,11 @@ class PostgresConnection(object):
183
182
  """
184
183
 
185
184
  connection = self._get_connection()
186
- with connection:
187
- connection.execute(query)
185
+ connection.execute(query)
186
+ connection.commit()
187
+
188
+ if self.use_pool:
189
+ self._session_pool.putconn(connection)
188
190
 
189
191
  @retry
190
192
  def safe_execute(self, query: SQL | str, packed_values: dict) -> None:
@@ -197,8 +199,11 @@ class PostgresConnection(object):
197
199
  """
198
200
 
199
201
  connection = self._get_connection()
200
- with connection:
201
- connection.execute(query, packed_values)
202
+ connection.execute(query, packed_values)
203
+ connection.commit()
204
+
205
+ if self.use_pool:
206
+ self._session_pool.putconn(connection)
202
207
 
203
208
  @retry
204
209
  def execute_multiple(self, queries: list[tuple[SQL | str, dict]]) -> None:
@@ -210,14 +215,17 @@ class PostgresConnection(object):
210
215
  """
211
216
 
212
217
  connection = self._get_connection()
213
- with connection:
214
- for item in queries:
215
- query = item[0]
216
- packed_values = item[1]
217
- if packed_values:
218
- connection.execute(query, packed_values)
219
- else:
220
- connection.execute(query)
218
+ for item in queries:
219
+ query = item[0]
220
+ packed_values = item[1]
221
+ if packed_values:
222
+ connection.execute(query, packed_values)
223
+ else:
224
+ connection.execute(query)
225
+ connection.commit()
226
+
227
+ if self.use_pool:
228
+ self._session_pool.putconn(connection)
221
229
 
222
230
  @retry
223
231
  def execute_many(self, query: SQL | str, dictionary: list[dict]) -> None:
@@ -230,9 +238,12 @@ class PostgresConnection(object):
230
238
  """
231
239
 
232
240
  connection = self._get_connection()
233
- with connection:
234
- cursor = connection.cursor()
235
- cursor.executemany(query, dictionary)
241
+ cursor = connection.cursor()
242
+ cursor.executemany(query, dictionary)
243
+ connection.commit()
244
+
245
+ if self.use_pool:
246
+ self._session_pool.putconn(connection)
236
247
 
237
248
  @retry
238
249
  def fetch_data(self, query: SQL | str, packed_data=None) -> list[tuple]:
@@ -245,13 +256,16 @@ class PostgresConnection(object):
245
256
  """
246
257
 
247
258
  connection = self._get_connection()
248
- with connection:
249
- cursor = connection.cursor()
250
- if packed_data:
251
- cursor.execute(query, packed_data)
252
- else:
253
- cursor.execute(query)
254
- rows = cursor.fetchall()
259
+ cursor = connection.cursor()
260
+ if packed_data:
261
+ cursor.execute(query, packed_data)
262
+ else:
263
+ cursor.execute(query)
264
+ rows = cursor.fetchall()
265
+ connection.commit()
266
+
267
+ if self.use_pool:
268
+ self._session_pool.putconn(connection)
255
269
  return rows
256
270
 
257
271
  @retry
@@ -443,8 +457,8 @@ class AsyncPostgresConnection(object):
443
457
  """
444
458
 
445
459
  connection = await self._get_connection()
446
- async with connection:
447
- await connection.execute(query)
460
+ await connection.execute(query)
461
+ await connection.commit()
448
462
 
449
463
  if self.use_pool:
450
464
  await self._session_pool.putconn(connection)
@@ -460,8 +474,8 @@ class AsyncPostgresConnection(object):
460
474
  """
461
475
 
462
476
  connection = await self._get_connection()
463
- async with connection:
464
- await connection.execute(query, packed_values)
477
+ await connection.execute(query, packed_values)
478
+ await connection.commit()
465
479
 
466
480
  if self.use_pool:
467
481
  await self._session_pool.putconn(connection)
@@ -476,14 +490,14 @@ class AsyncPostgresConnection(object):
476
490
  """
477
491
 
478
492
  connection = await self._get_connection()
479
- async with connection:
480
- for item in queries:
481
- query = item[0]
482
- packed_values = item[1]
483
- if packed_values:
484
- await connection.execute(query, packed_values)
485
- else:
486
- await connection.execute(query)
493
+ for item in queries:
494
+ query = item[0]
495
+ packed_values = item[1]
496
+ if packed_values:
497
+ await connection.execute(query, packed_values)
498
+ else:
499
+ await connection.execute(query)
500
+ await connection.commit()
487
501
 
488
502
  if self.use_pool:
489
503
  await self._session_pool.putconn(connection)
@@ -499,9 +513,9 @@ class AsyncPostgresConnection(object):
499
513
  """
500
514
 
501
515
  connection = await self._get_connection()
502
- async with connection:
503
- cursor = connection.cursor()
504
- await cursor.executemany(query, dictionary)
516
+ cursor = connection.cursor()
517
+ await cursor.executemany(query, dictionary)
518
+ await connection.commit()
505
519
 
506
520
  if self.use_pool:
507
521
  await self._session_pool.putconn(connection)
@@ -517,13 +531,13 @@ class AsyncPostgresConnection(object):
517
531
  """
518
532
 
519
533
  connection = await self._get_connection()
520
- async with connection:
521
- cursor = connection.cursor()
522
- if packed_data:
523
- await cursor.execute(query, packed_data)
524
- else:
525
- await cursor.execute(query)
526
- rows = await cursor.fetchall()
534
+ cursor = connection.cursor()
535
+ if packed_data:
536
+ await cursor.execute(query, packed_data)
537
+ else:
538
+ await cursor.execute(query)
539
+ rows = await cursor.fetchall()
540
+ await connection.commit()
527
541
 
528
542
  if self.use_pool:
529
543
  await self._session_pool.putconn(connection)
File without changes