<s> import getpass <EOL> import logging <EOL> import os <EOL> import pymysql <EOL> import pymysql . cursors <EOL> from . collections import AllRevisions , Archives , Pages , Revisions , Users <EOL> logger = logging . getLogger ( "<STR_LIT>" ) <EOL> class DB : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , connection ) : <EOL> self . shared_connection = connection <EOL> self . shared_connection . cursorclass = pymysql . cursors . DictCursor <EOL> self . revisions = Revisions ( self ) <EOL> """<STR_LIT>""" <EOL> self . archives = Archives ( self ) <EOL> """<STR_LIT>""" <EOL> self . all_revisions = AllRevisions ( self ) <EOL> """<STR_LIT>""" <EOL> self . pages = Pages ( self ) <EOL> """<STR_LIT>""" <EOL> self . users = Users ( self ) <EOL> """<STR_LIT>""" <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . __class__ . __name__ , <EOL> "<STR_LIT:U+002CU+0020>" . join ( <EOL> [ repr ( arg ) for arg in self . args ] + <EOL> [ "<STR_LIT>" % ( k , v ) for k , v in self . kwargs . items ( ) ] <EOL> ) <EOL> ) <EOL> def __str__ ( self ) : <EOL> return self . __repr__ ( ) <EOL> @ classmethod <EOL> def add_arguments ( cls , parser , defaults = None ) : <EOL> """<STR_LIT>""" <EOL> defaults = defaults if defaults is not None else defaults <EOL> default_host = defaults . get ( '<STR_LIT:host>' , "<STR_LIT:localhost>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> help = "<STR_LIT>" . format ( default_host ) , <EOL> default = default_host <EOL> ) <EOL> default_database = defaults . get ( '<STR_LIT>' , getpass . getuser ( ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> help = "<STR_LIT>" . format ( default_database ) , <EOL> default = default_database <EOL> ) <EOL> default_defaults_file = defaults . get ( '<STR_LIT>' , os . path . expanduser ( "<STR_LIT>" ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = "<STR_LIT>" . format ( default_defaults_file ) , <EOL> default = default_defaults_file <EOL> ) <EOL> default_user = defaults . get ( '<STR_LIT:user>' , getpass . getuser ( ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> help = "<STR_LIT>" . format ( default_user ) , <EOL> default = default_user <EOL> ) <EOL> return parser <EOL> @ classmethod <EOL> def from_arguments ( cls , args ) : <EOL> """<STR_LIT>""" <EOL> connection = pymysql . connect ( <EOL> args . host , <EOL> args . user , <EOL> database = args . database , <EOL> read_default_file = args . defaults_file <EOL> ) <EOL> return cls ( connection ) <EOL> @ classmethod <EOL> def from_params ( cls , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> kwargs [ '<STR_LIT>' ] = pymysql . cursors . DictCursor <EOL> if kwargs [ '<STR_LIT>' ] : <EOL> kwargs [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] <EOL> del kwargs [ '<STR_LIT>' ] <EOL> connection = pymysql . connect ( * args , ** kwargs ) <EOL> return cls ( connection ) </s>
