pyquocca 0.2.2__tar.gz → 0.2.3__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.2
3
+ Version: 0.2.3
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.2"
3
+ version = "0.2.3"
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"
@@ -85,6 +85,11 @@ logconfig_dict = {
85
85
  "handlers": ["console"],
86
86
  "qualname": "pyquocca.pgsql",
87
87
  },
88
+ "pyquocca.mysql": {
89
+ "level": "DEBUG",
90
+ "handlers": ["console"],
91
+ "qualname": "pyquocca.mysql",
92
+ },
88
93
  },
89
94
  "handlers": {
90
95
  "console": {
@@ -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
@@ -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,9 +152,15 @@ 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):
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
+
152
164
  # g._pgsql_connections is a dictionary of database names to connections.
153
165
  try:
154
166
  assert type(g._pgsql_connections) is dict
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