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