<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def factory(ec, code=None, token=None, refresh=None, **kwargs):
 """ Create a token handler :param code: :param token: :param refresh: :return: TokenHandler instance """


    TTYPE = {'code': 'A', 'token': 'T', 'refresh': 'R'}

    args = {}

    if code:
        args['code_handler'] = init_token_handler(ec, code, TTYPE['code'])
    if token:
        args['access_token_handler'] = init_token_handler(ec, token, TTYPE['token'])
    if refresh:
        args['refresh_token_handler'] = init_token_handler(ec, token, TTYPE['refresh'])

    return TokenHandler(**args)