MCPcopy Index your code
hub / github.com/PyMySQL/PyMySQL / TempUser

Class TempUser

pymysql/tests/test_connection.py:12–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12class TempUser:
13 def __init__(self, c, user, db, auth=None, authdata=None, password=None):
14 self._c = c
15 self._user = user
16 self._db = db
17 create = "CREATE USER " + user
18 if password is not None:
19 create += " IDENTIFIED BY '%s'" % password
20 elif auth is not None:
21 create += " IDENTIFIED WITH %s" % auth
22 if authdata is not None:
23 create += " AS '%s'" % authdata
24 try:
25 c.execute(create)
26 self._created = True
27 except pymysql.err.InternalError:
28 # already exists - TODO need to check the same plugin applies
29 self._created = False
30 try:
31 c.execute(f"GRANT SELECT ON {db}.* TO {user}")
32 self._grant = True
33 except pymysql.err.InternalError:
34 self._grant = False
35
36 def __enter__(self):
37 return self
38
39 def __exit__(self, exc_type, exc_value, traceback):
40 if self._grant:
41 self._c.execute(f"REVOKE SELECT ON {self._db}.* FROM {self._user}")
42 if self._created:
43 self._c.execute("DROP USER %s" % self._user)
44
45
46class TestAuthentication(base.PyMySQLTestCase):

Callers 6

realtestSocketAuthMethod · 0.85
realTestPamAuthMethod · 0.85
testAuthSHA256Method · 0.85
testAuthEd25519Method · 0.85

Calls

no outgoing calls

Tested by 6

realtestSocketAuthMethod · 0.68
realTestPamAuthMethod · 0.68
testAuthSHA256Method · 0.68
testAuthEd25519Method · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…