def params_from_signature(sig):
    """
    Takes a method signature, such as ``sig_example``. Returns a list of
    3-tuples, each with a parameter, it's type, and whether it's optional.

    Usage:

    >>> params_from_signature('spam_eggs(arg=<str>, arg2=<str>) -> <str>')
    [('arg', 'str', False), ('arg2', 'str', False)]
    >>>

    """
    try:
        args = re.match(SIG_RE, sig).group('args')
    except AttributeError:
        raise ValueError(
            u'Method signature syntax "{sig}" is incorrect.'.format(sig=sig))
    try:
        lot = []  # Return value ``[(name, type, optional), ...]``
        if len(args) > 0:
            args = args.split(', ')
            opt_flag = False
            for arg in args:
                match = re.match(ARG_RE, arg)
                if match.group('optional') is not None:
                    optional = True
                    opt_flag = True
                else:
                    if opt_flag:  # Optional params already encountered.
                        raise ValueError(
                            u'Required params must come before optional '
                            'params in "{sig}".'.format(sig=sig))
                    optional = False
                lot.append(
                    (match.group('name'), match.group('type'), optional))
        return lot
    except __HOLE__:
        raise ValueError(
            u'Method signature params syntax "{sig}" is incorrect '.format(
                sig=sig))
dataset/ETHPy150Open orokusaki/django-jsonrpc-2-0/jsonrpc/signatures.py/params_from_signature