File tree Expand file tree Collapse file tree 3 files changed +28
-29
lines changed
Expand file tree Collapse file tree 3 files changed +28
-29
lines changed Original file line number Diff line number Diff line change 1- use pyo3:: prelude:: * ;
2- use anyhow:: { Result } ;
1+ use anyhow:: Result ;
32use mitmproxy:: contentviews:: Contentview ;
3+ use pyo3:: prelude:: * ;
44
55#[ pyclass]
66pub struct PyContentview ( & ' static dyn Contentview ) ;
77
88impl 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]
1518impl 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+ }
Original file line number Diff line number Diff line change @@ -5,14 +5,14 @@ use std::sync::RwLock;
55use once_cell:: sync:: Lazy ;
66use pyo3:: { exceptions:: PyException , prelude:: * } ;
77
8+ mod contentview;
89mod dns_resolver;
910mod process_info;
1011mod server;
1112mod stream;
1213pub mod task;
1314mod udp_client;
1415mod util;
15- mod contentview;
1616
1717static 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
Original file line number Diff line number Diff line change 1- use std:: num:: ParseIntError ;
2- use anyhow:: { Result } ;
1+ use anyhow:: Result ;
32use pretty_hex:: { HexConfig , PrettyHex } ;
3+ use std:: num:: ParseIntError ;
44
55#[ derive( Debug ) ]
66pub 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+ }
You can’t perform that action at this time.
0 commit comments