aws_smithy_http_server_python/
lib.rs1#![cfg_attr(docsrs, feature(doc_auto_cfg))]
8#![allow(clippy::derive_partial_eq_without_eq)]
10#![cfg_attr(docsrs, feature(doc_cfg))]
11
12pub mod context;
21mod error;
22pub mod lambda;
23pub mod logging;
24pub mod middleware;
25mod server;
26mod socket;
27pub mod tls;
28pub mod types;
29mod util;
30
31#[doc(inline)]
32pub use error::{PyError, PyMiddlewareException};
33#[doc(inline)]
34pub use logging::{py_tracing_event, PyTracingHandler};
35#[doc(inline)]
36pub use middleware::{PyMiddlewareHandler, PyMiddlewareLayer, PyRequest, PyResponse};
37#[doc(inline)]
38pub use server::{PyApp, PyHandler};
39#[doc(inline)]
40pub use socket::PySocket;
41#[doc(inline)]
42pub use util::error::{rich_py_err, RichPyErr};
43
44#[cfg(test)]
45mod tests {
46 use std::sync::Once;
47
48 use pyo3::{PyErr, Python};
49 use pyo3_asyncio::TaskLocals;
50
51 static INIT: Once = Once::new();
52
53 pub(crate) fn initialize() -> TaskLocals {
54 INIT.call_once(|| {
55 pyo3::prepare_freethreaded_python();
56 });
57
58 Python::with_gil(|py| {
59 let asyncio = py.import("asyncio")?;
60 let event_loop = asyncio.call_method0("new_event_loop")?;
61 asyncio.call_method1("set_event_loop", (event_loop,))?;
62 Ok::<TaskLocals, PyErr>(TaskLocals::new(event_loop))
63 })
64 .unwrap()
65 }
66}