# Path: falsy/loader/func.py
# def load(function_name):
# def deep_getattr(obj, attr):
# 
# 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/one.py
# def get_it(payload):
#     if type(payload) is list:
#         payload = payload[0]
#     c = pycurl.Curl()
#     data_buf = BytesIO()
#     # header_buf = BytesIO()
#     headers = {'count': 0, 'content': [{}]}
#     try:
#         setup_curl_for_get(c, payload, data_buf, headers)  # header_buf)
#         c.perform()
# 
#         resp = curl_result(c)
#         resp['url'] = payload.get('url')
#         resp['id'] = payload.get('id')
#         resp['state'] = 'normal'
#         resp['spider'] = 'pycurl'
#         resp['payload'] = payload
# 
#         pycurl_get_resp(data_buf, headers, payload, resp)
#         return resp
#     except pycurl.error as e:
#         resp = curl_result(c)
#         resp['url'] = payload.get('url')
#         resp['id'] = payload.get('id')
#         resp['state'] = 'error'
#         resp['spider'] = 'pycurl'
#         resp['error_code'] = code = e.args[0]
#         resp['error_desc'] = desc = e.args[1]
#         if code in [18, 47]:
#             resp['state'] = 'abnormal'
#             pycurl_get_resp(data_buf, headers, payload, resp)
#         return resp
#     except Exception as e:
#         resp = curl_result(c)
#         resp['url'] = payload.get('url')
#         resp['id'] = payload.get('id')
#         resp['state'] = 'critical'
#         resp['spider'] = 'pycurl'
#         resp['error_code'] = '-1'
#         resp['error_desc'] = 'pycurl re-one exception leaked: ' + str(e) + ' ' + str(type(e))
#         return resp
#     finally:
#         c.close()


import datetime
import json
import socket
import traceback
import html
import pycurl
import uvloop
import websocket
import sys
import asyncio as aio
from concurrent import futures
from logging import Logger
from time import sleep
from urllib.parse import urlparse
from bs4 import UnicodeDammit
from falsy.loader import func
from falsy.netboy.netboy import NetBoy
from falsy.netboy.one import get_it
        ws.send(json.dumps(req))
        resp = self.recv4result(ws)
        return resp

    def new_blank_target(self, ws):
        resp = self.new_target(ws, "about:blank")
        if resp is None or resp.get('error') or resp.get('result') is None or resp.get('result').get(
                'targetId') is None:
            raise ChromeTargetException('chrome target not created!')
        return resp.get('result').get('targetId')

    @property
    def url(self):
        return self._url

    @url.setter
    def url(self, value):
        if type(value) is dict:
            self._url = '%s:%d' % (value.get('host', 'localhost'), value.get('port', 9222))
        elif type(value) is tuple:
            self._url = '%s:%d' % (value[0], value[1])
        elif type(value) is str:
            self._url = value

    def set_user_agent(self, ws, user_agent):
        if user_agent is None:
            return
        req = {}
        req['id'] = self.auto_id()
        req['method'] = 'Network.setUserAgentOverride'

# Path: falsy/loader/func.py
# def load(function_name):
# def deep_getattr(obj, attr):
# 
# 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/one.py
# def get_it(payload):
#     if type(payload) is list:
#         payload = payload[0]
#     c = pycurl.Curl()
#     data_buf = BytesIO()
#     # header_buf = BytesIO()
#     headers = {'count': 0, 'content': [{}]}
#     try:
#         setup_curl_for_get(c, payload, data_buf, headers)  # header_buf)
#         c.perform()
# 
#         resp = curl_result(c)
#         resp['url'] = payload.get('url')
#         resp['id'] = payload.get('id')
#         resp['state'] = 'normal'
#         resp['spider'] = 'pycurl'
#         resp['payload'] = payload
# 
#         pycurl_get_resp(data_buf, headers, payload, resp)
#         return resp
#     except pycurl.error as e:
#         resp = curl_result(c)
#         resp['url'] = payload.get('url')
#         resp['id'] = payload.get('id')
#         resp['state'] = 'error'
#         resp['spider'] = 'pycurl'
#         resp['error_code'] = code = e.args[0]
#         resp['error_desc'] = desc = e.args[1]
#         if code in [18, 47]:
#             resp['state'] = 'abnormal'
#             pycurl_get_resp(data_buf, headers, payload, resp)
#         return resp
#     except Exception as e:
#         resp = curl_result(c)
#         resp['url'] = payload.get('url')
#         resp['id'] = payload.get('id')
#         resp['state'] = 'critical'
#         resp['spider'] = 'pycurl'
#         resp['error_code'] = '-1'
#         resp['error_desc'] = 'pycurl re-one exception leaked: ' + str(e) + ' ' + str(type(e))
#         return resp
#     finally:
#         c.close()


# Path: falsy/netboy/chromeboy.py
import datetime
import json
import socket
import traceback
import html
import pycurl
import uvloop
import websocket
import sys
import asyncio as aio
from concurrent import futures
from logging import Logger
from time import sleep
from urllib.parse import urlparse
from bs4 import UnicodeDammit
from falsy.loader import func
from falsy.netboy.netboy import NetBoy
from falsy.netboy.one import get_it

        ws.send(json.dumps(req))
        resp = self.recv4result(ws)
        return resp

    def new_blank_target(self, ws):
        resp = self.new_target(ws, "about:blank")
        if resp is None or resp.get('error') or resp.get('result') is None or resp.get('result').get(
                'targetId') is None:
            raise ChromeTargetException('chrome target not created!')
        return resp.get('result').get('targetId')

    @property
    def url(self):
        return self._url

    @url.setter
    def url(self, value):
        if type(value) is dict:
            self._url = '%s:%d' % (value.get('host', 'localhost'), value.get('port', 9222))
        elif type(value) is tuple:
            self._url = '%s:%d' % (value[0], value[1])
        elif type(value) is str:
            self._url = value

    def set_user_agent(self, ws, user_agent):
        if user_agent is None:
            return
        req = {}
        req['id'] = self.auto_id()
        req['method'] = 'Network.setUserAgentOverride'

        req['params'] = {"userAgent": user_agent}