# Path: lepo/apidef/parameter/base.py
# NO_VALUE = object()
# 
# Path: lepo/excs.py
# class ErroneousParameters(Exception):
#     def __init__(self, error_map, parameters):
#         self.errors = error_map
#         self.parameters = parameters
# 
# class MissingParameter(ValueError):
#     pass


import base64
import iso8601
from django.core.exceptions import ImproperlyConfigured
from django.utils.encoding import force_bytes, force_str
from lepo.apidef.parameter.base import NO_VALUE
from lepo.excs import ErroneousParameters, MissingParameter

def read_parameters(request, view_kwargs=None, capture_errors=False):  # noqa: C901
    """
    :param request: HttpRequest with attached api_info
    :type request: HttpRequest
    :type view_kwargs: dict[str, object]
    :type capture_errors: bool
    :rtype: dict[str, object]
    """
    if view_kwargs is None:
        view_kwargs = {}
    params = {}
    errors = {}
    for param in request.api_info.operation.parameters:
        try:
            value = param.get_value(request, view_kwargs)
            if value is NO_VALUE:
                if param.has_default:
                    params[param.name] = param.default
                elif param.required:  # Required but missing
                    errors[param.name] = MissingParameter(f'parameter {param.name} is required but missing')
                continue  # No value, or a default was added, or an error was added.
            params[param.name] = param.cast(request.api_info.api, value)
        except (NotImplementedError, ImproperlyConfigured):
            raise
        except Exception as e:
            if not capture_errors:
                raise
            errors[param.name] = e
    if errors:

# Path: lepo/apidef/parameter/base.py
# NO_VALUE = object()
# 
# Path: lepo/excs.py
# class ErroneousParameters(Exception):
#     def __init__(self, error_map, parameters):
#         self.errors = error_map
#         self.parameters = parameters
# 
# class MissingParameter(ValueError):
#     pass


# Path: lepo/parameter_utils.py
import base64
import iso8601
from django.core.exceptions import ImproperlyConfigured
from django.utils.encoding import force_bytes, force_str
from lepo.apidef.parameter.base import NO_VALUE
from lepo.excs import ErroneousParameters, MissingParameter


def read_parameters(request, view_kwargs=None, capture_errors=False):  # noqa: C901
    """
    :param request: HttpRequest with attached api_info
    :type request: HttpRequest
    :type view_kwargs: dict[str, object]
    :type capture_errors: bool
    :rtype: dict[str, object]
    """
    if view_kwargs is None:
        view_kwargs = {}
    params = {}
    errors = {}
    for param in request.api_info.operation.parameters:
        try:
            value = param.get_value(request, view_kwargs)
            if value is NO_VALUE:
                if param.has_default:
                    params[param.name] = param.default
                elif param.required:  # Required but missing
                    errors[param.name] = MissingParameter(f'parameter {param.name} is required but missing')
                continue  # No value, or a default was added, or an error was added.
            params[param.name] = param.cast(request.api_info.api, value)
        except (NotImplementedError, ImproperlyConfigured):
            raise
        except Exception as e:
            if not capture_errors:
                raise
            errors[param.name] = e
    if errors:

        raise ErroneousParameters(errors, params)