diff --git a/src/exceptions.rs b/src/exceptions.rs index d40c8ab..b8db0d3 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -3,6 +3,8 @@ use ring::error::Unspecified; use scrypt::errors::InvalidOutputLen; use thiserror::Error; +#[cfg(feature = "python")] +use pyo3::prelude::*; /// ## Oblivion exception iterator /// Use an iterator as the type of exception returned by a function. @@ -54,3 +56,18 @@ pub enum OblivionException { #[error("Exception while decrypting: {error:?}")] DecryptError { error: Unspecified }, } + +#[cfg(feature = "python")] +#[pyclass] +pub struct PyOblivionException { + pub message: String, +} + +#[cfg(feature = "python")] +#[pymethods] +impl PyOblivionException { + #[new] + fn new(message: String) -> Self { + Self { message } + } +} diff --git a/src/models/client.rs b/src/models/client.rs index 11e9045..b131176 100644 --- a/src/models/client.rs +++ b/src/models/client.rs @@ -1,7 +1,7 @@ //! # Oblivion Client use crate::models::packet::{OED, OKE, OSC}; -use crate::exceptions::OblivionException; +use crate::exceptions::{OblivionException, PyOblivionException}; use crate::utils::gear::Socket; use crate::utils::generator::generate_key_pair; @@ -20,9 +20,13 @@ use serde_json::{json, Value}; #[cfg_attr(feature = "python", pyclass)] pub struct Response { + #[pyo3(get)] pub header: String, + #[pyo3(get)] pub content: Vec, + #[pyo3(get)] pub olps: String, + #[pyo3(get)] pub status_code: i32, } @@ -62,26 +66,11 @@ impl Response { } } -#[cfg(feature = "python")] -#[pyclass] -pub struct PyOblivionException { - pub message: String, -} - -#[cfg(feature = "python")] -#[pymethods] -impl PyOblivionException { - #[new] - fn new(message: String) -> Self { - Self { message } - } -} - #[cfg(feature = "python")] #[pymethods] impl Response { #[new] - fn new(header: String, content: Vec, olps: String, status_code: i32) -> Self { + pub fn new(header: String, content: Vec, olps: String, status_code: i32) -> Self { Self { header, content,