# Path: falsy/loader/func.py
# def load(function_name):
#     if not function_name:
#         return None
# 
#     if function_name in func_map.keys():
#         return func_map[function_name]
# 
#     module_name, attr_path = function_name.rsplit('.', 1)
#     module = None
#     last_import_error = None
# 
#     while not module:
# 
#         try:
#             module = importlib.import_module(module_name)
#         except ImportError as import_error:
#             last_import_error = import_error
#             if '.' in module_name:
#                 module_name, attr_path1 = module_name.rsplit('.', 1)
#                 attr_path = '{0}.{1}'.format(attr_path1, attr_path)
#             else:
#                 raise
#     try:
#         function = deep_getattr(module, attr_path)
#     except AttributeError:
#         if last_import_error:
#             raise last_import_error
#         else:
#             raise
#     func_map[str(function_name)] = function
#     return function
# 
# Path: falsy/netboy/curl_result.py
# def curl_result(c):
#     effective_url = c.getinfo(pycurl.EFFECTIVE_URL)
#     primary_ip = c.getinfo(pycurl.PRIMARY_IP)
#     primary_port = c.getinfo(pycurl.PRIMARY_PORT)
#     local_ip = c.getinfo(pycurl.LOCAL_IP)
#     local_port = c.getinfo(pycurl.LOCAL_PORT)
#     speed_download = c.getinfo(pycurl.SPEED_DOWNLOAD)
#     size_download = c.getinfo(pycurl.SIZE_DOWNLOAD)
#     redirect_time = c.getinfo(pycurl.REDIRECT_TIME)
#     redirect_count = c.getinfo(pycurl.REDIRECT_COUNT)
#     redirect_url = c.getinfo(pycurl.REDIRECT_URL)
#     http_code = c.getinfo(pycurl.HTTP_CODE)
#     response_code = c.getinfo(pycurl.RESPONSE_CODE)
#     total_time = c.getinfo(pycurl.TOTAL_TIME)
#     content_type = c.getinfo(pycurl.CONTENT_TYPE)
#     namelookup_time = c.getinfo(pycurl.NAMELOOKUP_TIME)
#     info_filetime = c.getinfo(pycurl.INFO_FILETIME)
#     http_connectcode = c.getinfo(pycurl.HTTP_CONNECTCODE)
#     starttransfer_time = c.getinfo(pycurl.STARTTRANSFER_TIME)
#     pretransfer_time = c.getinfo(pycurl.PRETRANSFER_TIME)
#     header_size = c.getinfo(pycurl.HEADER_SIZE)
#     request_size = c.getinfo(pycurl.REQUEST_SIZE)
#     ssl_verifyresult = c.getinfo(pycurl.SSL_VERIFYRESULT)
#     num_connects = c.getinfo(pycurl.NUM_CONNECTS)
# 
#     return {
#         'effective_url': effective_url,
#         'primary_ip': primary_ip,
#         'primary_port': primary_port,
#         'local_ip': local_ip,
#         'local_port': local_port,
#         'speed_download': speed_download,
#         'size_download': size_download,
#         'redirect_time': redirect_time,
#         'redirect_count': redirect_count,
#         'redirect_url': redirect_url,
#         'http_code': http_code,
#         'response_code': response_code,
#         'total_time': total_time,
#         'content_type': content_type,
#         'namelookup_time': namelookup_time,
#         'info_filetime': info_filetime,
#         'http_connectcode': http_connectcode,
#         'starttransfer_time': starttransfer_time,
#         'pretransfer_time': pretransfer_time,
#         'header_size': header_size,
#         'request_size': request_size,
#         'ssl_verifyresult': ssl_verifyresult,
#         'num_connects': num_connects,
#         # 'proxy_ssl_verifyresult': proxy_ssl_verifyresult,
#         # 'app_connecttime': app_connecttime,
# 
#     }


import asyncio as aio
import atexit
import pycurl
from falsy.loader.func import load
from falsy.netboy.curl_result import curl_result
        finally:
            cls._multi.remove_handle(c)

    @classmethod
    def perform(cls):
        if cls._futures:
            while True:
                status, num_active = cls._multi.perform()
                if status != pycurl.E_CALL_MULTI_PERFORM:
                    break
            while True:
                num_ready, success, fail = cls._multi.info_read()
                for c in success:
                    cc = cls._futures.pop(c)
                    result = curl_result(c)
                    result['url'] = c._raw_url
                    result['id'] = c._raw_id
                    result['state'] = 'normal'
                    result['spider'] = 'pycurl'
                    result['payload'] = payload = c._raw_payload

                    # post_func = payload.get('post_func')
                    # if type(post_func) == str:
                    #     post_func = load(post_func)
                    # if post_func:
                    #     result = post_func(payload, result)

                    cc.set_result(result)
                for c, err_num, err_msg in fail:
                    print('error:', err_num, err_msg, c.getinfo(pycurl.EFFECTIVE_URL))

