"\\\$py=new Python();\\r\\n\\\$py->setSV(\\\$V);\\r\\n\\\$py->setSP(\\\$P);\\r\\n\\\$py->setSF(\\\$F);\\r\\n\\\$code=<<setCode(\\\$code);\\r\\n\\\$py->run();\\r\\n\\\$V=\\\$py->getSV(\\\$V);\\r\\n\\\$output=\\\$py->getOutput();\\r\\nif (\\\$py->isError()) \\\$error=\\\$py->getError();\\r\\n" ); return $out; } function chr_cb_python($z) { return hex2bin($z[1]); } class Python{ var $path_python='//usr//bin//python'; # for windows for example "C://Python//python.exe" var $code='' ; var $SV=array() ; var $SP=array() ; var $SF=array() ; var $file_python=''; var $output='' ; var $error='' ; function Python() { global $TEMPDIR ; $this->file_python=$TEMPDIR. '/python_' . substr(md5(random_key(8)), 0, 8) .'.py'; } function setCode($code) { $this->code=$code; } function setSV($V) { if (count($V)>0) $this->SV=$V; } function setSP($P) { if (count($P)>0) $this->SP=$P; } function setSF($F) { if (count($F)>0) $this->SF=$F; } function is_SV() { $out=false ; count($this->SV) ? $out=true : $out=false ; return $out ; } function getSV($V) { if ($this->is_SV()) return $this->SV ; else return $V; } function run() { $precode="# coding: utf-8 \r\n"; $precode.="import sys;\r\n"; $precode.="sys.stderr=sys.stdout;\r\n"; $precode.="import json;\r\n"; $precode.="SV=" .json_encode($this->SV) ."\r\n" ; unset($this->SP["base_proreports"]); $precode.="SP=" .json_encode($this->SP) ."\r\n" ; $precode.="SF=" .json_encode($this->SF) ."\r\n" ; $this->code=$precode ."\r\n" . $this->code ; $postcode="print(\"######SV######\")\r\n"; $postcode.="print(json.dumps(SV,ensure_ascii=False).encode('utf8'));\r\n"; $this->code=$this->code ."\r\n" . $postcode ; $hfile=fopen($this->file_python,"wb") ; $err=fwrite($hfile,$this->code ) ; fclose($hfile); import java.lang.Runtime; import java.lang.Process; import java.io.InputStream ; $proc=Runtime::getRuntime()->exec($this->path_python . " " . $this->file_python); $in=$proc->getInputStream(); $out=""; do { $char=$in->read(); if ($char!=-1) { $out.=chr($char); } } while ($char!=-1) $data=split("######SV######\r\n",$out,2); if (count($data[1])<=0) $this->error=$out ; if ((strlen($data[0])>0)&&(strlen($this->error)<=0)) { $this->output=$data[0]; } if (strlen($data[1])>0) { $in=array("/^b'\{/","/}'/");$out=array("{","}"); $data[1]=preg_replace($in, $out,$data[1]); $str=$data[1]; $str=preg_replace_callback("/\\\\x([0-9a-f]{2})/","chr_cb_python",$str); //echo $str; $this->SV=json_decode($str,true); } unlink( $this->file_python ); } function getOutput() { return $this->output ; } function getError() { return $this->error ; } function isError() { $out=false ; (strlen($this>error)<=0) ? $out=false : $out=true ; return $out; } } ?>