Switch to 2024 edition

This commit is contained in:
Giovanni Barillari 2025-05-19 10:25:13 +02:00
parent 9a65516fde
commit 17c45dd580
No known key found for this signature in database
24 changed files with 52 additions and 53 deletions

View file

@ -4,7 +4,7 @@ version = "2.3.0"
description = "A Rust HTTP server for Python applications"
authors = ["Giovanni Barillari <g@baro.dev>"]
license = "BSD-3-Clause"
edition = "2021"
edition = "2024"
keywords = ["web", "asyncio"]

View file

@ -4,7 +4,7 @@ use std::{
net::SocketAddr,
sync::{Arc, OnceLock},
};
use tokio::sync::{oneshot, Notify};
use tokio::sync::{Notify, oneshot};
use super::{
io::{ASGIHTTPProtocol as HTTPProtocol, ASGIWebsocketProtocol as WebsocketProtocol, WebsocketDetachedTransport},
@ -12,7 +12,7 @@ use super::{
};
use crate::{
callbacks::ArcCBScheduler,
http::{response_500, HTTPResponse},
http::{HTTPResponse, response_500},
runtime::{Runtime, RuntimeRef},
utils::log_application_callable_exception,
ws::{HyperWebsocket, UpgradeData},

View file

@ -1,7 +1,7 @@
use pyo3::{
IntoPyObjectExt,
prelude::*,
types::{PyBytes, PyDict},
IntoPyObjectExt,
};
use tokio_tungstenite::tungstenite::Message;

View file

@ -1,14 +1,14 @@
use http_body_util::BodyExt;
use hyper::{header::SERVER as HK_SERVER, http::response::Builder as ResponseBuilder, StatusCode};
use hyper::{StatusCode, header::SERVER as HK_SERVER, http::response::Builder as ResponseBuilder};
use std::{net::SocketAddr, sync::Arc};
use tokio::sync::{mpsc, Notify};
use tokio::sync::{Notify, mpsc};
use super::callbacks::{call_http, call_ws};
use crate::{
callbacks::ArcCBScheduler,
http::{empty_body, response_500, HTTPRequest, HTTPResponse, HV_SERVER},
http::{HTTPRequest, HTTPResponse, HV_SERVER, empty_body, response_500},
runtime::RuntimeRef,
ws::{is_upgrade_request as is_ws_upgrade, upgrade_intent as ws_upgrade, UpgradeData},
ws::{UpgradeData, is_upgrade_request as is_ws_upgrade, upgrade_intent as ws_upgrade},
};
const SCHEME_HTTPS: &str = "https";

View file

@ -1,32 +1,31 @@
use anyhow::Result;
use futures::{sink::SinkExt, StreamExt, TryStreamExt};
use futures::{StreamExt, TryStreamExt, sink::SinkExt};
use http_body_util::BodyExt;
use hyper::{
body,
Response, StatusCode, body,
header::{HeaderMap, HeaderName, HeaderValue, SERVER as HK_SERVER},
Response, StatusCode,
};
use pyo3::{prelude::*, pybacked::PyBackedBytes, types::PyDict};
use std::{
borrow::Cow,
sync::{atomic, Arc, Mutex},
sync::{Arc, Mutex, atomic},
};
use tokio::{
fs::File,
sync::{mpsc, oneshot, Mutex as AsyncMutex, Notify},
sync::{Mutex as AsyncMutex, Notify, mpsc, oneshot},
};
use tokio_tungstenite::tungstenite::Message;
use tokio_util::io::ReaderStream;
use super::{
errors::{error_flow, error_message, UnsupportedASGIMessage},
errors::{UnsupportedASGIMessage, error_flow, error_message},
types::ASGIMessageType,
};
use crate::{
conversion::FutureResultToPy,
http::{response_404, HTTPResponse, HTTPResponseBody, HV_SERVER},
http::{HTTPResponse, HTTPResponseBody, HV_SERVER, response_404},
runtime::{
done_future_into_py, empty_future_into_py, err_future_into_py, future_into_py_futlike, Runtime, RuntimeRef,
Runtime, RuntimeRef, done_future_into_py, empty_future_into_py, err_future_into_py, future_into_py_futlike,
},
ws::{HyperWebsocket, UpgradeData, WSRxStream, WSTxStream},
};

View file

@ -6,7 +6,7 @@ use super::http::{handle, handle_ws};
use crate::callbacks::CallbackScheduler;
use crate::conversion::{worker_http1_config_from_py, worker_http2_config_from_py};
use crate::tcp::SocketHolder;
use crate::workers::{gen_serve_match, gen_serve_methods, WorkerConfig, WorkerSignal};
use crate::workers::{WorkerConfig, WorkerSignal, gen_serve_match, gen_serve_methods};
#[pyclass(frozen, module = "granian._granian")]
pub struct ASGIWorker {

View file

@ -1,4 +1,4 @@
use hyper::{body, HeaderMap};
use hyper::{HeaderMap, body};
use tokio_tungstenite::tungstenite::Message;
pub(crate) enum ASGIMessageType {

View file

@ -1,7 +1,7 @@
use crossbeam_channel as channel;
use pyo3::prelude::*;
use std::{
sync::{atomic, Arc},
sync::{Arc, atomic},
thread, time,
};

View file

@ -1,5 +1,5 @@
use pyo3::{exceptions::PyStopIteration, prelude::*, types::PyDict, IntoPyObjectExt};
use std::sync::{atomic, Arc, OnceLock, RwLock};
use pyo3::{IntoPyObjectExt, exceptions::PyStopIteration, prelude::*, types::PyDict};
use std::sync::{Arc, OnceLock, RwLock, atomic};
use tokio::sync::Notify;
use crate::{asyncio::copy_context, conversion::FutureResultToPy};
@ -260,6 +260,7 @@ pub(crate) struct CallbackSchedulerState {
}
impl CallbackSchedulerState {
#[allow(unsafe_op_in_unsafe_fn)]
unsafe fn add_waker(self: Arc<Self>, py: Python, fut: *mut pyo3::ffi::PyObject, fut_cbm: *mut pyo3::ffi::PyObject) {
let waker = Py::new(py, CallbackSchedulerWaker { state: self.clone() }).unwrap();
let ctxd = PyDict::new(py);

View file

@ -1,4 +1,4 @@
use pyo3::{prelude::*, IntoPyObjectExt};
use pyo3::{IntoPyObjectExt, prelude::*};
use crate::workers::{HTTP1Config, HTTP2Config};

View file

@ -2,14 +2,14 @@ use anyhow::Result;
use futures::TryStreamExt;
use http_body_util::BodyExt;
use hyper::{
header::{HeaderValue, SERVER as HK_SERVER},
HeaderMap, StatusCode,
header::{HeaderValue, SERVER as HK_SERVER},
};
use std::{io, path::Path};
use tokio::fs::File;
use tokio_util::io::ReaderStream;
use crate::http::{response_404, HTTPResponse, HV_SERVER};
use crate::http::{HTTPResponse, HV_SERVER, response_404};
#[inline(always)]
pub(crate) fn match_static_file(uri_path: &str, prefix: &str, mount_point: &str) -> Option<Result<String>> {

View file

@ -1,8 +1,8 @@
use http_body_util::BodyExt;
use hyper::{
Response,
body::Bytes,
header::{HeaderValue, SERVER as HK_SERVER},
Response,
};
pub(crate) type HTTPRequest = hyper::Request<hyper::body::Incoming>;

View file

@ -1,6 +1,6 @@
use pyo3::prelude::*;
use std::sync::{Arc, OnceLock};
use tokio::sync::{oneshot, Notify};
use tokio::sync::{Notify, oneshot};
use super::{
io::{RSGIHTTPProtocol as HTTPProtocol, RSGIWebsocketProtocol as WebsocketProtocol, WebsocketDetachedTransport},

View file

@ -1,7 +1,7 @@
use pyo3::{
IntoPyObjectExt,
prelude::*,
types::{PyBytes, PyString},
IntoPyObjectExt,
};
use tokio_tungstenite::tungstenite::Message;

View file

@ -1,8 +1,8 @@
use futures::sink::SinkExt;
use http_body_util::BodyExt;
use hyper::{header::SERVER as HK_SERVER, http::response::Builder as ResponseBuilder, StatusCode};
use hyper::{StatusCode, header::SERVER as HK_SERVER, http::response::Builder as ResponseBuilder};
use std::{net::SocketAddr, sync::Arc};
use tokio::sync::{mpsc, Notify};
use tokio::sync::{Notify, mpsc};
use super::{
callbacks::{call_http, call_ws},
@ -10,9 +10,9 @@ use super::{
};
use crate::{
callbacks::ArcCBScheduler,
http::{empty_body, response_500, HTTPRequest, HTTPResponse, HV_SERVER},
http::{HTTPRequest, HTTPResponse, HV_SERVER, empty_body, response_500},
runtime::RuntimeRef,
ws::{is_upgrade_request as is_ws_upgrade, upgrade_intent as ws_upgrade, UpgradeData},
ws::{UpgradeData, is_upgrade_request as is_ws_upgrade, upgrade_intent as ws_upgrade},
};
macro_rules! build_scope {

View file

@ -1,12 +1,12 @@
use futures::{sink::SinkExt, StreamExt};
use futures::{StreamExt, sink::SinkExt};
use http_body_util::BodyExt;
use hyper::body;
use pyo3::{prelude::*, pybacked::PyBackedStr};
use std::{
borrow::Cow,
sync::{atomic, Arc, Mutex, RwLock},
sync::{Arc, Mutex, RwLock, atomic},
};
use tokio::sync::{mpsc, oneshot, Mutex as AsyncMutex, Notify};
use tokio::sync::{Mutex as AsyncMutex, Notify, mpsc, oneshot};
use tokio_tungstenite::tungstenite::Message;
use super::{
@ -15,7 +15,7 @@ use super::{
};
use crate::{
conversion::FutureResultToPy,
runtime::{empty_future_into_py, err_future_into_py, future_into_py_futlike, RuntimeRef},
runtime::{RuntimeRef, empty_future_into_py, err_future_into_py, future_into_py_futlike},
ws::{HyperWebsocket, UpgradeData, WSRxStream, WSTxStream},
};

View file

@ -6,7 +6,7 @@ use super::http::{handle, handle_ws};
use crate::callbacks::CallbackScheduler;
use crate::conversion::{worker_http1_config_from_py, worker_http2_config_from_py};
use crate::tcp::SocketHolder;
use crate::workers::{gen_serve_match, gen_serve_methods, WorkerConfig, WorkerSignal};
use crate::workers::{WorkerConfig, WorkerSignal, gen_serve_match, gen_serve_methods};
#[pyclass(frozen, module = "granian._granian")]
pub struct RSGIWorker {

View file

@ -2,10 +2,10 @@ use anyhow::Result;
use futures::TryStreamExt;
use http_body_util::BodyExt;
use hyper::{
Method, Uri, Version,
body::Bytes,
header::{HeaderMap, HeaderName, HeaderValue, SERVER as HK_SERVER},
http::uri::Authority,
Method, Uri, Version,
};
use percent_encoding::percent_decode_str;
use pyo3::types::{PyBytes, PyIterator, PyList, PyString};
@ -14,7 +14,7 @@ use std::{borrow::Cow, net::SocketAddr};
use tokio::fs::File;
use tokio_util::io::ReaderStream;
use crate::http::{empty_body, response_404, HTTPResponseBody, HV_SERVER};
use crate::http::{HTTPResponseBody, HV_SERVER, empty_body, response_404};
const RSGI_PROTO_VERSION: &str = "1.5";

View file

@ -1,4 +1,4 @@
use pyo3::{prelude::*, IntoPyObjectExt};
use pyo3::{IntoPyObjectExt, prelude::*};
use std::{
future::Future,
sync::{Arc, Mutex},

View file

@ -1,5 +1,5 @@
use anyhow::Result;
use pyo3::{prelude::*, IntoPyObjectExt};
use pyo3::{IntoPyObjectExt, prelude::*};
use std::net::{IpAddr, SocketAddr, TcpListener};
#[cfg(unix)]

View file

@ -1,4 +1,4 @@
use anyhow::{anyhow, Result};
use anyhow::{Result, anyhow};
use std::{
fs, io,
iter::Iterator,
@ -6,17 +6,17 @@ use std::{
sync::Arc,
};
use tls_listener::{
TlsListener,
rustls::{
TlsAcceptor,
rustls::{
pki_types::{
pem::PemObject, CertificateDer as Certificate, CertificateRevocationListDer as CRL,
PrivateKeyDer as PrivateKey,
CertificateDer as Certificate, CertificateRevocationListDer as CRL, PrivateKeyDer as PrivateKey,
pem::PemObject,
},
server::ServerConfig,
},
TlsAcceptor,
},
TlsListener,
};
pub(crate) fn tls_listener(

View file

@ -1,8 +1,8 @@
use http_body_util::BodyExt;
use hyper::{
header::{HeaderName, HeaderValue, CONNECTION, UPGRADE},
http::response::Builder,
Request, Response, StatusCode,
header::{CONNECTION, HeaderName, HeaderValue, UPGRADE},
http::response::Builder,
};
use pin_project_lite::pin_project;
use std::{
@ -12,13 +12,13 @@ use std::{
};
use tokio::sync::mpsc;
use tokio_tungstenite::{
WebSocketStream,
tungstenite::{
Error as TungsteniteError, Message,
error::ProtocolError,
handshake::derive_accept_key,
protocol::{Role, WebSocketConfig},
Error as TungsteniteError, Message,
},
WebSocketStream,
};
use super::http::HTTPResponse;

View file

@ -1,7 +1,6 @@
use hyper::{
body, header,
HeaderMap, Version, body, header,
http::{request, uri::Authority},
HeaderMap, Version,
};
use itertools::Itertools;
use percent_encoding::percent_decode_str;
@ -15,7 +14,7 @@ use tokio::sync::oneshot;
use super::{io::WSGIProtocol, types::WSGIBody};
use crate::{
callbacks::ArcCBScheduler,
http::{empty_body, HTTPResponseBody},
http::{HTTPResponseBody, empty_body},
runtime::{Runtime, RuntimeRef},
utils::log_application_callable_exception,
};

View file

@ -5,7 +5,7 @@ use tokio::sync::Notify;
use super::callbacks::call_http;
use crate::{
callbacks::ArcCBScheduler,
http::{response_500, HTTPRequest, HTTPResponse, HTTPResponseBody},
http::{HTTPRequest, HTTPResponse, HTTPResponseBody, response_500},
runtime::RuntimeRef,
};