# Path: falsy/loader/func.py
# def load(function_name):
#     if not function_name:
#         return None
# 
#     if function_name in func_map.keys():
#         return func_map[function_name]
# 
#     module_name, attr_path = function_name.rsplit('.', 1)
#     module = None
#     last_import_error = None
# 
#     while not module:
# 
#         try:
#             module = importlib.import_module(module_name)
#         except ImportError as import_error:
#             last_import_error = import_error
#             if '.' in module_name:
#                 module_name, attr_path1 = module_name.rsplit('.', 1)
#                 attr_path = '{0}.{1}'.format(attr_path1, attr_path)
#             else:
#                 raise
#     try:
#         function = deep_getattr(module, attr_path)
#     except AttributeError:
#         if last_import_error:
#             raise last_import_error
#         else:
#             raise
#     func_map[str(function_name)] = function
#     return function
# 
# Path: falsy/netboy/curl_result.py
# def curl_result(c):
#     effective_url = c.getinfo(pycurl.EFFECTIVE_URL)
#     primary_ip = c.getinfo(pycurl.PRIMARY_IP)
#     primary_port = c.getinfo(pycurl.PRIMARY_PORT)
#     local_ip = c.getinfo(pycurl.LOCAL_IP)
#     local_port = c.getinfo(pycurl.LOCAL_PORT)
#     speed_download = c.getinfo(pycurl.SPEED_DOWNLOAD)
#     size_download = c.getinfo(pycurl.SIZE_DOWNLOAD)
#     redirect_time = c.getinfo(pycurl.REDIRECT_TIME)
#     redirect_count = c.getinfo(pycurl.REDIRECT_COUNT)
#     redirect_url = c.getinfo(pycurl.REDIRECT_URL)
#     http_code = c.getinfo(pycurl.HTTP_CODE)
#     response_code = c.getinfo(pycurl.RESPONSE_CODE)
#     total_time = c.getinfo(pycurl.TOTAL_TIME)
#     content_type = c.getinfo(pycurl.CONTENT_TYPE)
#     namelookup_time = c.getinfo(pycurl.NAMELOOKUP_TIME)
#     info_filetime = c.getinfo(pycurl.INFO_FILETIME)
#     http_connectcode = c.getinfo(pycurl.HTTP_CONNECTCODE)
#     starttransfer_time = c.getinfo(pycurl.STARTTRANSFER_TIME)
#     pretransfer_time = c.getinfo(pycurl.PRETRANSFER_TIME)
#     header_size = c.getinfo(pycurl.HEADER_SIZE)
#     request_size = c.getinfo(pycurl.REQUEST_SIZE)
#     ssl_verifyresult = c.getinfo(pycurl.SSL_VERIFYRESULT)
#     num_connects = c.getinfo(pycurl.NUM_CONNECTS)
# 
#     return {
#         'effective_url': effective_url,
#         'primary_ip': primary_ip,
#         'primary_port': primary_port,
#         'local_ip': local_ip,
#         'local_port': local_port,
#         'speed_download': speed_download,
#         'size_download': size_download,
#         'redirect_time': redirect_time,
#         'redirect_count': redirect_count,
#         'redirect_url': redirect_url,
#         'http_code': http_code,
#         'response_code': response_code,
#         'total_time': total_time,
#         'content_type': content_type,
#         'namelookup_time': namelookup_time,
#         'info_filetime': info_filetime,
#         'http_connectcode': http_connectcode,
#         'starttransfer_time': starttransfer_time,
#         'pretransfer_time': pretransfer_time,
#         'header_size': header_size,
#         'request_size': request_size,
#         'ssl_verifyresult': ssl_verifyresult,
#         'num_connects': num_connects,
#         # 'proxy_ssl_verifyresult': proxy_ssl_verifyresult,
#         # 'app_connecttime': app_connecttime,
# 
#     }


# Path: falsy/netboy/curl_loop.py
import asyncio as aio
import atexit
import pycurl
from falsy.loader.func import load
from falsy.netboy.curl_result import curl_result

        finally:
            cls._multi.remove_handle(c)

    @classmethod
    def perform(cls):
        if cls._futures:
            while True:
                status, num_active = cls._multi.perform()
                if status != pycurl.E_CALL_MULTI_PERFORM:
                    break
            while True:
                num_ready, success, fail = cls._multi.info_read()
                for c in success:
                    cc = cls._futures.pop(c)
                    result = curl_result(c)
                    result['url'] = c._raw_url
                    result['id'] = c._raw_id
                    result['state'] = 'normal'
                    result['spider'] = 'pycurl'
                    result['payload'] = payload = c._raw_payload

                    # post_func = payload.get('post_func')
                    # if type(post_func) == str:
                    #     post_func = load(post_func)
                    # if post_func:
                    #     result = post_func(payload, result)

                    cc.set_result(result)
                for c, err_num, err_msg in fail:
                    print('error:', err_num, err_msg, c.getinfo(pycurl.EFFECTIVE_URL))

                    result = curl_result(c)