def load_module(name):
    # if os.path.isdir(name):
    #     exp = parse_exp(name)
    #     for i in exp:
    #         path = (name + i).replace('/', '.')
    #         try:
    #             module_obj = importlib.import_module(name=path)
    #             if hasattr(module_obj, 'Zerooosploit'):
    #                 pass
    #         except ModuleNotFoundError as e:
    #             LOGGER.error(e)
    # else:
    exp = name.replace('/', '.')

    try:
        global mod
        mod = importlib.import_module('modules.' + exp)
        if hasattr(mod, 'Zerooosploit'):
            module_self = getattr(mod, 'Zerooosploit')
            # print(getattr(module_self, 'show_info'))
            # print('class', module_self())
            return module_self()
        else:
            msg = f'Module {exp} doesn\'t define any object named Zerooosploit'
            LOGGER.error(ModuleNotDefineException(msg))
    except ModuleNotFoundError as e:
        LOGGER.error(e)
    except Exception as e:
        LOGGER.exception(e)
    async def send_request_cgi(self, method, url, **kwargs):

        kwargs.setdefault('timeout', self.http_timeout)
        kwargs.setdefault('headers', self.http_headers)
        kwargs.setdefault('verify_ssl', self.verify_ssl)
        kwargs.setdefault('allow_redirects', self.http_allow_redirects)
        kwargs.setdefault('proxy', self.proxy)

        # 连接数限制 禁止dns缓存
        conn = aiohttp.TCPConnector(use_dns_cache=False)

        try:
            # async with asyncio.Semaphore(rate):
            async with aiohttp.ClientSession(connector=conn) as session:
                # async with aiohttp.ClientSession(connector=conn) as session:
                resp = await session.request(method, url, **kwargs)
                LOGGER.debug(f'Requests: {method} {url}', self.debug)
                text = await resp.text()
                content = await resp.read()
                stream_content = await resp.content.read()
                resp = {
                    'code': resp.status,
                    'text': text,
                    'content': content,
                    'url': resp.url,
                    'stream_content': stream_content,
                    'headers': resp.headers,
                    'cookie': resp.cookies
                }
                LOGGER.debug(http_response_style(resp['code'], resp['headers'], resp['text'], resp['content'],
                                                 resp['stream_content']), self.debug)
                return resp
        except aiohttp.ClientConnectorError:
            LOGGER.error(f'{url} Error: ConnectionError')
        except aiohttp.ServerDisconnectedError:
            LOGGER.error(f'{url} Error: ServerDisconnectedError')
        except aiohttp.InvalidURL:
            LOGGER.error(f'Invalid URL format: {url}')
        except socket.error as e:
            LOGGER.warning(e)
        except KeyboardInterrupt:
            LOGGER.warning('Module has been stopped')
        except asyncio.TimeoutError as e:
            pass
        except Exception as e:
            LOGGER.exception(e)

        return None
        #     if exp_info:
        #         self.only_insert_data('Exploit', exp_info['Name'], exp_info['Module'], exp_info['Product'], exp_info['Cve'],
        #                               exp_info['Create_date'], exp_info['Description'], exp_info['Authors'],
        #                               exp_info['References'])
        #     if aux_info:
        #         self.only_insert_data('Auxiliary', aux_info['Name'], aux_info['Module'], aux_info['Product'],
        #                               aux_info['Cve'], aux_info['Create_date'], aux_info['Description'],
        #                               aux_info['Authors'], aux_info['References'])
        # except KeyError:
        #     pass


try:
    module_manager = ModuleManager()
except (sqlite3.OperationalError, Exception) as e:
    LOGGER.exception(e)


def parse_module():
    exp = []
    for dirpath, dirnames, filenames in os.walk('./modules/exploit'):
        for file in filenames:
            if file.endswith('.py') and '__init__' not in file:
                if '__pycache__' not in dirpath:
                    exp.append(f'{dirpath}/{file}')
    aux = []
    for dirpath, dirnames, filenames in os.walk('./modules/auxiliary'):
        for file in filenames:
            if file.endswith('.py') and '__init__' not in file:
                if '__pycache__' not in dirpath:
                    aux.append(f'{dirpath}/{file}')