# Path: falsy/netboy/fetch.py
# async def get_boy(payload):
#     targets = []
#     for p in payload:
#         targets.append(get_request(p))
#     res = await aio.gather(
#         *targets, return_exceptions=True
#     )
#     return res
# 
# async def post_boy(payload):
#     targets = []
#     for p in payload:
#         targets.append(post_request(p))
#     res = await aio.gather(
#         *targets, return_exceptions=True
#     )
#     return res
# 
# async def net_boy(payload, share=None):
#     targets = []
#     for p in payload:
#         if p.get('postfields'):
#             targets.append(post_request(p, share))
#         else:
#             targets.append(get_request(p, share))
#     res = await aio.gather(
#         *targets, return_exceptions=True
#     )
#     return res
# 
# Path: falsy/netboy/netboy.py
# class NetBoy:
#     class Exception(Exception):
#         pass
# 
#     class Dict(typing.Dict[str, typing.Any]):
#         def __getattr__(self, name):
#             # type: (str) -> Any
#             try:
#                 return self[name]
#             except KeyError:
#                 # raise NetBoy.Exception('netboy key error: ' + name)
#                 return None  # '!netboy key [' + name + '] does not exist'
#             except Exception:
#                 raise NetBoy.Exception('netboy exception: ' + name)
# 
#         def __setattr__(self, name, value):
#             # type: (str, Any) -> None
#             self[name] = value
# 
#     def __init__(self, payload=None, share=None):
#         self.payload = payload
#         if share:
#             s = pycurl.CurlShare()
#             s.setopt(pycurl.SH_SHARE, pycurl.LOCK_DATA_COOKIE)
#             s.setopt(pycurl.SH_SHARE, pycurl.LOCK_DATA_DNS)
#             s.setopt(pycurl.SH_SHARE, pycurl.LOCK_DATA_SSL_SESSION)
#             self.share = s
#         else:
#             self.share = None
# 
#     def run(self, payload=None, loop=None):
#         real_payload = payload
#         if self.payload is None:
#             real_payload = payload
#         elif payload is None:
#             real_payload = self.payload
#         else:
#             real_payload = self.payload + payload
#         ress = run(net_boy(real_payload, self.share), loop=loop)
#         obj_ress = []
#         for v in ress:
#             if type(v) == CurlLoop.CurlException:
#                 boy = NetBoy.Dict(v.data)
#                 # boy['payload'] = real_payload
#                 obj_ress.append(boy)
#             elif type(v) == dict:
#                 boy = NetBoy.Dict(v)
#                 obj_ress.append(boy)
#                 # else:
#                 #     boy = NetBoy.Dict({
#                 #         'state': 'critical',
#                 #         'spider': 'pycurl',
#                 #         'error_code': -1,
#                 #         'error_desc': "{} - {}".format(type(v), str(v)),
#                 #         'payload': real_payload
#                 #     })
#                 #     obj_ress.append(boy)
#         return obj_ress
# 
# Path: falsy/netboy/run.py
# def run(coro, loop=None):
#     async def main_task():
#         pycurl_task = aio.ensure_future(curl_loop())
#         try:
#             r = await coro
#         finally:
#             pycurl_task.cancel()
#             with suppress(aio.CancelledError):
#                 await pycurl_task
#         return r, pycurl_task
# 
#     if loop is None:
#         loop = uvloop.new_event_loop()
#         # loop = aio.get_event_loop()
#     aio.set_event_loop(loop)
#     loop.set_exception_handler(exception_handler)
#     r, _ = loop.run_until_complete(main_task())
#     return r


import json
from falsy.netboy.fetch import get_boy, post_boy, net_boy
from falsy.netboy.netboy import NetBoy
from falsy.netboy.run import run


if __name__ == "__main__":
    payload = [
        # {
        #     "url": "http://172.30.0.77:8003/v1/validate",
        #     "postfields": {
        #         "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0OTE4ODg2ODQsImNvZGVfaWQiOiJjYWYwZTZlOC0wYTEzLTExZTctOTVhNy0xYzg3MmM3MTBhNDgifQ.SkwAtOX8JW4ZRb2S4cftg7PGveU21DZKzlrBYRK6S9I"
        #     },
        #
        #     'id':2
        # },
        # {
        #     'url': 'http://www.douban.com',
        #     'dns_servers': '114.114.114.114'
        # },
        {
            'url': 'http://www.baidu.com',
        },
        {
            'url': 'http://www.douban.com',
        },
        # {
        #     'url': 'http://www.google.com',
        #     'dns_servers': '114.114.114.114',
        #     'id':1
        # },
    ]
    # payload=[{'url': 'http://lwjk.hncd.cn:8091/hnjtyjws', 'useragent': 'Mozilla/5.0', 'followlocation': 0, 'aiohttp_timeout': 60, 'connecttimeout': 30, 'timeout': 30}]

