Skip to content

Commit

Permalink
refactor(pyo3): refactor pyexception to exceptions.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Mar 10, 2024
1 parent bffb1f0 commit 52c7a27
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
17 changes: 17 additions & 0 deletions src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 }
}
}
23 changes: 6 additions & 17 deletions src/models/client.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<u8>,
#[pyo3(get)]
pub olps: String,
#[pyo3(get)]
pub status_code: i32,
}

Expand Down Expand Up @@ -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<u8>, olps: String, status_code: i32) -> Self {
pub fn new(header: String, content: Vec<u8>, olps: String, status_code: i32) -> Self {
Self {
header,
content,
Expand Down

0 comments on commit 52c7a27

Please sign in to comment.