| 71 | |
| 72 | impl ParseValue { |
| 73 | fn from_python(value: &Bound<'_, PyAny>) -> PyResult<Self> { |
| 74 | if value.is_none() { |
| 75 | return Ok(ParseValue::Str("None".to_string())); |
| 76 | } |
| 77 | if let Ok(dict) = value.downcast::<PyDict>() { |
| 78 | let mut items = HashMap::new(); |
| 79 | for (key, item) in dict.iter() { |
| 80 | items.insert(key.extract::<String>()?, ParseValue::from_python(&item)?); |
| 81 | } |
| 82 | return Ok(ParseValue::Map(items)); |
| 83 | } |
| 84 | if let Ok(text) = value.extract::<String>() { |
| 85 | return Ok(ParseValue::Str(text)); |
| 86 | } |
| 87 | if let Ok(number) = value.extract::<i64>() { |
| 88 | return Ok(ParseValue::Int(number)); |
| 89 | } |
| 90 | if let Ok(number) = value.extract::<f64>() { |
| 91 | return Ok(ParseValue::Float(number)); |
| 92 | } |
| 93 | Ok(ParseValue::PyObject(value.clone().unbind())) |
| 94 | } |
| 95 | |
| 96 | /// Convert this ParseValue to a Python object. |
| 97 | pub fn to_pyobject(&self, py: Python<'_>) -> PyObject { |