Skip to content

Commit ca07adf

Browse files
committed
chore: organise rust file
order crate and imports
1 parent 99281fe commit ca07adf

10 files changed

Lines changed: 70 additions & 74 deletions

File tree

src/catcher.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::Status;
21
use pyo3::prelude::*;
32
use pyo3_stub_gen::derive::*;
43

4+
use crate::Status;
5+
56
/// A catcher for handling specific HTTP status codes.
67
///
78
/// Catchers allow you to provide custom responses for specific HTTP status codes.

src/cors.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::response::Response;
21
use pyo3::prelude::*;
32
use pyo3_stub_gen::derive::*;
43

4+
use crate::response::Response;
5+
56
/// Cross-Origin Resource Sharing (CORS) configuration.
67
///
78
/// This class allows you to configure CORS headers for your server to control

src/jwt.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1+
use std::str::FromStr;
2+
use std::time::{Duration, SystemTime, UNIX_EPOCH};
3+
14
use jsonwebtoken::errors::ErrorKind;
25
use jsonwebtoken::{Algorithm, DecodingKey, EncodingKey, Header, Validation};
36
use pyo3::exceptions::PyException;
7+
use pyo3::prelude::*;
48
use pyo3::types::PyDict;
5-
use pyo3::{exceptions::PyValueError, prelude::*};
69
use pyo3_stub_gen::derive::*;
710
use serde::{Deserialize, Serialize};
811
use serde_json::Value;
912

10-
use std::str::FromStr;
11-
use std::time::{Duration, SystemTime, UNIX_EPOCH};
12-
13-
use crate::exceptions::IntoPyException;
1413
use crate::json;
1514

