from typing import Union
from typing import List
from typing import Tuple
from typing import Any


def to_keyval(ob: Union[dict, List[Tuple[Any, Any]]], valsplit=':', csvsplit=',') -> str:
    """
    Convert a :class:`.dict` , or a :class:`.list` of two value :class:`.tuple` 's
    into a "key value" string, which can be parsed by :func:`privex.helpers.common.parse_keyval`
    or manually with a small amount of python.

    Example::

        >>> d = dict(hello='world', lorem=123, ipsum='dolor')
        >>> to_keyval(d)
        'hello:world,lorem:123,ipsum:dolor'
        >>> to_keyval(d, valsplit='=', csvsplit='/')
        hello=world/lorem=123/ipsum=dolor

    """
    xo = ob.items() if isinstance(ob, dict) else ob
    return csvsplit.join([f'{k}{valsplit}{v}' for k, v in xo])