# Path: sevenbridges/errors.py
# class BadRequest(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=400, message=message, more_info=more_info)
# 
# class Unauthorized(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=401, message=message, more_info=more_info
#         )
# 
# class Forbidden(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=403, message=message, more_info=more_info
#         )
# 
# class NotFound(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=404, message=message, more_info=more_info
#         )
# 
# class MethodNotAllowed(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=405, message=message, more_info=more_info
#         )
# 
# class RequestTimeout(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=408, message=message, more_info=more_info
#         )
# 
# class Conflict(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=409, message=message, more_info=more_info
#         )
# 
# class TooManyRequests(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=429, message=message, more_info=more_info
#         )
# 
# class SbgError(Exception):
#     """Base class for SBG errors.
# 
#     Provides a base exception for all errors
#     that are thrown by sevenbridges-python library.
#     """
# 
#     def __init__(self, message=None, code=None, status=None, more_info=None):
#         """
#         :param code: Custom error code
#         :param status: Http status code.
#         :param message: Message describing the error.
#         """
#         self.code = code
#         self.status = status
#         self.message = message
#         self.more_info = more_info
# 
#     def __str__(self):
#         return str(self.message)
# 
# class ServerError(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=500, message=message, more_info=more_info
#         )
# 
# class ServiceUnavailable(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=503, message=message, more_info=more_info
#         )
# 
# class NonJSONResponseError(SbgError):
#     def __init__(self, status, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=status, message=message, more_info=more_info
#         )


import copy
import logging
import functools
import requests
from json import JSONDecodeError
from sevenbridges.errors import (
    BadRequest, Unauthorized, Forbidden, NotFound, MethodNotAllowed,
    RequestTimeout, Conflict, TooManyRequests, SbgError, ServerError,
    ServiceUnavailable, NonJSONResponseError
)
    with data returned from the server.
    """

    # noinspection PyProtectedMember
    def wrapped(obj, *args, **kwargs):
        in_place = True if kwargs.get('inplace') in (True, None) else False
        api_object = method(obj, *args, **kwargs)
        if in_place and api_object:
            obj._data = api_object._data
            obj._dirty = api_object._dirty
            obj._old = copy.deepcopy(api_object._data.data)
            obj._data.fetched = False
            return obj
        elif api_object:
            return api_object
        else:
            return obj

    return wrapped


def throttle(func):
    """Throttles number of parallel requests made by threads from single
    HttpClient session."""

    # noinspection PyProtectedMember
    @functools.wraps(func)
    def wrapper(http_client, *args, **kwargs):
        if http_client._throttle_limit:
            with http_client._throttle_limit:

# Path: sevenbridges/errors.py
# class BadRequest(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=400, message=message, more_info=more_info)
# 
# class Unauthorized(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=401, message=message, more_info=more_info
#         )
# 
# class Forbidden(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=403, message=message, more_info=more_info
#         )
# 
# class NotFound(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=404, message=message, more_info=more_info
#         )
# 
# class MethodNotAllowed(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=405, message=message, more_info=more_info
#         )
# 
# class RequestTimeout(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=408, message=message, more_info=more_info
#         )
# 
# class Conflict(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=409, message=message, more_info=more_info
#         )
# 
# class TooManyRequests(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=429, message=message, more_info=more_info
#         )
# 
# class SbgError(Exception):
#     """Base class for SBG errors.
# 
#     Provides a base exception for all errors
#     that are thrown by sevenbridges-python library.
#     """
# 
#     def __init__(self, message=None, code=None, status=None, more_info=None):
#         """
#         :param code: Custom error code
#         :param status: Http status code.
#         :param message: Message describing the error.
#         """
#         self.code = code
#         self.status = status
#         self.message = message
#         self.more_info = more_info
# 
#     def __str__(self):
#         return str(self.message)
# 
# class ServerError(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=500, message=message, more_info=more_info
#         )
# 
# class ServiceUnavailable(SbgError):
#     def __init__(self, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=503, message=message, more_info=more_info
#         )
# 
# class NonJSONResponseError(SbgError):
#     def __init__(self, status, code=None, message=None, more_info=None):
#         super().__init__(
#             code=code, status=status, message=message, more_info=more_info
#         )


# Path: sevenbridges/decorators.py
import copy
import logging
import functools
import requests
from json import JSONDecodeError
from sevenbridges.errors import (
    BadRequest, Unauthorized, Forbidden, NotFound, MethodNotAllowed,
    RequestTimeout, Conflict, TooManyRequests, SbgError, ServerError,
    ServiceUnavailable, NonJSONResponseError
)

    with data returned from the server.
    """

    # noinspection PyProtectedMember
    def wrapped(obj, *args, **kwargs):
        in_place = True if kwargs.get('inplace') in (True, None) else False
        api_object = method(obj, *args, **kwargs)
        if in_place and api_object:
            obj._data = api_object._data
            obj._dirty = api_object._dirty
            obj._old = copy.deepcopy(api_object._data.data)
            obj._data.fetched = False
            return obj
        elif api_object:
            return api_object
        else:
            return obj

    return wrapped


def throttle(func):
    """Throttles number of parallel requests made by threads from single
    HttpClient session."""

    # noinspection PyProtectedMember
    @functools.wraps(func)
    def wrapper(http_client, *args, **kwargs):
        if http_client._throttle_limit:
            with http_client._throttle_limit:

                return func(http_client, *args, **kwargs)