MCPcopy Index your code
hub / github.com/ddserver/ddserver / cursor

Method cursor

ddserver/db.py:56–88  ·  view source on GitHub ↗
(self, config)

Source from the content-addressed store, hash-verified

54 @contextlib.contextmanager
55 @require(config = 'ddserver.config:Config')
56 def cursor(self, config):
57 # Ensure we have a connection for this thread
58 if not hasattr(self.thread_local, 'connection'):
59 connection = MySQLdb.connect(host = config.db.host,
60 port = config.db.port,
61 user = config.db.username,
62 passwd = config.db.password,
63 db = config.db.name,
64 cursorclass = MySQLdb.cursors.DictCursor,
65 charset = 'utf8')
66 setattr(self.thread_local, 'connection', connection)
67
68 else:
69 # Use existing connection
70 connection = getattr(self.thread_local, 'connection')
71
72 # Reconnect if connection is down
73 connection.ping(True)
74
75 cursor = connection.cursor()
76
77 try:
78 yield cursor
79
80 except:
81 connection.rollback()
82 raise
83
84 else:
85 connection.commit()
86
87 finally:
88 cursor.close()

Callers 15

answer_soaFunction · 0.80
answer_aFunction · 0.80
__getitem__Method · 0.80
generate_authcodeMethod · 0.80
validate_pythonMethod · 0.80
validate_pythonMethod · 0.80
post_signupFunction · 0.80
post_signup_activateFunction · 0.80
post_signup_cancelFunction · 0.80
post_lostpass_setnewFunction · 0.80
post_lostpass_cancelFunction · 0.80
get_statisticsFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected