-
-
Notifications
You must be signed in to change notification settings - Fork 101
feat(http1/http2): implement __str__ for types
#559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| use std::fmt; | ||
|
|
||
| use bytes::Bytes; | ||
| use pyo3::{ | ||
| prelude::*, | ||
|
|
@@ -234,11 +232,7 @@ impl HeaderMap { | |
| } | ||
| } | ||
|
|
||
| impl fmt::Display for HeaderMap { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| write!(f, "{:?}", self.0) | ||
| } | ||
| } | ||
| define_display!(HeaderMap); | ||
|
|
||
| impl FromPyObject<'_, '_> for HeaderMap { | ||
| type Error = PyErr; | ||
|
|
@@ -347,11 +341,7 @@ impl OrigHeaderMap { | |
| } | ||
| } | ||
|
|
||
| impl fmt::Display for OrigHeaderMap { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| write!(f, "{:?}", self.0) | ||
| } | ||
| } | ||
| define_display!(OrigHeaderMap); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| impl FromPyObject<'_, '_> for OrigHeaderMap { | ||
| type Error = PyErr; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ struct Builder { | |
| /// These options allow you to customize the behavior of HTTP/1 connections, | ||
| /// such as enabling support for HTTP/0.9 responses, header case preservation, etc. | ||
| #[derive(Clone)] | ||
| #[pyclass(frozen, from_py_object)] | ||
| #[pyclass(frozen, str, from_py_object)] | ||
| pub struct Http1Options(pub wreq::http1::Http1Options); | ||
|
|
||
| // ===== impl Builder ===== | ||
|
|
@@ -106,3 +106,5 @@ impl Http1Options { | |
| }) | ||
| } | ||
| } | ||
|
|
||
| define_display!(Http1Options); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| use std::time::Duration; | ||
| use std::{fmt::Debug, time::Duration}; | ||
|
|
||
| use pyo3::prelude::*; | ||
|
|
||
|
|
@@ -50,7 +50,7 @@ define_enum!( | |
| /// | ||
| /// [Section 5.1.1]: https://tools.ietf.org/html/rfc7540#section-5.1.1 | ||
| #[derive(Clone)] | ||
| #[pyclass(frozen, from_py_object)] | ||
| #[pyclass(frozen, str, from_py_object)] | ||
| pub struct StreamId(wreq::http2::StreamId); | ||
|
|
||
| /// Represents a stream dependency in HTTP/2 priority frames. | ||
|
|
@@ -66,15 +66,15 @@ pub struct StreamId(wreq::http2::StreamId); | |
| /// can depend on another stream. This creates a priority hierarchy that helps | ||
| /// determine the relative order in which streams should be processed. | ||
| #[derive(Clone)] | ||
| #[pyclass(frozen, from_py_object)] | ||
| #[pyclass(frozen, str, from_py_object)] | ||
| pub struct StreamDependency(wreq::http2::StreamDependency); | ||
|
|
||
| /// The PRIORITY frame (type=0x2) specifies the sender-advised priority | ||
| /// of a stream [Section 5.3]. It can be sent in any stream state, | ||
| /// including idle or closed streams. | ||
| /// [Section 5.3]: <https://tools.ietf.org/html/rfc7540#section-5.3> | ||
| #[derive(Clone)] | ||
| #[pyclass(frozen, from_py_object)] | ||
| #[pyclass(frozen, str, from_py_object)] | ||
| pub struct Priority(wreq::http2::Priority); | ||
|
|
||
| /// A collection of HTTP/2 PRIORITY frames. | ||
|
|
@@ -85,7 +85,7 @@ pub struct Priority(wreq::http2::Priority); | |
| /// sending multiple PRIORITY frames at once during connection setup or | ||
| /// stream reprioritization. | ||
| #[derive(Clone)] | ||
| #[pyclass(frozen, from_py_object)] | ||
| #[pyclass(frozen, str, from_py_object)] | ||
| pub struct Priorities(wreq::http2::Priorities); | ||
|
|
||
| /// Represents the order of HTTP/2 pseudo-header fields in a header block. | ||
|
|
@@ -95,7 +95,7 @@ pub struct Priorities(wreq::http2::Priorities); | |
| /// significant according to the HTTP/2 specification, and this type ensures that the correct order | ||
| /// is preserved and that no duplicates are present. | ||
| #[derive(Clone)] | ||
| #[pyclass(frozen, from_py_object)] | ||
| #[pyclass(frozen, str, from_py_object)] | ||
| pub struct PseudoOrder(wreq::http2::PseudoOrder); | ||
|
|
||
| /// Represents the order of settings in a SETTINGS frame. | ||
|
|
@@ -105,7 +105,7 @@ pub struct PseudoOrder(wreq::http2::PseudoOrder); | |
| /// or interoperability. `SettingsOrder` ensures that the specified order is preserved and that no | ||
| /// duplicate settings are present. | ||
| #[derive(Clone)] | ||
| #[pyclass(frozen, from_py_object)] | ||
| #[pyclass(frozen, str, from_py_object)] | ||
| pub struct SettingsOrder(wreq::http2::SettingsOrder); | ||
|
|
||
| /// A builder for [`Http2Options`]. | ||
|
|
@@ -183,7 +183,7 @@ struct Builder { | |
| /// This struct defines various parameters to fine-tune the behavior of an HTTP/2 connection, | ||
| /// including stream management, window sizes, frame limits, and header config. | ||
| #[derive(Clone)] | ||
| #[pyclass(frozen, from_py_object)] | ||
| #[pyclass(frozen, str, from_py_object)] | ||
| pub struct Http2Options(pub wreq::http2::Http2Options); | ||
|
|
||
| // ===== impl StreamId ===== | ||
|
|
@@ -206,6 +206,8 @@ impl StreamId { | |
| } | ||
| } | ||
|
|
||
| define_display!(StreamId); | ||
|
|
||
| // ===== impl StreamDependency ===== | ||
|
|
||
| #[pymethods] | ||
|
|
@@ -222,6 +224,8 @@ impl StreamDependency { | |
| } | ||
| } | ||
|
|
||
| define_display!(StreamDependency); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // ===== impl Priority ===== | ||
|
|
||
| #[pymethods] | ||
|
|
@@ -234,6 +238,8 @@ impl Priority { | |
| } | ||
| } | ||
|
|
||
| define_display!(Priority); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // ===== impl Priorities ===== | ||
|
|
||
| #[pymethods] | ||
|
|
@@ -250,6 +256,8 @@ impl Priorities { | |
| } | ||
| } | ||
|
|
||
| define_display!(Priorities); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // ===== impl PseudoOrder ===== | ||
|
|
||
| #[pymethods] | ||
|
|
@@ -266,6 +274,8 @@ impl PseudoOrder { | |
| } | ||
| } | ||
|
|
||
| define_display!(PseudoOrder); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // ===== impl SettingsOrder ===== | ||
|
|
||
| #[pymethods] | ||
|
|
@@ -282,6 +292,8 @@ impl SettingsOrder { | |
| } | ||
| } | ||
|
|
||
| define_display!(SettingsOrder); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // ===== impl Builder ===== | ||
|
|
||
| impl FromPyObject<'_, '_> for Builder { | ||
|
|
@@ -449,3 +461,5 @@ impl Http2Options { | |
| }) | ||
| } | ||
| } | ||
|
|
||
| define_display!(Http2Options); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
wreq::header::HeaderMapdoes not implementDisplay, you should use thedebugvariant of the improveddefine_display!macro.