Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DB:
- def __init__(self, host, user, db, password):
- self.host = host
- self.user = user
- self.password = password
- self.db = db
- self.charset = 'utf8mb4'
- self.cursorclass = pymysql.cursors.DictCursor
- class DataConn:
- def __init__(self, db_obj):
- self.host = db_obj.host
- self.user = db_obj.user
- self.password = db_obj.password
- self.db = db_obj.db
- self.charset = db_obj.charset
- self.cursorclass = db_obj.cursorclass
- def __enter__(self):
- self.conn = pymysql.connect(
- host = self.host,
- user = self.user,
- password = self.password,
- db = self.db,
- charset = self.charset,
- cursorclass = self.cursorclass
- )
- return self.conn
- def __exit__(self, exc_type, exc_val, exc_tb):
- self.conn.close()
- if exc_val:
- raise
- db = DB(
- host = config.host,
- user = config.user,
- password = config.password,
- db = config.db
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement