pyquocca 0.2.2__tar.gz → 0.3.0__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. {pyquocca-0.2.2 → pyquocca-0.3.0}/PKG-INFO +4 -4
  2. pyquocca-0.3.0/bump.zsh +26 -0
  3. pyquocca-0.3.0/bump_examples.zsh +26 -0
  4. {pyquocca-0.2.2 → pyquocca-0.3.0}/docker-compose.yml +3 -3
  5. {pyquocca-0.2.2 → pyquocca-0.3.0}/pyproject.toml +2 -2
  6. {pyquocca-0.2.2 → pyquocca-0.3.0}/src/pyquocca/gunicorn.py +7 -2
  7. {pyquocca-0.2.2 → pyquocca-0.3.0}/src/pyquocca/logging.py +1 -1
  8. {pyquocca-0.2.2 → pyquocca-0.3.0}/src/pyquocca/mysql.py +11 -0
  9. {pyquocca-0.2.2 → pyquocca-0.3.0}/src/pyquocca/pgsql.py +18 -6
  10. pyquocca-0.2.2/bump.zsh +0 -21
  11. pyquocca-0.2.2/bump_examples.zsh +0 -21
  12. {pyquocca-0.2.2 → pyquocca-0.3.0}/.gitignore +0 -0
  13. {pyquocca-0.2.2 → pyquocca-0.3.0}/.python-version +0 -0
  14. {pyquocca-0.2.2 → pyquocca-0.3.0}/Dockerfile +0 -0
  15. {pyquocca-0.2.2 → pyquocca-0.3.0}/README.md +0 -0
  16. {pyquocca-0.2.2 → pyquocca-0.3.0}/src/pyquocca/__init__.py +0 -0
  17. {pyquocca-0.2.2 → pyquocca-0.3.0}/src/pyquocca/envvars.py +0 -0
  18. {pyquocca-0.2.2 → pyquocca-0.3.0}/src/pyquocca/flags.py +0 -0
  19. {pyquocca-0.2.2 → pyquocca-0.3.0}/src/pyquocca/header_utils.py +0 -0
  20. {pyquocca-0.2.2 → pyquocca-0.3.0}/src/pyquocca/py.typed +0 -0
  21. {pyquocca-0.2.2 → pyquocca-0.3.0}/src/pyquocca/xssbot.py +0 -0
  22. {pyquocca-0.2.2 → pyquocca-0.3.0}/src/test_app/main.py +0 -0
  23. {pyquocca-0.2.2 → pyquocca-0.3.0}/src/test_app/sqlimports-mysql/init.sql +0 -0
  24. {pyquocca-0.2.2/src/test_app/sqlimports-pgsql → pyquocca-0.3.0/src/test_app/sqlimports-postgres}/init.sql +0 -0
  25. {pyquocca-0.2.2 → pyquocca-0.3.0}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyquocca
3
- Version: 0.2.2
3
+ Version: 0.3.0
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>
@@ -13,9 +13,9 @@ Requires-Dist: requests>=2.31.0
13
13
  Requires-Dist: typing-extensions>=4.10.0
14
14
  Provides-Extra: mysql
15
15
  Requires-Dist: pymysql>=1.0.2; extra == 'mysql'
16
- Provides-Extra: pgsql
17
- Requires-Dist: psycopg-binary>=3.2.4; extra == 'pgsql'
18
- Requires-Dist: psycopg[pool]>=3.2.4; extra == 'pgsql'
16
+ Provides-Extra: postgres
17
+ Requires-Dist: psycopg-binary>=3.2.4; extra == 'postgres'
18
+ Requires-Dist: psycopg[pool]>=3.2.4; extra == 'postgres'
19
19
  Description-Content-Type: text/markdown
20
20
 
21
21
  # QuoccaBank Standard Library
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env zsh
2
+
3
+ cd $(dirname "$0")
4
+
5
+ version=$(yq '.project.version' pyproject.toml)
6
+ echo "Using version $version for pyquocca packages..."
7
+
8
+ # Update parent module challenges
9
+ cd ../../../challenges
10
+
11
+ for file in **/requirements.txt; do
12
+ old=$(grep "^pyquocca" $file)
13
+ if [[ -n $old ]]; then
14
+ current_version=$(echo $old | grep -oE '==(.*)' | cut -d'=' -f3)
15
+
16
+ if [[ $current_version == $version ]]; then
17
+ echo $(dirname $file): up to date
18
+ else
19
+ echo $(dirname $file): updating $old '->' $version
20
+ # Match pyquocca with optional extras, followed by any version
21
+ sed -E -i '' '/^pyquocca(\[[^]]*\])?==.*/s//pyquocca\1=='$version'/' $file
22
+ fi
23
+ else
24
+ echo $(dirname $file): no pyquocca requirement
25
+ fi
26
+ done
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env zsh
2
+
3
+ cd $(dirname "$0")
4
+
5
+ version=$(yq '.project.version' pyproject.toml)
6
+ echo "Using version $version for pyquocca packages..."
7
+
8
+ # Update example challenges
9
+ cd ../../challenges
10
+
11
+ for file in **/requirements.txt; do
12
+ old=$(grep "^pyquocca" $file)
13
+ if [[ -n $old ]]; then
14
+ current_version=$(echo $old | grep -oE '==(.*)' | cut -d'=' -f3)
15
+
16
+ if [[ $current_version == $version ]]; then
17
+ echo $(dirname $file): up to date
18
+ else
19
+ echo $(dirname $file): updating $old '->' $version
20
+ # Match pyquocca with optional extras, followed by any version
21
+ sed -E -i '' '/^pyquocca(\[[^]]*\])?==.*/s//pyquocca\1=='$version'/' $file
22
+ fi
23
+ else
24
+ echo $(dirname $file): no pyquocca requirement
25
+ fi
26
+ done
@@ -6,7 +6,7 @@ services:
6
6
  ports:
7
7
  - "8000:8000"
8
8
  environment:
9
- - POSTGRES_HOST=pgsql
9
+ - POSTGRES_HOST=postgres
10
10
  - POSTGRES_USER=user
11
11
  - POSTGRES_PASSWORD=verysecure
12
12
  - POSTGRES_DB=challengedb
@@ -26,11 +26,11 @@ services:
26
26
  # volumes:
27
27
  # - ./src/test_app/sqlimports-mysql:/docker-entrypoint-initdb.d
28
28
 
29
- pgsql:
29
+ postgres:
30
30
  image: postgres:17-alpine
31
31
  environment:
32
32
  - POSTGRES_USER=user
33
33
  - POSTGRES_PASSWORD=verysecure
34
34
  - POSTGRES_DB=challengedb
35
35
  volumes:
36
- - ./src/test_app/sqlimports-pgsql:/docker-entrypoint-initdb.d
36
+ - ./src/test_app/sqlimports-postgres:/docker-entrypoint-initdb.d
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pyquocca"
3
- version = "0.2.2"
3
+ version = "0.3.0"
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"
@@ -16,7 +16,7 @@ dependencies = [
16
16
  ]
17
17
 
18
18
  [project.optional-dependencies]
19
- pgsql = ["psycopg[pool]>=3.2.4", "psycopg-binary>=3.2.4"]
19
+ postgres = ["psycopg[pool]>=3.2.4", "psycopg-binary>=3.2.4"]
20
20
  mysql = ["pymysql>=1.0.2"]
21
21
 
22
22
  [build-system]
@@ -80,10 +80,15 @@ logconfig_dict = {
80
80
  "handlers": ["console_error"],
81
81
  "qualname": "gunicorn.error",
82
82
  },
83
- "pyquocca.pgsql": {
83
+ "pyquocca.postgres": {
84
84
  "level": "DEBUG",
85
85
  "handlers": ["console"],
86
- "qualname": "pyquocca.pgsql",
86
+ "qualname": "pyquocca.postgres",
87
+ },
88
+ "pyquocca.mysql": {
89
+ "level": "DEBUG",
90
+ "handlers": ["console"],
91
+ "qualname": "pyquocca.mysql",
87
92
  },
88
93
  },
89
94
  "handlers": {
@@ -11,5 +11,5 @@ def setup_dev_server_logging():
11
11
  # Don't overwrite the format of the dev server.
12
12
  logging.getLogger("werkzeug").propagate = False
13
13
  # Log debugging for SQL.
14
- logging.getLogger("pyquocca.pgsql").setLevel("DEBUG")
14
+ logging.getLogger("pyquocca.postgres").setLevel("DEBUG")
15
15
  logging.getLogger("pyquocca.mysql").setLevel("DEBUG")
@@ -91,12 +91,18 @@ def fetch_all(connection: Connection, sql: str, values=None) -> list[dict[str, A
91
91
  return list(cursor.fetchall())
92
92
 
93
93
 
94
+ class UninitialisedError(Exception):
95
+ pass
96
+
97
+
94
98
  class FlaskMySQL:
95
99
  """Flask extension to add basic DB transaction usage to requests using MySQL. Each request gets a new connection
96
100
  and automatically commits or rolls back (if there is an unhandled exception) the entire transaction at
97
101
  the end of the request.
98
102
  """
99
103
 
104
+ app: Optional[Flask]
105
+
100
106
  def __init__(self, name: str = "mysql", app: Optional[Flask] = None):
101
107
  self.name = name
102
108
 
@@ -104,9 +110,14 @@ class FlaskMySQL:
104
110
  self.init_app(app)
105
111
 
106
112
  def init_app(self, app: Flask):
113
+ self.app = app
107
114
  app.teardown_request(self._teardown_request)
108
115
 
109
116
  def _get_connections_dict(self):
117
+ if self.app is None:
118
+ raise UninitialisedError(
119
+ "This Flask extension has not been initialised with .init_app() yet (required for auto-commit)."
120
+ )
110
121
  # g._mysql_connections is a dictionary of database names to connections.
111
122
  try:
112
123
  assert type(g._mysql_connections) is dict
@@ -22,7 +22,7 @@ class LoggingCursor(Cursor):
22
22
  prepare: Optional[bool] = None,
23
23
  binary: Optional[bool] = None,
24
24
  ):
25
- logger = logging.getLogger("pyquocca.pgsql")
25
+ logger = logging.getLogger("pyquocca.postgres")
26
26
 
27
27
  start = time.monotonic_ns()
28
28
  try:
@@ -123,12 +123,18 @@ def fetch_all(
123
123
  return cursor.fetchall()
124
124
 
125
125
 
126
+ class UninitialisedError(Exception):
127
+ pass
128
+
129
+
126
130
  class FlaskPostgres(Generic[T]):
127
131
  """Flask extension to add basic DB transaction usage to requests using Postgres. Each request gets a connection
128
132
  from the pool and automatically commits or rolls back (if there is an unhandled exception) the entire
129
133
  transaction at the end of the request.
130
134
  """
131
135
 
136
+ app: Optional[Flask]
137
+
132
138
  def __init__(
133
139
  self,
134
140
  name: str = "postgres",
@@ -146,16 +152,22 @@ class FlaskPostgres(Generic[T]):
146
152
  self.init_app(app)
147
153
 
148
154
  def init_app(self, app: Flask):
155
+ self.app = app
149
156
  app.teardown_request(self._teardown_request)
150
157
 
151
158
  def _get_connections_dict(self):
152
- # g._pgsql_connections is a dictionary of database names to connections.
159
+ if self.app is None:
160
+ raise UninitialisedError(
161
+ "This Flask extension has not been initialised with .init_app() yet (required for auto-commit)."
162
+ )
163
+
164
+ # g._postgres_connections is a dictionary of database names to connections.
153
165
  try:
154
- assert type(g._pgsql_connections) is dict
155
- return g._pgsql_connections
166
+ assert type(g._postgres_connections) is dict
167
+ return g._postgres_connections
156
168
  except (AttributeError, AssertionError):
157
- g._pgsql_connections = {}
158
- return g._pgsql_connections
169
+ g._postgres_connections = {}
170
+ return g._postgres_connections
159
171
 
160
172
  def _get_connection(self):
161
173
  connections = self._get_connections_dict()
pyquocca-0.2.2/bump.zsh DELETED
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env zsh
2
-
3
- cd $(dirname "$0")
4
-
5
- new="pyquocca==$(yq '.project.version' pyproject.toml)"
6
- echo Replacing existing pyquocca requirements with $new...
7
-
8
- # Update parent module challenges
9
- cd ../../../challenges
10
-
11
- for file in **/requirements.txt; do
12
- old=$(grep -E 'pyquocca==\d+\.\d+\.\d+' $file)
13
- if [[ $? == '0' ]]; then
14
- echo $(dirname $file): $old '-->' $new
15
- safe=$(sed 's/\./\\./g' <<<$old)
16
- sed -i.bak s/$safe/$new/g $file
17
- rm $file.bak
18
- else
19
- echo $(dirname $file): no pyquocca requirement
20
- fi
21
- done
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env zsh
2
-
3
- cd $(dirname "$0")
4
-
5
- new="pyquocca==$(yq '.project.version' pyproject.toml)"
6
- echo Replacing existing pyquocca requirements with $new...
7
-
8
- # Update example challenges
9
- cd ../../challenges
10
-
11
- for file in **/requirements.txt; do
12
- old=$(grep -E 'pyquocca==\d+\.\d+\.\d+' $file)
13
- if [[ $? == '0' ]]; then
14
- echo $(dirname $file): $old '-->' $new
15
- safe=$(sed 's/\./\\./g' <<<$old)
16
- sed -i.bak s/$safe/$new/g $file
17
- rm $file.bak
18
- else
19
- echo $(dirname $file): no pyquocca requirement
20
- fi
21
- done
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes