#include <pylib.h>
Public Member Functions | |
PyObject * | addModule (char *, PyMethodDef *) |
CPyExport () | |
char * | getCodeFromFile (const char *FileName) |
permet d'avoir un poiteur sur le contenu d'un fichier text, le pointeur est à detruir par l'utulisateur. | |
sint32 | getDebugStat () |
return the debug mode status | |
sint32 | getGlobal (char *NameSpace, char *VarName, char *Format, void *VarValue) |
sint32 | getMembreValue (PyObject *Obj, char *AttribName, char *ResFormat, void *ResTarget) |
PyObject * | getRefVar (char *VarName) |
bool | isDebug () |
test debug mode is on | |
sint32 | runCode (const char *Code, char *NameSpace=NULL, sint32 ModeExec=Py_file_input, char *Format=NULL, void *ResultTarget=NULL, sint32 Error=true) |
sint32 | runFunction (char *ModuleName, char *MethodName, char *ResFormat, void *ResTarget, char *Format,...) |
sint32 | runMethod (PyObject *Obj, char *MethodName, char *ResFormat, void *ResTarget, char *Format,...) |
bool | setDebug () |
Put the debug mode on. | |
sint32 | setGlobal (char *NameSpace, char *VarName, char *Format,...) |
sint32 | setMembreValue (PyObject *Obj, char *AttribName, char *ResFormat,...) |
bool | unSetDebug () |
Put the debug mode off. | |
~CPyExport () | |
Static Public Member Functions | |
const char * | getPathSeparator () |
Private Member Functions | |
sint32 | convertResult (PyObject *Result, char *Format, void *Target) |
PyObject * | debugCode (sint32 RunMode, const char *code, PyObject *ModDict) |
PyObject * | debugFunction (PyObject *Func, PyObject *Arg) |
const char * | getNameSpace (const char *Name) const |
PyObject * | loadAttruibut (char *, char *) |
PyObject * | loadModule (char *) |
void | printLastError () |
Private Attributes | |
bool | _DebugMode |
|
Definition at line 57 of file pylib.h. References _DebugMode.
00058 { 00059 _DebugMode = false; 00060 //Py_Initialize(); 00061 _DebugMode = false; 00062 } |
|
Definition at line 218 of file pylib.h.
00219 { 00220 00221 } |
|
Definition at line 299 of file pylib.cpp.
00300 {
00301 return Py_InitModule(ModuleName,DefCodeModule);
00302 }
|
|
Definition at line 63 of file pylib.cpp. References sint32. Referenced by getGlobal(), getMembreValue(), runCode(), runFunction(), and runMethod().
00064 { 00065 if(Result) 00066 { 00067 if(!Target)//nodefaultlib:libcpmtd.lib 00068 { 00069 Py_DECREF(Result); 00070 return 0; 00071 } 00072 if(!PyArg_Parse(Result,Format,Target)) 00073 { 00074 Py_DECREF(Result); 00075 return -1; 00076 } 00077 /*if(!strcmp(Format,"O")) 00078 { 00079 Py_DECREF(Result); 00080 return 0; 00081 }*/ 00082 return 0; 00083 } 00084 00085 return -1; 00086 } |
|
Definition at line 103 of file pylib.cpp. References runFunction(), and sint32. Referenced by runCode().
00104 { 00105 sint32 Stat; 00106 PyObject *Result; 00107 const char *pdbName = (RunMode == Py_eval_input ? "runeval":"run"); 00108 00109 00110 //UnSetDebug(); 00111 Stat = runFunction("pdb",(char *)pdbName,"O",&Result,"(sOO)",code,ModDict,ModDict); 00112 00113 //SetDebug(); 00114 00115 return (Stat != 0) ? NULL : Result; 00116 } |
|
Definition at line 88 of file pylib.cpp. Referenced by runFunction(), and runMethod().
00089 { 00090 /*sint32 oops,res; 00091 PyObject *Result = NULL; 00092 00093 oops = _PyTuple_Resize(&Arg,(1 + PyTuple_Size(Arg))); 00094 oops |= PyTuple_SetItem(Arg,0,Func); 00095 00096 if(oops) return NULL; 00097 00098 res = runFunction("pdb","runcall","O",&Result,"O",Arg);*/ 00099 00100 return NULL;//(res != 0) ? NULL : Result; 00101 } |
|
permet d'avoir un poiteur sur le contenu d'un fichier text, le pointeur est à detruir par l'utulisateur.
Definition at line 304 of file pylib.cpp. References NLMISC::CIFile::getFileSize(), NLMISC::CIFile::serialBuffer(), sint32, uint16, and uint8.
00305 { 00306 uint8 *buf; 00307 char* code; 00308 sint32 si; 00309 uint16 ui,uk; 00310 00311 NLMISC::CIFile f(FileName); 00312 si = f.getFileSize (); 00313 // fseek(f,0,SEEK_END); 00314 // si = ftell(f); 00315 // rewind(f); 00316 buf = new uint8 [si + 1]; 00317 f.serialBuffer(buf, sizeof( uint8 )*si); 00318 buf[si] = 0; 00319 00320 code = new char[si + 1]; 00321 for(ui=0,uk=0; ui < si; ui++) 00322 { 00323 if(buf[ui] != '\r') 00324 { 00325 code[uk] = buf[ui]; 00326 uk ++; 00327 } 00328 } 00329 code[uk] = 0; 00330 return code; 00331 delete buf; 00332 } |
|
return the debug mode status
Definition at line 71 of file pylib.h. References _DebugMode, and sint32.
00072 { 00073 return _DebugMode; 00074 } |
|
Definition at line 252 of file pylib.cpp. References convertResult(), loadAttruibut(), and sint32.
00253 { 00254 PyObject *Var; 00255 00256 Var = loadAttruibut(NameSpace,VarName); 00257 return convertResult(Var,Format,VarValue); 00258 } |
|
get valu of an attribut in an python object.
The method return 0 if Ok; -1 if fail. Definition at line 227 of file pylib.cpp. References convertResult(), and sint32.
00228 { 00229 PyObject *Attrib; 00230 00231 if((Attrib = PyObject_GetAttrString(Obj,AttribName)) == NULL) 00232 { 00233 PyErr_Print (); 00234 return -1; 00235 } 00236 00237 return convertResult(Attrib,ResFormat,ResTarget); 00238 } |
|
Definition at line 43 of file pylib.h. Referenced by loadAttruibut(), and loadModule().
00044 { 00045 return Name == NULL ? "__main__" : Name; 00046 } |
|
Definition at line 334 of file pylib.cpp. References s.
|
|
Definition at line 284 of file pylib.cpp. References runCode(), and NLAIC::stringGetBuild().
00285 { 00286 PyObject *Objet; 00287 std::string text; 00288 text = NLAIC::stringGetBuild("%s",VarName); 00289 runCode(text.c_str(),NULL,Py_eval_input,"O",&Objet); 00290 if(Objet) 00291 { 00292 Py_INCREF(Objet); 00293 return Objet; 00294 } 00295 return NULL; 00296 } |
|
test debug mode is on
Definition at line 84 of file pylib.h. References _DebugMode. Referenced by runCode(), runFunction(), and runMethod().
00085 { 00086 return (_DebugMode == true); 00087 } |
|
Definition at line 53 of file pylib.cpp. References getNameSpace(), and loadModule(). Referenced by getGlobal(), and runFunction().
00054 { 00055 PyObject *Module; 00056 00057 ModeName = (char *)getNameSpace((const char *)ModeName); 00058 Module = loadModule(ModeName); 00059 if(Module == NULL) return NULL; 00060 return PyObject_GetAttrString(Module,Attribut); 00061 } |
|
Definition at line 34 of file pylib.cpp. References getNameSpace(). Referenced by loadAttruibut(), runCode(), and setGlobal().
00035 { 00036 char *Name = (char *)getNameSpace(name); 00037 00038 PyObject *Module; 00039 00040 Module = PyDict_GetItemString(PyImport_GetModuleDict(),Name); 00041 00042 00043 if(strcmp(Name,"__main__") == 0) return PyImport_AddModule(Name); 00044 else 00045 if(Module != NULL && PyDict_GetItemString(Module,"__dummy__")) return Module; 00046 else 00047 { 00048 Module = PyImport_ImportModule(Name); 00049 return Module; 00050 } 00051 } |
|
|
|
Run Python script on debug/release mode depend on _DebugMode status.
Definition at line 148 of file pylib.cpp. References convertResult(), debugCode(), isDebug(), loadModule(), and sint32. Referenced by getRefVar(), and NLAIPYSERVER::initPythonLib().
00149 { 00150 PyObject *Module,*Dict,*Result; 00151 00152 Module = loadModule(NameSpace); 00153 if(Module == NULL) return -1; 00154 00155 Dict = PyModule_GetDict(Module); 00156 00157 if(Dict == NULL) return -1; 00158 00159 if(isDebug()) 00160 { 00161 Result = debugCode(ModeExec,Code,Dict); 00162 } 00163 else Result = PyRun_String((char *)Code,ModeExec,Dict,Dict); 00164 00165 if(Result == NULL) 00166 { 00167 /*if(Error) PrintLastError(); 00168 else PyErr_Print ();*/ 00169 PyErr_Print (); 00170 return -1; 00171 } 00172 else 00173 { 00174 if(ModeExec == Py_file_input) 00175 { 00176 Py_XDECREF(Result); 00177 return 0; 00178 } 00179 else 00180 return convertResult(Result,Format,Target); 00181 } 00182 00183 } |
|
Run a python function on an module.
Definition at line 118 of file pylib.cpp. References convertResult(), debugFunction(), isDebug(), loadAttruibut(), and sint32. Referenced by debugCode().
00119 { 00120 00121 PyObject *Func,*Arg,*Result; 00122 va_list ArgList; 00123 va_start(ArgList,Format); 00124 00125 if((Func = loadAttruibut(ModuleName,MethodName)) == NULL ) return -1; 00126 00127 if((Arg = Py_VaBuildValue(Format,ArgList)) == NULL) 00128 { 00129 Py_DECREF(Func); 00130 return -1; 00131 } 00132 00133 if(isDebug() && strcmp(ModuleName,"pdb")) 00134 { 00135 Result = debugFunction(Func,Arg); 00136 } 00137 else 00138 { 00139 Result = PyEval_CallObject(Func,Arg); 00140 if(!Result) 00141 PyErr_Print (); 00142 } 00143 Py_DECREF(Func); 00144 Py_DECREF(Arg); 00145 return convertResult(Result,ResFormat,ResTarget); 00146 } |
|
Run a python method on a python class.
Definition at line 185 of file pylib.cpp. References convertResult(), debugFunction(), isDebug(), and sint32.
00186 { 00187 if(Obj) 00188 { 00189 /*PyObject *s = PyObject_Str(Obj); 00190 char *S = PyString_AsString(s);*/ 00191 PyObject *Method,*Arg,*Result; 00192 va_list ArgList; 00193 va_start(ArgList,Format); 00194 00195 if((Method = PyObject_GetAttrString(Obj,MethodName)) == NULL) 00196 { 00197 PyErr_Print (); 00198 return -1; 00199 } 00200 00201 if((Arg = Py_VaBuildValue(Format,ArgList)) == NULL) 00202 { 00203 PyErr_Print(); 00204 Py_DECREF(Method); 00205 return -1; 00206 } 00207 00208 if(isDebug()) 00209 { 00210 Result = debugFunction(Method,Arg); 00211 } 00212 else 00213 { 00214 Result = PyEval_CallObject(Method,Arg); 00215 if(!Result) 00216 PyErr_Print (); 00217 } 00218 00219 Py_DECREF(Method); 00220 Py_DECREF(Arg); 00221 00222 return convertResult(Result,ResFormat,ResTarget); 00223 } 00224 return -1; 00225 } |
|
Put the debug mode on.
Definition at line 65 of file pylib.h. References _DebugMode.
00066 { 00067 return (_DebugMode = true); 00068 } |
|
Definition at line 261 of file pylib.cpp. References loadModule(), and sint32.
00262 { 00263 sint32 Result; 00264 PyObject *Module,*Var; 00265 00266 va_list CVals; 00267 va_start(CVals,Format); 00268 00269 if( (Module = loadModule(NameSpace)) == NULL) 00270 return -1; 00271 00272 Var = Py_VaBuildValue(Format,CVals); 00273 va_end(CVals); 00274 00275 if(Var == NULL) 00276 return -1; 00277 00278 Result = PyObject_SetAttrString(Module,VarName,Var); 00279 Py_DECREF(Var); 00280 00281 return Result; 00282 } |
|
Change attribut value of an Python object.
The method return 0 if Ok; -1 if fail. Definition at line 240 of file pylib.cpp. References sint32.
00241 { 00242 PyObject *Val; 00243 00244 va_list ArgList; 00245 va_start(ArgList,ResFormat); 00246 if((Val = Py_VaBuildValue(ResFormat,ArgList)) == NULL) return -1; 00247 sint32 Res = PyObject_SetAttrString(Obj,AttribName,Val); 00248 Py_DECREF(Val); 00249 return Res; 00250 } |
|
Put the debug mode off.
Definition at line 77 of file pylib.h. References _DebugMode.
00078 { 00079 return (_DebugMode = false); 00080 } |
|
Definition at line 41 of file pylib.h. Referenced by CPyExport(), getDebugStat(), isDebug(), setDebug(), and unSetDebug(). |