@@ -7,11 +7,15 @@ const INLINE_ERROR_DOCSTRING: &str = "An error that can occur during CSS inlinin
7
7
8
8
create_exception ! ( css_inline, InlineError , exceptions:: ValueError ) ;
9
9
10
- fn to_pyerr ( error : rust_inline:: InlineError ) -> PyErr {
11
- match error {
12
- rust_inline:: InlineError :: IO ( error) => InlineError :: py_err ( format ! ( "{}" , error) ) ,
13
- rust_inline:: InlineError :: Network ( error) => InlineError :: py_err ( format ! ( "{}" , error) ) ,
14
- rust_inline:: InlineError :: ParseError ( message) => InlineError :: py_err ( message) ,
10
+ struct InlineErrorWrapper ( rust_inline:: InlineError ) ;
11
+
12
+ impl From < InlineErrorWrapper > for PyErr {
13
+ fn from ( error : InlineErrorWrapper ) -> Self {
14
+ match error. 0 {
15
+ rust_inline:: InlineError :: IO ( error) => InlineError :: py_err ( format ! ( "{}" , error) ) ,
16
+ rust_inline:: InlineError :: Network ( error) => InlineError :: py_err ( format ! ( "{}" , error) ) ,
17
+ rust_inline:: InlineError :: ParseError ( message) => InlineError :: py_err ( message) ,
18
+ }
15
19
}
16
20
}
17
21
@@ -61,7 +65,7 @@ impl CSSInliner {
61
65
/// Inline CSS in the given HTML document
62
66
#[ text_signature = "(html)" ]
63
67
fn inline ( & self , html : & str ) -> PyResult < String > {
64
- Ok ( self . inner . inline ( html) . map_err ( to_pyerr ) ?)
68
+ Ok ( self . inner . inline ( html) . map_err ( InlineErrorWrapper ) ?)
65
69
}
66
70
67
71
/// inline_many(htmls)
@@ -90,7 +94,7 @@ fn inline(
90
94
load_remote_stylesheets : load_remote_stylesheets. unwrap_or ( true ) ,
91
95
} ;
92
96
let inliner = rust_inline:: CSSInliner :: new ( options) ;
93
- Ok ( inliner. inline ( html) . map_err ( to_pyerr ) ?)
97
+ Ok ( inliner. inline ( html) . map_err ( InlineErrorWrapper ) ?)
94
98
}
95
99
96
100
/// inline_many(htmls, remove_style_tags=False, base_url=None, load_remote_stylesheets=True)
@@ -120,7 +124,7 @@ fn inline_many_impl(inliner: &rust_inline::CSSInliner, htmls: &PyList) -> PyResu
120
124
. par_iter ( )
121
125
. map ( |html| inliner. inline ( html) )
122
126
. collect ( ) ;
123
- Ok ( inlined. map_err ( to_pyerr ) ?)
127
+ Ok ( inlined. map_err ( InlineErrorWrapper ) ?)
124
128
}
125
129
126
130
#[ allow( dead_code) ]
0 commit comments