pyquocca 0.2.1__tar.gz → 0.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyquocca
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: Challenge utilities for SecEDU CTFs (primarily UNSW's COMP6[48]43).
5
5
  Author-email: Hamish Cox <hamish.cox@unsw.edu.au>
6
6
  Maintainer-email: Hamish Cox <hamish.cox@unsw.edu.au>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pyquocca"
3
- version = "0.2.1"
3
+ version = "0.2.2"
4
4
  description = "Challenge utilities for SecEDU CTFs (primarily UNSW's COMP6[48]43)."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.9"
@@ -0,0 +1,7 @@
1
+ import re
2
+
3
+ _NAME_TO_ENV = re.compile(r"[^A-Z0-9_]")
4
+
5
+
6
+ def to_env_var(s: str):
7
+ return _NAME_TO_ENV.sub("", s.upper().replace("-", "_"))
@@ -1,6 +1,5 @@
1
1
  import logging
2
2
  import os
3
- import re
4
3
  import time
5
4
  from typing import Any, Optional, Union
6
5
 
@@ -8,7 +7,7 @@ from flask import Flask, g
8
7
  from pymysql import Connection
9
8
  from pymysql.cursors import DictCursor
10
9
 
11
- _NAME_TO_ENV = re.compile(r"[^A-Z0-9_]")
10
+ from pyquocca.envvars import to_env_var
12
11
 
13
12
 
14
13
  class LoggingDictCursor(DictCursor):
@@ -40,12 +39,10 @@ class LoggingDictCursor(DictCursor):
40
39
 
41
40
  def connect(name: str = "mysql"):
42
41
  """Connects to a MySQL database resource using provided environment variables
43
- (e.g. `MYSQL_{name}_HOST`, note that `MYSQL_MYSQL_HOST` will be abbreviated to `MYSQL_HOST`).
42
+ (e.g. `{name}_HOST`).
44
43
  """
45
44
 
46
- env_prefix = f"MYSQL_{name}" if name != "mysql" else "MYSQL"
47
- env_prefix = _NAME_TO_ENV.sub("", env_prefix.upper().replace("-", "_"))
48
-
45
+ env_prefix = to_env_var(name)
49
46
  host = os.getenv(f"{env_prefix}_HOST")
50
47
  database = os.getenv(f"{env_prefix}_DB") or os.getenv(f"{env_prefix}_DATABASE")
51
48
  user = os.getenv(f"{env_prefix}_USER")
@@ -1,7 +1,6 @@
1
1
  import atexit
2
2
  import logging
3
3
  import os
4
- import re
5
4
  import time
6
5
  from typing import Generic, Optional, TypeVar, cast
7
6
 
@@ -11,7 +10,7 @@ from psycopg.abc import Params, Query
11
10
  from psycopg.rows import RowFactory, dict_row
12
11
  from psycopg_pool import ConnectionPool, NullConnectionPool
13
12
 
14
- _NAME_TO_ENV = re.compile(r"[^A-Z0-9_]")
13
+ from pyquocca.envvars import to_env_var
15
14
 
16
15
 
17
16
  class LoggingCursor(Cursor):
@@ -53,12 +52,10 @@ def connect(
53
52
  pool: Optional[bool] = None,
54
53
  ) -> ConnectionPool[Connection[T]] | NullConnectionPool[Connection[T]]:
55
54
  """Connects to a PostgreSQL database resource using provided environment variables
56
- (e.g. `POSTGRES_{name}_HOST`, note that `POSTGRES_POSTGRES_HOST` will be abbreviated to `POSTGRES_HOST`).
55
+ (e.g. `{name}_HOST`).
57
56
  """
58
57
 
59
- env_prefix = f"POSTGRES_{name}" if name != "postgres" else "POSTGRES"
60
- env_prefix = _NAME_TO_ENV.sub("", env_prefix.upper().replace("-", "_"))
61
-
58
+ env_prefix = to_env_var(name)
62
59
  host = os.getenv(f"{env_prefix}_HOST")
63
60
  database = os.getenv(f"{env_prefix}_DB") or os.getenv(f"{env_prefix}_DATABASE")
64
61
  user = os.getenv(f"{env_prefix}_USER")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes