Exemplo n.º 1
0
    def __init__(self, engine, db_config):
        super(OrmProxy, self).__init__()
        self.logger = LogManager.get_logger("orm." + self.__class__.__name__)
        self.engine = engine
        self.db_config = db_config
        self.host = self.db_config["HOST"]
        self.port = self.db_config["PORT"]
        self.user = self.db_config["USER"]
        self.passwd = self.db_config["PASSWORD"]
        self.db = self.db_config["NAME"]
        self.connected = False
        self.orm_engine = None

        try:
            if self.engine == 'mysql':
                params = (self.user, self.passwd, self.host, self.port, self.db)
                connect = 'mysql+mysqldb://%s:%s@%s:%s/%s?charset=utf8' % params
                self.orm_engine = create_engine(connect, max_overflow=5,
                                                encoding='utf-8', echo=True)
                self.connected = True
                self.logger.info('init: %s', 'Database engine MySQLdb.')
            else:
                self.logger.error('init: err=%s', 'Database engine not find.')
                raise "Database engine not find."
        except SQLAlchemyError:
            self.logger.error('connect: err=%s', 'Connect orm failed.')
            self.logger.log_last_except()
Exemplo n.º 2
0
 def __init__(self, db_config):
     super(MysqlDatabase, self).__init__()
     self.logger = LogManager.get_logger("db." + self.__class__.__name__)
     self.db_config = db_config
     self.host = self.db_config["HOST"]
     self.port = self.db_config["PORT"]
     self.user = self.db_config["USER"]
     self.passwd = self.db_config["PASSWORD"]
     self.db = self.db_config["NAME"]
     self.connected = False
     self.pool = None
Exemplo n.º 3
0
 def __init__(self, engine, db_config):
     super(DatabaseProxy, self).__init__()
     self.logger = LogManager.get_logger("db." + self.__class__.__name__)
     self.engine = engine
     if self.engine == 'mysql':
         self.db_client = MysqlDatabase(db_config)
         self.db_client.connect()
         self.logger.info('init: %s', 'Database engine MySQLdb.')
     else:
         self.logger.error('init: err=%s', 'Database engine not find.')
         raise "Database engine not find."
     self.connected = self.db_client.connected
     self.data_types = self.db_client.data_types
     self.operators = self.db_client.operators
     self.format_string = self.db_client.format_string
     self.thread_num = 10
     self.request_pool = ThreadPool(self.thread_num)
     self.request_time = 0.01
     self.timer = Timer.add_repeat_timer(self.request_time, self.request_result)
Exemplo n.º 4
0
        self.certfile = certfile
        self.body = body

    def __str__(self):
        return self.method + " " + self.host + " " + self.url

class HttpReply(object):
    def __init__(self, header, body):
        super(HttpReply, self).__init__()
        self.header = header
        self.body = body

    def __str__(self):
        return str(self.header)

_logger = LogManager.get_logger("http_client")


class AsyncHTTPClient(object):
    def __init__(self, max_clients=10, max_buffer_size=10240):
        """
        max_buffer_size is the number of bytes that can be read by IOStream. It
        defaults to 10kB.
        """
        super(AsyncHTTPClient, self).__init__()
        self.max_clients = max_clients
        self.active = {}
        self.max_buffer_size = max_buffer_size
        _logger.info('__init__: max_clients %d, max_buffer_size %d ',
                     max_clients, max_buffer_size)