def _get_current_api_session():
"""
Get an API session, either from the Click context cache, or a new one from the config.
:return: API session
:rtype: APISession
"""
host, token = get_host_and_token()
ctx = click.get_current_context(silent=True) or None
cache_key = force_text('_api_session_%s_%s' % (host, token))
session = (getattr(ctx, cache_key, None) if ctx else None)
if not session:
session = APISession(host, token)
if ctx:
setattr(ctx, cache_key, session)
return session
评论列表
文章目录