# Path: cpauto/core/exceptions.py
# class CoreClientError(WebClientError):
#     """Exception raised when an core web client runs into trouble."""
#     pass
# 
# class WaitOnTaskError(CoreClientError):
#     """An error occurred whilst waiting on a task or tasks."""
#     pass
# 
# class ConnectionError(CoreClientError):
#     """A connection error occurred."""
#     pass
# 
# class HTTPError(CoreClientError):
#     """An HTTP error occurred."""
#     pass
# 
# class SSLError(CoreClientError):
#     """An SSL error occurred."""
#     pass
# 
# class Timeout(CoreClientError):
#     """The request timed out."""
#     pass
# 
# class TooManyRedirects(CoreClientError):
#     """Too many redirects."""
#     pass
# 
# class InvalidURL(CoreClientError, ValueError):
#     """The URL provided was invalid."""
#     pass
# 
# Path: cpauto/objects/_common.py
# class _CommonClient:
#     def __init__(self, core_client):
#         self.__core_client = core_client
# 
#     def _add(self, endpoint, name='', params={}):
#         payload = { 'name': name }
#         if params:
#             payload = self.__core_client.merge_payloads(payload, params)
#         return self.__core_client.http_post(endpoint, payload=payload)
# 
#     def _add_with_layer(self, endpoint="", layer="", position="", params={}):
#         payload = { 'layer': layer, 'position': position }
#         if params:
#             payload = self.__core_client.merge_payloads(payload, params)
#         return self.__core_client.http_post(endpoint, payload=payload)
# 
#     def _post_with_layer(self, endpoint='', layer='', name='', uid='', params={}):
#         payload = { 'layer': layer }
#         if name:
#             payload['name'] = name
#         if uid:
#             payload['uid'] = uid
#         if params:
#             payload = self.__core_client.merge_payloads(payload, params)
#         return self.__core_client.http_post(endpoint, payload=payload)
# 
#     def _show(self, endpoint, name='', uid='', details_level='', params={}):
#         payload = {}
#         if name:
#             payload['name'] = name
#         if uid:
#             payload['uid'] = uid
#         if details_level:
#             payload['details-level'] = details_level
#         if params:
#             payload = self.__core_client.merge_payloads(payload, params)
#         return self.__core_client.http_post(endpoint, payload=payload)
# 
#     def _set(self, endpoint, name='', uid='', params={}):
#         payload = {}
#         if name:
#             payload['name'] = name
#         if uid:
#             payload['uid'] = uid
#         if params:
#             payload = self.__core_client.merge_payloads(payload, params)
#         return self.__core_client.http_post(endpoint, payload=payload)
# 
#     def _delete(self, endpoint, name='', uid='', params={}):
#         payload = {}
#         if name:
#             payload['name'] = name
#         if uid:
#             payload['uid'] = uid
#         if params:
#             payload = self.__core_client.merge_payloads(payload, params)
#         return self.__core_client.http_post(endpoint, payload=payload)
# 
#     def _show_all(self, endpoint, limit=50, offset=0, order=[], details_level=''):
#         payload = { 'limit': limit, 'offset': offset }
#         if order:
#             payload['order'] = order
#         if details_level:
#             payload['details-level'] = details_level
#         return self.__core_client.http_post(endpoint, payload=payload)


from .exceptions import (
    CoreClientError,
    WaitOnTaskError,
    ConnectionError,
    HTTPError,
    SSLError,
    Timeout,
    TooManyRedirects,
    InvalidURL
)
from ..objects._common import _CommonClient
import time
import requests

    def __check_task_result(self, task_result):
        data = task_result.json()
        for task in data["tasks"]:
            if task["status"] == "failed" or task["status"] == "partially succeeded":
                task_result.set_success(False)
                task_result.set_message("There was at least one task that failed or partially succeeded")
                break

    def http_post(self, endpoint, send_sid=True, payload={}):
        """Makes an HTTP post to the specified API endpoint using user supplied data.

        :param endpoint: The API endpoint (e.g. /login).
        :param send_sid: Send the session ID as a header when true.
        :param payload: The payload (dictionary) that will be included
            as JSON in the body of the request.
        :rtype: CoreClientResult
        """
        uri = self.__build_uri(endpoint)
        headers = self.__build_headers(send_sid)
        try:
            r = requests.post(uri, headers=headers, json=payload, verify=self.__verify)
            # wait for tasks if needed
            if self.__wait_for_tasks and r.status_code == 200 and endpoint != "show-task":
                data = r.json()
                if "task-id" in data:
                    return self.__wait_on_task(data["task-id"])
                elif "tasks" in data:
                    return self.__wait_on_tasks(data["tasks"])
        except requests.exceptions.SSLError as e:

