void ClientUserLua::OutputStat( StrDict *values ) { StrPtr * spec = values->GetVar( "specdef" ); StrPtr * data = values->GetVar( "data" ); StrPtr * sf = values->GetVar( "specFormatted" ); StrDict * dict = values; SpecDataTable specData; Error e; // // Determine whether or not the data we've got contains a spec in one form // or another. 2000.1 -> 2005.1 servers supplied the form in a data variable // and we use the spec variable to parse the form. 2005.2 and later servers // supply the spec ready-parsed but set the 'specFormatted' variable to tell // the client what's going on. Either way, we need the specdef variable set // to enable spec parsing. // int isspec = spec && ( sf || data ); // // Save the spec definition for later // if( spec ) specMgr->AddSpecDef( cmd.Text(), spec->Text() ); // // Parse any form supplied in the 'data' variable and convert it into a // dictionary. // if( spec && data ) { // 2000.1 -> 2005.1 server's handle tagged form output by supplying the form // as text in the 'data' variable. We need to convert it to a dictionary // using the supplied spec. if( P4LUADEBUG_CALLS ) fprintf( stderr, "[P4] OutputStat() - parsing form\n" ); // Parse the form. Use the ParseNoValid() interface to prevent // errors caused by the use of invalid defaults for select items in // jobspecs. //#if P4APIVER_ID >= 513538 Spec s( spec->Text(), "", &e ); //#else //Spec s( spec->Text(), "" ); //#endif if( !e.Test() ) s.ParseNoValid( data->Text(), &specData, &e ); if( e.Test() ) { HandleError( &e ); return; } dict = specData.Dict(); } // // If what we've got is a parsed form, then we'll convert it to a P4::Spec // object. Otherwise it's a plain hash. // if( isspec ) { if( P4LUADEBUG_CALLS ) fprintf(stderr ,"[P4] OutputStat() - Converting to P4::Spec object\n"); results.AddOutput( specMgr->StrDictToSpec( dict, spec ) ); lua_pop( L, 1 ); } else { if( P4LUADEBUG_CALLS ) fprintf(stderr ,"[P4] OutputStat() - Converting to hash\n"); results.AddOutput( specMgr->StrDictToHash( dict ) ); lua_pop( L, 1 ); } }
void PythonClientUser::OutputStat( StrDict *values ) { EnsurePythonLock guard; StrPtr * spec = values->GetVar( "specdef" ); StrPtr * data = values->GetVar( "data" ); StrPtr * sf = values->GetVar( "specFormatted" ); StrDict * dict = values; SpecDataTable specData; Error e; // // Determine whether or not the data we've got contains a spec in one form // or another. 2000.1 -> 2005.1 servers supplied the form in a data variable // and we use the spec variable to parse the form. 2005.2 and later servers // supply the spec ready-parsed but set the 'specFormatted' variable to tell // the client what's going on. Either way, we need the specdef variable set // to enable spec parsing. // int isspec = spec && ( sf || data ); // // Save the spec definition for later // if( spec ) specMgr->AddSpecDef( cmd.Text(), spec->Text() ); // // Parse any form supplied in the 'data' variable and convert it into a // dictionary. // if( spec && data ) { // 2000.1 -> 2005.1 server's handle tagged form output by supplying the form // as text in the 'data' variable. We need to convert it to a dictionary // using the supplied spec. if( P4PYDBG_CALLS ) cerr << "[P4] OutputStat() - parsing form" << endl; // Parse the form. Use the ParseNoValid() interface to prevent // errors caused by the use of invalid defaults for select items in // jobspecs. Spec s( spec->Text(), "", &e ); if( !e.Test() ) s.ParseNoValid( data->Text(), &specData, &e ); if( e.Test() ) { HandleError( &e ); return; } dict = specData.Dict(); } // // If what we've got is a parsed form, then we'll convert it to a P4::Spec // object. Otherwise it's a plain dict. // PyObject * r = 0; if( isspec ) { if( P4PYDBG_CALLS ) cerr << "[P4] OutputStat() - Converting to P4::Spec object" << endl; r = specMgr->StrDictToSpec( dict, spec ); } else { if( P4PYDBG_CALLS ) cerr << "[P4] OutputStat() - Converting to dict" << endl; r = specMgr->StrDictToDict( dict ); } ProcessOutput("outputStat", r ); }