mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 04:31:05 +08:00
迁移一些
This commit is contained in:
parent
c5de63f02e
commit
75832bfa2e
|
@ -127,7 +127,7 @@ macro_rules! call_py_func {
|
||||||
e,
|
e,
|
||||||
// 获取 traceback
|
// 获取 traceback
|
||||||
match &e {
|
match &e {
|
||||||
PyPluginError::FuncCallError(py_err, _, _) => match py_err.traceback_bound(py) {
|
PyPluginError::FuncCallError(py_err, _, _) => match py_err.traceback(py) {
|
||||||
Some(traceback) => match traceback.format() {
|
Some(traceback) => match traceback.format() {
|
||||||
Ok(trace) => trace,
|
Ok(trace) => trace,
|
||||||
Err(trace_e) => format!("failed to format traceback: {:?}", trace_e),
|
Err(trace_e) => format!("failed to format traceback: {:?}", trace_e),
|
||||||
|
|
|
@ -2,6 +2,7 @@ pub mod call;
|
||||||
pub mod class;
|
pub mod class;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
|
||||||
|
use std::ffi::CString;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
use std::{collections::HashMap, path::PathBuf};
|
||||||
|
@ -133,7 +134,7 @@ impl PyStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_py_err_traceback(py_err: &PyErr) -> String {
|
pub fn get_py_err_traceback(py_err: &PyErr) -> String {
|
||||||
Python::with_gil(|py| match py_err.traceback_bound(py) {
|
Python::with_gil(|py| match py_err.traceback(py) {
|
||||||
Some(traceback) => match traceback.format() {
|
Some(traceback) => match traceback.format() {
|
||||||
Ok(trace) => trace,
|
Ok(trace) => trace,
|
||||||
Err(e) => format!("{:?}", e),
|
Err(e) => format!("{:?}", e),
|
||||||
|
@ -398,11 +399,11 @@ pub fn get_change_time(path: &Path) -> Option<SystemTime> { path.metadata().ok()
|
||||||
|
|
||||||
pub fn py_module_from_code(content: &str, path: &Path) -> PyResult<Py<PyAny>> {
|
pub fn py_module_from_code(content: &str, path: &Path) -> PyResult<Py<PyAny>> {
|
||||||
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
|
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
|
||||||
let module: PyResult<Py<PyAny>> = PyModule::from_code_bound(
|
let module: PyResult<Py<PyAny>> = PyModule::from_code(
|
||||||
py,
|
py,
|
||||||
content,
|
CString::new(content).unwrap().as_c_str(),
|
||||||
&path.to_string_lossy(),
|
CString::new(path.to_string_lossy().as_bytes()).unwrap().as_c_str(),
|
||||||
&path.file_name().unwrap().to_string_lossy(),
|
CString::new(path.file_name().unwrap().to_string_lossy().as_bytes()).unwrap().as_c_str(),
|
||||||
// !!!! 请注意, 一定要给他一个名字, cpython 会自动把后面的重名模块覆盖掉前面的
|
// !!!! 请注意, 一定要给他一个名字, cpython 会自动把后面的重名模块覆盖掉前面的
|
||||||
)
|
)
|
||||||
.map(|module| module.into());
|
.map(|module| module.into());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user