<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from functools import partial <EOL> from timeit import default_timer as python_timer <EOL> from hug import introspect <EOL> def _built_in_directive ( directive ) : <EOL> """<STR_LIT>""" <EOL> directive . directive = True <EOL> return directive <EOL> @ _built_in_directive <EOL> class Timer ( object ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( '<STR_LIT:start>' , '<STR_LIT>' ) <EOL> def __init__ ( self , round_to = None , ** kwargs ) : <EOL> self . start = python_timer ( ) <EOL> self . round_to = round_to <EOL> def __float__ ( self ) : <EOL> time_taken = python_timer ( ) - self . start <EOL> return round ( time_taken , self . round_to ) if self . round_to else time_taken <EOL> def __int__ ( self ) : <EOL> return int ( round ( float ( self ) ) ) <EOL> def __native_types__ ( self ) : <EOL> return self . __float__ ( ) <EOL> @ _built_in_directive <EOL> def module ( default = None , api = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return api . module if api else default <EOL> @ _built_in_directive <EOL> def api ( default = None , api = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return api if api else default <EOL> @ _built_in_directive <EOL> def api_version ( default = None , api_version = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return api_version <EOL> @ _built_in_directive <EOL> def documentation ( default = None , api_version = None , api = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> api_version = default or api_version <EOL> if api : <EOL> return api . http . documentation ( base_url = "<STR_LIT>" , api_version = api_version ) <EOL> @ _built_in_directive <EOL> def session ( context_name = '<STR_LIT>' , request = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return request and request . context . get ( context_name , None ) <EOL> @ _built_in_directive <EOL> def user ( default = None , request = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return request and request . context . get ( '<STR_LIT:user>' , None ) or default <EOL> @ _built_in_directive <EOL> class CurrentAPI ( object ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , default = None , api_version = None , ** kwargs ) : <EOL> self . api_version = api_version <EOL> self . api = api ( ** kwargs ) <EOL> def __getattr__ ( self , name ) : <EOL> function = self . api . http . versioned . get ( self . api_version , { } ) . get ( name , None ) <EOL> if not function : <EOL> function = self . api . http . versioned . get ( None , { } ) . get ( name , None ) <EOL> if not function : <EOL> raise AttributeError ( '<STR_LIT>' . format ( name ) ) <EOL> accepts = function . interface . arguments <EOL> if '<STR_LIT>' in accepts : <EOL> function = partial ( function , hug_api_version = self . api_version ) <EOL> if '<STR_LIT>' in accepts : <EOL> function = partial ( function , hug_current_api = self ) <EOL> return function </s>
