#NEWLINE# def parse_inlinefunc( string , strip = False , **kwargs ) : #NEWLINE# #INDENT# '\n    Parse the incoming string.\n\n    Args:\n        string (str): The incoming string to parse.\n        strip (bool, optional): Whether to strip function calls rather than\n            execute them.\n    Kwargs:\n        session (Session): This is sent to this function by Evennia when triggering\n            it. It is passed to the inlinefunc.\n        kwargs (any): All other kwargs are also passed on to the inlinefunc.\n\n\n    ' #NEWLINE# global _PARSING_CACHE #NEWLINE# if ( string in _PARSING_CACHE ) : #NEWLINE# #INDENT# stack = _PARSING_CACHE [ string ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not _RE_STARTTOKEN . search ( string ) ) : #NEWLINE# #INDENT# return string #NEWLINE# #UNINDENT# stack = ParseStack ( ) #NEWLINE# ncallable = 0 #NEWLINE# for match in _RE_TOKEN . finditer ( string ) : #NEWLINE# #INDENT# gdict = match . groupdict ( ) #NEWLINE# if gdict [ 'singlequote' ] : #NEWLINE# #INDENT# stack . append ( gdict [ 'singlequote' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if gdict [ 'doublequote' ] : #NEWLINE# #INDENT# stack . append ( gdict [ 'doublequote' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if gdict [ 'end' ] : #NEWLINE# #INDENT# if ( ncallable <= 0 ) : #NEWLINE# #INDENT# stack . append ( ')' ) #NEWLINE# continue #NEWLINE# #UNINDENT# args = [ ] #NEWLINE# while stack : #NEWLINE# #INDENT# operation = stack . pop ( ) #NEWLINE# if callable ( operation ) : #NEWLINE# #INDENT# if ( not strip ) : #NEWLINE# #INDENT# stack . append ( ( operation , [ arg for arg in reversed ( args ) ] ) ) #NEWLINE# #UNINDENT# ncallable -= 1 #NEWLINE# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# args . append ( operation ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if gdict [ 'start' ] : #NEWLINE# #INDENT# funcname = _RE_STARTTOKEN . match ( gdict [ 'start' ] ) . group ( 1 ) #NEWLINE# try : #NEWLINE# #INDENT# stack . append ( _INLINE_FUNCS [ funcname ] ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# stack . append ( _INLINE_FUNCS [ 'nomatch' ] ) #NEWLINE# stack . append ( funcname ) #NEWLINE# #UNINDENT# ncallable += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if gdict [ 'escaped' ] : #NEWLINE# #INDENT# token = gdict [ 'escaped' ] . lstrip ( '\\' ) #NEWLINE# stack . append ( token ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if gdict [ 'comma' ] : #NEWLINE# #INDENT# if ( ncallable > 0 ) : #NEWLINE# #INDENT# stack . append ( None ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# stack . append ( ',' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# stack . append ( gdict [ 'rest' ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( ncallable > 0 ) : #NEWLINE# #INDENT# return string #NEWLINE# #UNINDENT# if ( ( _STACK_MAXSIZE > 0 ) and ( _STACK_MAXSIZE < len ( stack ) ) ) : #NEWLINE# #INDENT# return ( string + gdict [ 'stackfull' ] ( * args , ** kwargs ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# _PARSING_CACHE [ string ] = stack #NEWLINE# #UNINDENT# #UNINDENT# def _run_stack( item , depth = 0 ) : #NEWLINE# #INDENT# retval = item #NEWLINE# if isinstance ( item , tuple ) : #NEWLINE# #INDENT# if strip : #NEWLINE# #INDENT# return '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( func , arglist ) = item #NEWLINE# args = [ '' ] #NEWLINE# for arg in arglist : #NEWLINE# #INDENT# if ( arg is None ) : #NEWLINE# #INDENT# args . append ( '' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# args [ ( - 1 ) ] += _run_stack ( arg , depth = ( depth + 1 ) ) #NEWLINE# #UNINDENT# #UNINDENT# kwargs [ 'inlinefunc_stack_depth' ] = depth #NEWLINE# retval = ( '' if strip else func ( * args , ** kwargs ) ) #NEWLINE# #UNINDENT# #UNINDENT# return utils . to_str ( retval , force_string = True ) #NEWLINE# #UNINDENT# return '' . join ( ( _run_stack ( item ) for item in _PARSING_CACHE [ string ] ) )