# Path: cpauto/core/exceptions.py
# class CoreClientError(WebClientError):
#     """Exception raised when an core web client runs into trouble."""
#     pass
# 
# class WaitOnTaskError(CoreClientError):
#     """An error occurred whilst waiting on a task or tasks."""
#     pass
# 
# class ConnectionError(CoreClientError):
#     """A connection error occurred."""
#     pass
# 
# class HTTPError(CoreClientError):
#     """An HTTP error occurred."""
#     pass
# 
# class SSLError(CoreClientError):
#     """An SSL error occurred."""
#     pass
# 
# class Timeout(CoreClientError):
#     """The request timed out."""
#     pass
# 
# class TooManyRedirects(CoreClientError):
#     """Too many redirects."""
#     pass
# 
# class InvalidURL(CoreClientError, ValueError):
#     """The URL provided was invalid."""
#     pass
# 
# Path: cpauto/objects/_common.py
# class _CommonClient:
#     def __init__(self, core_client):
#         self.__core_client = core_client
# 
#     def _add(self, endpoint, name='', params={}):
#         payload = { 'name': name }
#         if params:
#             payload = self.__core_client.merge_payloads(payload, params)
#         return self.__core_client.http_post(endpoint, payload=payload)
# 
#     def _add_with_layer(self, endpoint="", layer="", position="", params={}):
#         payload = { 'layer': layer, 'position': position }
#         if params:
#             payload = self.__core_client.merge_payloads(payload, params)
#         return self.__core_client.http_post(endpoint, payload=payload)
# 
#     def _post_with_layer(self, endpoint='', layer='', name='', uid='', params={}):
#         payload = { 'layer': layer }
#         if name:
#             payload['name'] = name
#         if uid:
#             payload['uid'] = uid
#         if params:
#             payload = self.__core_client.merge_payloads(payload, params)
#         return self.__core_client.http_post(endpoint, payload=payload)
# 
#     def _show(self, endpoint, name='', uid='', details_level='', params={}):
#         payload = {}
#         if name:
#             payload['name'] = name
#         if uid:
#             payload['uid'] = uid
#         if details_level:
#             payload['details-level'] = details_level
#         if params:
#             payload = self.__core_client.merge_payloads(payload, params)
#         return self.__core_client.http_post(endpoint, payload=payload)
# 
#     def _set(self, endpoint, name='', uid='', params={}):
#         payload = {}
#         if name:
#             payload['name'] = name
#         if uid:
#             payload['uid'] = uid
#         if params:
#             payload = self.__core_client.merge_payloads(payload, params)
#         return self.__core_client.http_post(endpoint, payload=payload)
# 
#     def _delete(self, endpoint, name='', uid='', params={}):
#         payload = {}
#         if name:
#             payload['name'] = name
#         if uid:
#             payload['uid'] = uid
#         if params:
#             payload = self.__core_client.merge_payloads(payload, params)
#         return self.__core_client.http_post(endpoint, payload=payload)
# 
#     def _show_all(self, endpoint, limit=50, offset=0, order=[], details_level=''):
#         payload = { 'limit': limit, 'offset': offset }
#         if order:
#             payload['order'] = order
#         if details_level:
#             payload['details-level'] = details_level
#         return self.__core_client.http_post(endpoint, payload=payload)


# Path: cpauto/core/sessions.py
from .exceptions import (
    CoreClientError,
    WaitOnTaskError,
    ConnectionError,
    HTTPError,
    SSLError,
    Timeout,
    TooManyRedirects,
    InvalidURL
)
from ..objects._common import _CommonClient
import time
import requests


    def __check_task_result(self, task_result):
        data = task_result.json()
        for task in data["tasks"]:
            if task["status"] == "failed" or task["status"] == "partially succeeded":
                task_result.set_success(False)
                task_result.set_message("There was at least one task that failed or partially succeeded")
                break

    def http_post(self, endpoint, send_sid=True, payload={}):
        """Makes an HTTP post to the specified API endpoint using user supplied data.

        :param endpoint: The API endpoint (e.g. /login).
        :param send_sid: Send the session ID as a header when true.
        :param payload: The payload (dictionary) that will be included
            as JSON in the body of the request.
        :rtype: CoreClientResult
        """
        uri = self.__build_uri(endpoint)
        headers = self.__build_headers(send_sid)
        try:
            r = requests.post(uri, headers=headers, json=payload, verify=self.__verify)
            # wait for tasks if needed
            if self.__wait_for_tasks and r.status_code == 200 and endpoint != "show-task":
                data = r.json()
                if "task-id" in data:
                    return self.__wait_on_task(data["task-id"])
                elif "tasks" in data:
                    return self.__wait_on_tasks(data["tasks"])
        except requests.exceptions.SSLError as e:

            raise SSLError('SSL error: ' + str(e))