# Path: core/ngw_error.py
# class NGWError(Exception):
#     TypeUnknownError, TypeRequestError, TypeNGWError, TypeNGWUnexpectedAnswer = list(range(4))
# 
#     def __init__(self, type, message, url=None, user_msg=None, need_reconnect=True):
#         if not isinstance(message, str):
#             self.message = str(message)#, 'utf-8')
#         else:
#             self.message = message
# 
#         self.type = type
#         self.url = url
#         self.user_msg = user_msg
#         self.need_reconnect = need_reconnect
# 
#     def __str__(self):
#         return self.message


import os
import json
import requests
from base64 import b64encode
from requests.utils import to_native_string
from .ngw_error import NGWError
from ..utils import log
            )
        )

        req = requests.Request(method, self.server_url + sub_url, data=payload, json=json_data)

        if all(map(len, self.__auth)):
            req.headers['Authorization'] = _basic_auth_str(self.__auth[0], self.__auth[1])

        prep = self.__session.prepare_request(req)

        try:
            resp = self.__session.send(prep, proxies=self.__proxy)
        except requests.exceptions.ConnectionError:
            raise NGWError(NGWError.TypeRequestError, "Connection error", req.url)
        except requests.exceptions.RequestException as e:
            log( "Response\nerror {}: {}".format(type(e), e) )
            raise NGWError(NGWError.TypeRequestError, "%s" % type(e), req.url)

        if resp.status_code == 502:
            log( "Response\nerror status_code 502" )
            raise NGWError(NGWError.TypeRequestError, "Response status code is 502", req.url)

        if resp.status_code / 100 != 2:
            log("Response\nerror status_code {}\nmsg: {!r}".format(resp.status_code, resp.content))
            raise NGWError(NGWError.TypeNGWError, resp.content, req.url)

        try:
            json_response = resp.json()
        except:
            log("Response\nerror response JSON parse")

# Path: core/ngw_error.py
# class NGWError(Exception):
#     TypeUnknownError, TypeRequestError, TypeNGWError, TypeNGWUnexpectedAnswer = list(range(4))
# 
#     def __init__(self, type, message, url=None, user_msg=None, need_reconnect=True):
#         if not isinstance(message, str):
#             self.message = str(message)#, 'utf-8')
#         else:
#             self.message = message
# 
#         self.type = type
#         self.url = url
#         self.user_msg = user_msg
#         self.need_reconnect = need_reconnect
# 
#     def __str__(self):
#         return self.message


# Path: core/ngw_connection.py
import os
import json
import requests
from base64 import b64encode
from requests.utils import to_native_string
from .ngw_error import NGWError
from ..utils import log

            )
        )

        req = requests.Request(method, self.server_url + sub_url, data=payload, json=json_data)

        if all(map(len, self.__auth)):
            req.headers['Authorization'] = _basic_auth_str(self.__auth[0], self.__auth[1])

        prep = self.__session.prepare_request(req)

        try:
            resp = self.__session.send(prep, proxies=self.__proxy)
        except requests.exceptions.ConnectionError:
            raise NGWError(NGWError.TypeRequestError, "Connection error", req.url)
        except requests.exceptions.RequestException as e:
            log( "Response\nerror {}: {}".format(type(e), e) )
            raise NGWError(NGWError.TypeRequestError, "%s" % type(e), req.url)

        if resp.status_code == 502:
            log( "Response\nerror status_code 502" )
            raise NGWError(NGWError.TypeRequestError, "Response status code is 502", req.url)

        if resp.status_code / 100 != 2:
            log("Response\nerror status_code {}\nmsg: {!r}".format(resp.status_code, resp.content))
            raise NGWError(NGWError.TypeNGWError, resp.content, req.url)

        try:
            json_response = resp.json()
        except:
            log("Response\nerror response JSON parse")

            raise NGWError(NGWError.TypeNGWUnexpectedAnswer, "", req.url)