# Path: stackimpact/utils.py
# def timestamp():
#     return int(time.time())
# 
# def base64_encode(s):
#     return base64.b64encode(s.encode('utf-8')).decode('utf-8')
# 
# Path: stackimpact/runtime.py
# class runtime_info(object):
#     OS_LINUX = (sys.platform.startswith('linux'))
#     OS_DARWIN = (sys.platform == 'darwin')
#     OS_WIN = (sys.platform == 'win32')
#     PYTHON_2 = (sys.version_info.major == 2)
#     PYTHON_3 = (sys.version_info.major == 3)
#     GEVENT = False


import json
import gzip
import sys
import os
import socket
from io import BytesIO
from .utils import timestamp, base64_encode
from .runtime import runtime_info
    from urllib2 import urlopen
    from urllib2 import Request
    from urllib import urlencode
    from urllib.request import urlopen
    from urllib.request import Request
    from urllib.parse import urlencode
        except Exception:
            self.agent.exception()

        req_body = {
            'runtime_type':    'python',
            'runtime_version': '{0.major}.{0.minor}.{0.micro}'.format(sys.version_info),
            'runtime_path':    sys.prefix,
            'agent_version':   self.agent.AGENT_VERSION,
            'app_name':        self.agent.get_option('app_name'),
            'app_version':     self.agent.get_option('app_version'),
            'app_environment': self.agent.get_option('app_environment'),
            'host_name':       self.agent.get_option('host_name', host_name),
            'process_id':      os.getpid(),
            'run_id':          self.agent.run_id,
            'run_ts':          self.agent.run_ts,
            'sent_at':         timestamp(),
            'payload':         payload,
        }

        gzip_out = BytesIO()
        with gzip.GzipFile(fileobj=gzip_out, mode="w") as out_file:
          out_file.write(json.dumps(req_body).encode('utf-8'))
          out_file.close()

        gzip_out_val = gzip_out.getvalue()
        if isinstance(gzip_out_val, str):
            req_body_gzip = bytearray(gzip_out.getvalue())
        else:
            req_body_gzip = gzip_out.getvalue()


# Path: stackimpact/utils.py
# def timestamp():
#     return int(time.time())
# 
# def base64_encode(s):
#     return base64.b64encode(s.encode('utf-8')).decode('utf-8')
# 
# Path: stackimpact/runtime.py
# class runtime_info(object):
#     OS_LINUX = (sys.platform.startswith('linux'))
#     OS_DARWIN = (sys.platform == 'darwin')
#     OS_WIN = (sys.platform == 'win32')
#     PYTHON_2 = (sys.version_info.major == 2)
#     PYTHON_3 = (sys.version_info.major == 3)
#     GEVENT = False


# Path: stackimpact/api_request.py
import json
import gzip
import sys
import os
import socket
from io import BytesIO
from .utils import timestamp, base64_encode
from .runtime import runtime_info
    from urllib2 import urlopen
    from urllib2 import Request
    from urllib import urlencode
    from urllib.request import urlopen
    from urllib.request import Request
    from urllib.parse import urlencode

        except Exception:
            self.agent.exception()

        req_body = {
            'runtime_type':    'python',
            'runtime_version': '{0.major}.{0.minor}.{0.micro}'.format(sys.version_info),
            'runtime_path':    sys.prefix,
            'agent_version':   self.agent.AGENT_VERSION,
            'app_name':        self.agent.get_option('app_name'),
            'app_version':     self.agent.get_option('app_version'),
            'app_environment': self.agent.get_option('app_environment'),
            'host_name':       self.agent.get_option('host_name', host_name),
            'process_id':      os.getpid(),
            'run_id':          self.agent.run_id,
            'run_ts':          self.agent.run_ts,
            'sent_at':         timestamp(),
            'payload':         payload,
        }

        gzip_out = BytesIO()
        with gzip.GzipFile(fileobj=gzip_out, mode="w") as out_file:
          out_file.write(json.dumps(req_body).encode('utf-8'))
          out_file.close()

        gzip_out_val = gzip_out.getvalue()
        if isinstance(gzip_out_val, str):
            req_body_gzip = bytearray(gzip_out.getvalue())
        else:
            req_body_gzip = gzip_out.getvalue()


        request = Request(