peony/requests.py
def sanitize_params(method, **kwargs):
        """
            Request params can be extracted from the ``**kwargs``

        Arguments starting with `_` will be stripped from it, so they
        can be used as an argument for the request
        (eg. "_headers" → "headers" in the kwargs returned by this
        function while "headers" would be inserted into the parameters
        of the request)

        Parameters
        ----------
        method : str
            method to use to make the request
        kwargs : dict
            Keywords arguments given to the request

        Returns
        -------
        dict
            New requests parameters, correctly formatted
        """
        # items which does not have a key starting with `_`
        items = [(key, value) for key, value in kwargs.items()
                 if not key.startswith("_")]
        params, skip_params = {}, False

        for key, value in items:
            # binary data
            if hasattr(value, 'read') or isinstance(value, bytes):
                params[key] = value
                # The params won't be used to make the signature
                skip_params = True

            # booleans conversion
            elif isinstance(value, bool):
                params[key] = "true" if value else "false"

            # iterables conversion
            elif isinstance(value, iterable):
                params[key] = ",".join(map(str, value))

            # skip params with value None
            elif value is None:
                pass

            # the rest is converted to str
            # (make sure you don't send something wrong)
            else:
                params[key] = str(value)

        # dict with other items (+ strip "_" from keys)
        kwargs = {key[1:]: value for key, value in kwargs.items()
                  if key.startswith("_")}

        if method == "post" and not kwargs.get('data', None) and params:
            kwargs['data'] = params  # post requests use the data argument

        elif not kwargs.get('params', None) and params:
            kwargs['params'] = params

        return kwargs, skip_params
def sanitize_params(method, **kwargs):
        """
            Request params can be extracted from the ``**kwargs``

        Arguments starting with `_` will be stripped from it, so they
        can be used as an argument for the request
        (eg. "_headers" → "headers" in the kwargs returned by this
        function while "headers" would be inserted into the parameters
        of the request)

        Parameters
        ----------
        method : str
            method to use to make the request
        kwargs : dict
            Keywords arguments given to the request

        Returns
        -------
        dict
            New requests parameters, correctly formatted
        """
        # items which does not have a key starting with `_`
        items = [(key, value) for key, value in kwargs.items()
                 if not key.startswith("_")]
        params, skip_params = {}, False

        for key, value in items:
            # binary data
            if hasattr(value, 'read') or isinstance(value, bytes):
                params[key] = value
                # The params won't be used to make the signature
                skip_params = True

            # booleans conversion
            elif isinstance(value, bool):
                params[key] = "true" if value else "false"

            # iterables conversion
            elif isinstance(value, iterable):
                params[key] = ",".join(map(str, value))

            # skip params with value None
            elif value is None:
                pass

            # the rest is converted to str
            # (make sure you don't send something wrong)
            else:
                params[key] = str(value)

        # dict with other items (+ strip "_" from keys)
        kwargs = {key[1:]: value for key, value in kwargs.items()
                  if key.startswith("_")}

        if method == "post" and not kwargs.get('data', None) and params:
            kwargs['data'] = params  # post requests use the data argument

        elif not kwargs.get('params', None) and params:
            kwargs['params'] = params

        return kwargs, skip_params
Request params can be extracted from the ``**kwargs``

        Arguments starting with `_` will be stripped from it, so they
        can be used as an argument for the request
        (eg. "_headers" → "headers" in the kwargs returned by this
        function while "headers" would be inserted into the parameters
        of the request)

        Parameters
        ----------
        method : str
            method to use to make the request
        kwargs : dict
            Keywords arguments given to the request

        Returns
        -------
        dict
            New requests parameters, correctly formatted