# Path: falsy/netboy/fetch.py
# async def get_boy(payload):
#     targets = []
#     for p in payload:
#         targets.append(get_request(p))
#     res = await aio.gather(
#         *targets, return_exceptions=True
#     )
#     return res
# 
# async def post_boy(payload):
#     targets = []
#     for p in payload:
#         targets.append(post_request(p))
#     res = await aio.gather(
#         *targets, return_exceptions=True
#     )
#     return res
# 
# async def net_boy(payload, share=None):
#     targets = []
#     for p in payload:
#         if p.get('postfields'):
#             targets.append(post_request(p, share))
#         else:
#             targets.append(get_request(p, share))
#     res = await aio.gather(
#         *targets, return_exceptions=True
#     )
#     return res
# 
# Path: falsy/netboy/netboy.py
# class NetBoy:
#     class Exception(Exception):
#         pass
# 
#     class Dict(typing.Dict[str, typing.Any]):
#         def __getattr__(self, name):
#             # type: (str) -> Any
#             try:
#                 return self[name]
#             except KeyError:
#                 # raise NetBoy.Exception('netboy key error: ' + name)
#                 return None  # '!netboy key [' + name + '] does not exist'
#             except Exception:
#                 raise NetBoy.Exception('netboy exception: ' + name)
# 
#         def __setattr__(self, name, value):
#             # type: (str, Any) -> None
#             self[name] = value
# 
#     def __init__(self, payload=None, share=None):
#         self.payload = payload
#         if share:
#             s = pycurl.CurlShare()
#             s.setopt(pycurl.SH_SHARE, pycurl.LOCK_DATA_COOKIE)
#             s.setopt(pycurl.SH_SHARE, pycurl.LOCK_DATA_DNS)
#             s.setopt(pycurl.SH_SHARE, pycurl.LOCK_DATA_SSL_SESSION)
#             self.share = s
#         else:
#             self.share = None
# 
#     def run(self, payload=None, loop=None):
#         real_payload = payload
#         if self.payload is None:
#             real_payload = payload
#         elif payload is None:
#             real_payload = self.payload
#         else:
#             real_payload = self.payload + payload
#         ress = run(net_boy(real_payload, self.share), loop=loop)
#         obj_ress = []
#         for v in ress:
#             if type(v) == CurlLoop.CurlException:
#                 boy = NetBoy.Dict(v.data)
#                 # boy['payload'] = real_payload
#                 obj_ress.append(boy)
#             elif type(v) == dict:
#                 boy = NetBoy.Dict(v)
#                 obj_ress.append(boy)
#                 # else:
#                 #     boy = NetBoy.Dict({
#                 #         'state': 'critical',
#                 #         'spider': 'pycurl',
#                 #         'error_code': -1,
#                 #         'error_desc': "{} - {}".format(type(v), str(v)),
#                 #         'payload': real_payload
#                 #     })
#                 #     obj_ress.append(boy)
#         return obj_ress
# 
# Path: falsy/netboy/run.py
# def run(coro, loop=None):
#     async def main_task():
#         pycurl_task = aio.ensure_future(curl_loop())
#         try:
#             r = await coro
#         finally:
#             pycurl_task.cancel()
#             with suppress(aio.CancelledError):
#                 await pycurl_task
#         return r, pycurl_task
# 
#     if loop is None:
#         loop = uvloop.new_event_loop()
#         # loop = aio.get_event_loop()
#     aio.set_event_loop(loop)
#     loop.set_exception_handler(exception_handler)
#     r, _ = loop.run_until_complete(main_task())
#     return r


# Path: falsy/netboy/simple.py
import json
from falsy.netboy.fetch import get_boy, post_boy, net_boy
from falsy.netboy.netboy import NetBoy
from falsy.netboy.run import run



if __name__ == "__main__":
    payload = [
        # {
        #     "url": "http://172.30.0.77:8003/v1/validate",
        #     "postfields": {
        #         "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0OTE4ODg2ODQsImNvZGVfaWQiOiJjYWYwZTZlOC0wYTEzLTExZTctOTVhNy0xYzg3MmM3MTBhNDgifQ.SkwAtOX8JW4ZRb2S4cftg7PGveU21DZKzlrBYRK6S9I"
        #     },
        #
        #     'id':2
        # },
        # {
        #     'url': 'http://www.douban.com',
        #     'dns_servers': '114.114.114.114'
        # },
        {
            'url': 'http://www.baidu.com',
        },
        {
            'url': 'http://www.douban.com',
        },
        # {
        #     'url': 'http://www.google.com',
        #     'dns_servers': '114.114.114.114',
        #     'id':1
        # },
    ]
    # payload=[{'url': 'http://lwjk.hncd.cn:8091/hnjtyjws', 'useragent': 'Mozilla/5.0', 'followlocation': 0, 'aiohttp_timeout': 60, 'connecttimeout': 30, 'timeout': 30}]

    boy=NetBoy(payload, share=True)