1615
/// Base class for all JWT related exceptions.
@@ -90,11 +89,10 @@ impl Jwt {
9089
#[pyo3(signature = (secret, algorithm="HS256"))]
9190
pub fn new(secret: String, algorithm: &str) -> PyResult<Self> {
9291
if secret.is_empty() {
93-
return Err(PyValueError::new_err("Secret key cannot be empty"));
92+
return Err(JwtError::new_err("Secret key cannot be empty"));
9493
}
95-
96-
let algorithm = Algorithm::from_str(algorithm).into_py_exception()?;
97-
94+
let algorithm =
95+
Algorithm::from_str(algorithm).map_err(|err| JwtError::new_err(err.to_string()))?;
9896
Ok(Self { secret, algorithm })
9997
}
10098

src/lib.rs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
use std::net::SocketAddr;
2+
use std::ops::Deref;
3+
use std::sync::Arc;
4+
use std::sync::atomic::{AtomicBool, Ordering};
5+
6+
use ahash::HashMap;
7+
use pyo3::exceptions::PyValueError;
8+
use pyo3::prelude::*;
9+
use pyo3::types::{PyDict, PyInt, PyString};
10+
use pyo3_async_runtimes::tokio::{future_into_py, into_future};
11+
use pyo3_stub_gen::derive::*;
12+
use tokio::net::{TcpListener, TcpStream};
13+
use tokio::sync::Semaphore;
14+
use tokio::sync::mpsc::{Receiver, Sender, channel};
15+
16+
use catcher::Catcher;
17+
use cors::Cors;
18+
use exceptions::IntoPyException;
19+
use into_response::convert_to_response;
20+
use middleware::MiddlewareChain;
21+
use multipart::File;
22+
use request::{Request, RequestBuilder};
23+
use response::{FileStreaming, Redirect, Response};
24+
use routing::*;
25+
use session::{Session, SessionStore};
26+
use status::Status;
27+
use templating::Template;
28+
129
mod catcher;
230
mod cors;
331
#[macro_use]
@@ -15,35 +43,6 @@ mod session;
1543
mod status;
1644
mod templating;
1745

18-
use std::net::SocketAddr;
19-
use std::ops::Deref;
20-
use std::sync::Arc;
21-
use std::sync::atomic::{AtomicBool, Ordering};
22-
23-
use pyo3::exceptions::PyValueError;
24-
use pyo3::prelude::*;
25-
use pyo3::types::{PyDict, PyInt, PyString};
26-
use pyo3_async_runtimes::tokio::{future_into_py, into_future};
27-
use pyo3_stub_gen::derive::*;
28-
29-
use ahash::HashMap;
30-
use tokio::net::{TcpListener, TcpStream};
31-
use tokio::sync::Semaphore;
32-
use tokio::sync::mpsc::{Receiver, Sender, channel};
33-
34-
use crate::catcher::Catcher;
35-
use crate::cors::Cors;
36-
use crate::exceptions::IntoPyException;
37-
use crate::into_response::convert_to_response;
38-
use crate::middleware::MiddlewareChain;
39-
use crate::multipart::File;
40-
use crate::request::{Request, RequestBuilder};
41-
use crate::response::{FileStreaming, Redirect, Response};
42-
use crate::routing::*;
43-
use crate::session::{Session, SessionStore};
44-
use crate::status::Status;
45-
use crate::templating::Template;
46-
4746
pyo3_stub_gen::define_stub_info_gatherer!(stub_info);
4847

4948
struct ProcessRequest {

src/multipart.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use crate::IntoPyException;
21
use ahash::HashMap;
32
use futures_util::stream;
43
use hyper::body::Bytes;
54
use pyo3::{exceptions::PyValueError, prelude::*, types::PyBytes};
65
use pyo3_stub_gen::derive::*;
76

7+
use crate::IntoPyException;
8+
89
/// Represents an uploaded file in a multipart/form-data request.
910
///
1011
/// The File class provides access to uploaded file data, including the file name,

src/response.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
use futures_util::StreamExt;
2-
use http_body_util::combinators::BoxBody;
3-
use hyper::body::Frame;
4-
use hyper::http::HeaderValue;
1+
use std::convert::Infallible;
2+
use std::fs;
3+
use std::io::Read;
4+
use std::str::{self, FromStr};
5+
use std::sync::Arc;
6+
7+
use futures_util::{StreamExt, stream};
8+
use http_body_util::{BodyExt, Full, StreamBody, combinators::BoxBody};
59
use hyper::{
610
HeaderMap,
7-
body::Bytes,
8-
header::{CONTENT_TYPE, HeaderName, LOCATION},
11+
body::{Bytes, Frame},
12+
header::{CACHE_CONTROL, CONTENT_TYPE, HeaderName, LOCATION},
13+
http::HeaderValue,
914
};
10-
11-
use futures_util::stream;
12-
use http_body_util::{BodyExt, Full, StreamBody};
13-
use hyper::header::CACHE_CONTROL;
1415
use pyo3::exceptions::PyTypeError;
1516
use pyo3::prelude::*;
1617
use pyo3::types::{PyBytes, PyString};
1718
use pyo3_stub_gen::derive::*;
1819

19-
use std::convert::Infallible;
20-
use std::fs;
21-
use std::io::Read;
22-
use std::str::{self, FromStr};
23-
use std::sync::Arc;
24-
2520
use crate::{Cors, IntoPyException, ProcessRequest, Request, Status, convert_to_response, json};
2621

2722
pub type Body = BoxBody<Bytes, Infallible>;

src/serializer/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
mod fields;
2-
31
use std::sync::{Arc, Mutex};
42

53
use ahash::HashMap;
6-
7-
use self::fields::*;
8-
use crate::{IntoPyException, exceptions::ClientError, json};
9-
104
use pyo3::{
115
IntoPyObjectExt,
126
exceptions::PyException,
@@ -17,6 +11,11 @@ use pyo3::{
1711
use pyo3_stub_gen::derive::*;
1812
use serde_json::{Map, Value, json};
1913

14+
use self::fields::*;
15+
use crate::{IntoPyException, exceptions::ClientError, json};
16+
17+
mod fields;
18+
2019
static SQL_ALCHEMY_INSPECT: PyOnceLock<Py<PyAny>> = PyOnceLock::new();
2120

2221
#[gen_stub_pyclass]

src/templating/minijinja.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use ahash::HashMap;
1+
use std::sync::Arc;
22

3+
use ahash::HashMap;
34
use minijinja::Environment;
45
use pyo3::{prelude::*, types::PyDict};
56
use pyo3_stub_gen::derive::*;
6-
use std::sync::Arc;
77

88
use crate::IntoPyException;
99
use crate::json;

src/templating/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
use crate::{
2-
request::Request,
3-
response::{Response, ResponseBody},
4-
status::Status,
5-
};
6-
use hyper::{header::CONTENT_TYPE, HeaderMap};
1+
use hyper::{HeaderMap, header::CONTENT_TYPE};
72
use pyo3::{
3+
Bound, PyResult,
84
exceptions::{PyException, PyValueError},
95
prelude::*,
106
types::{PyDict, PyModule, PyModuleMethods},
11-
Bound, PyResult,
127
};
138
use pyo3_stub_gen::derive::*;
149

10+
use crate::{
11+
request::Request,
12+
response::{Response, ResponseBody},
13+
status::Status,
14+
};
15+
1516
mod minijinja;
1617
mod tera;
1718

src/templating/tera.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::sync::Arc;
22

3-
use crate::IntoPyException;
4-
use crate::json;
53
use ahash::HashMap;
64
use pyo3::{prelude::*, types::PyDict};
75
use pyo3_stub_gen::derive::*;
86

7+
use crate::IntoPyException;
8+
use crate::json;
9+
910
#[gen_stub_pyclass]
1011
#[pyclass(module = "oxapy.templating")]
1112
#[derive(Debug, Clone)]

0 commit comments

Comments
 (0)