Skip to content

Commit 0260b1b

Browse files
[autofix.ci] apply automated fixes
1 parent 0e81f26 commit 0260b1b

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

mitmproxy-rs/src/contentview.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
use pyo3::prelude::*;
2-
use anyhow::{Result};
1+
use anyhow::Result;
32
use mitmproxy::contentviews::Contentview;
3+
use pyo3::prelude::*;
44

55
#[pyclass]
66
pub struct PyContentview(&'static dyn Contentview);
77

88
impl PyContentview {
9-
pub fn new<'py>(py: Python<'py>, contentview: &'static dyn Contentview) -> PyResult<Bound<'py, Self>> {
9+
pub fn new<'py>(
10+
py: Python<'py>,
11+
contentview: &'static dyn Contentview,
12+
) -> PyResult<Bound<'py, Self>> {
1013
PyContentview(contentview).into_pyobject(py)
1114
}
1215
}
1316

1417
#[pymethods]
1518
impl PyContentview {
16-
1719
#[getter]
1820
pub fn name(&self) -> &str {
1921
self.0.name()
2022
}
2123

22-
pub fn deserialize<'py>(
23-
&self,
24-
data: Vec<u8>
25-
) -> Result<String> {
24+
pub fn deserialize<'py>(&self, data: Vec<u8>) -> Result<String> {
2625
self.0.deserialize(data)
2726
}
2827

2928
fn __repr__(&self) -> PyResult<String> {
3029
Ok(format!("<{} Contentview>", self.0.name()))
3130
}
32-
}
31+
}

mitmproxy-rs/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use std::sync::RwLock;
55
use once_cell::sync::Lazy;
66
use pyo3::{exceptions::PyException, prelude::*};
77

8+
mod contentview;
89
mod dns_resolver;
910
mod process_info;
1011
mod server;
1112
mod stream;
1213
pub mod task;
1314
mod udp_client;
1415
mod util;
15-
mod contentview;
1616

1717
static LOGGER_INITIALIZED: Lazy<RwLock<bool>> = Lazy::new(|| RwLock::new(false));
1818

@@ -84,16 +84,13 @@ mod mitmproxy_rs {
8484

8585
#[pymodule]
8686
mod contentviews {
87-
use crate::contentview::PyContentview;
8887
use super::*;
88+
use crate::contentview::PyContentview;
8989
use mitmproxy::contentviews::*;
9090

9191
#[pymodule_init]
9292
fn init(m: &Bound<'_, PyModule>) -> PyResult<()> {
93-
m.add(
94-
"hex",
95-
PyContentview::new(m.py(), &HexStream())?
96-
)
93+
m.add("hex", PyContentview::new(m.py(), &HexStream())?)
9794
}
9895
}
9996

src/contentviews/mod.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::num::ParseIntError;
2-
use anyhow::{Result};
1+
use anyhow::Result;
32
use pretty_hex::{HexConfig, PrettyHex};
3+
use std::num::ParseIntError;
44

55
#[derive(Debug)]
66
pub enum SerializeError {
@@ -25,15 +25,17 @@ impl Contentview for HexStream {
2525
}
2626

2727
fn deserialize(&self, data: Vec<u8>) -> Result<String> {
28-
Ok(data.hex_conf(HexConfig {
29-
title: false,
30-
ascii: false,
31-
width: 0,
32-
group: 0,
33-
chunk: 0,
34-
max_bytes: usize::MAX,
35-
display_offset: 0,
36-
}).to_string())
28+
Ok(data
29+
.hex_conf(HexConfig {
30+
title: false,
31+
ascii: false,
32+
width: 0,
33+
group: 0,
34+
chunk: 0,
35+
max_bytes: usize::MAX,
36+
display_offset: 0,
37+
})
38+
.to_string())
3739
}
3840
}
3941

@@ -43,8 +45,9 @@ impl SerializableContentview for HexStream {
4345
.step_by(2)
4446
.map(|i| u8::from_str_radix(&data[i..i + 2], 16))
4547
.collect::<Result<Vec<u8>, ParseIntError>>()
46-
.map_err(
47-
|e| SerializeError::InvalidFormat(format!("Failed to parse hex string: {}", e)))
48+
.map_err(|e| {
49+
SerializeError::InvalidFormat(format!("Failed to parse hex string: {}", e))
50+
})
4851
}
4952
}
5053

@@ -75,4 +78,4 @@ mod tests {
7578
let result = hex_stream.serialize(data).unwrap();
7679
assert_eq!(result, b"foo");
7780
}
78-
}
81+
}

0 commit comments

Comments
 (0)