@@ -58,7 +58,18 @@ fn adblock(py: Python<'_>, m: &PyModule) -> PyResult<()> {
5858 py. get_type :: < BadFilterAddUnsupported > ( ) ,
5959) ?;
6060 m. add ( "FilterExists" , py. get_type :: < FilterExists > ( ) ) ?;
61- m. add ( "AddResourceError" , py. get_type :: < AddResourceError > ( ) ) ?;
61+ m. add (
62+ "AddResourceException" ,
63+ py. get_type :: < AddResourceException > ( ) ,
64+ ) ?;
65+ m. add (
66+ "InvalidBase64ContentError" ,
67+ py. get_type :: < InvalidBase64ContentError > ( ) ,
68+ ) ?;
69+ m. add (
70+ "InvalidUtf8ContentError" ,
71+ py. get_type :: < InvalidUtf8ContentError > ( ) ,
72+ ) ?;
6273Ok ( ( ) )
6374}
6475
@@ -113,30 +124,23 @@ pub struct BlockerResult {
113124
114125impl From < RustBlockerResult > for BlockerResult {
115126fn from ( br : RustBlockerResult ) ->Self {
116- let mut redirect: Option < String > =None ;
117- let mut redirect_type: Option < String > =None ;
118- if br. redirect . is_some ( ) {
119- let resource = br. redirect . unwrap ( ) ;
120- redirect =Option :: from ( match resource{
121- Redirection :: Resource ( resource) =>{
122- redirect_type =Some ( "resource" . to_string ( ) ) ;
123- resource
124- }
125- Redirection :: Url ( url) =>{
126- redirect_type =Some ( "url" . to_string ( ) ) ;
127- url
128- }
129- } ) ;
130- }
127+ let ( redirect, redirect_type) =if let Some ( resource) = br. redirect {
128+ match resource{
129+ Redirection :: Resource ( resource) =>( Some ( resource) , Some ( "resource" . to_string ( ) ) ) ,
130+ Redirection :: Url ( url) =>( Some ( url) , Some ( "url" . to_string ( ) ) ) ,
131+ }
132+ } else {
133+ ( None , None )
134+ } ;
131135
132136Self {
133137matched : br. matched ,
134138important : br. important ,
135139exception : br. exception ,
136140filter : br. filter ,
137141error : br. error ,
138- redirect_type : redirect_type ,
139- redirect : redirect ,
142+ redirect_type,
143+ redirect,
140144}
141145}
142146}
@@ -189,12 +193,14 @@ impl Display for BlockerError {
189193
190194create_exception ! ( adblock, AdblockException , PyException ) ;
191195create_exception ! ( adblock, BlockerException , AdblockException ) ;
196+ create_exception ! ( adblock, AddResourceException , AdblockException ) ;
197+ create_exception ! ( adblock, InvalidBase64ContentError , AddResourceException ) ;
198+ create_exception ! ( adblock, InvalidUtf8ContentError , AddResourceException ) ;
192199create_exception ! ( adblock, SerializationError , BlockerException ) ;
193200create_exception ! ( adblock, DeserializationError , BlockerException ) ;
194201create_exception ! ( adblock, OptimizedFilterExistence , BlockerException ) ;
195202create_exception ! ( adblock, BadFilterAddUnsupported , BlockerException ) ;
196203create_exception ! ( adblock, FilterExists , BlockerException ) ;
197- create_exception ! ( adblock, AddResourceError , BlockerException ) ;
198204
199205impl From < BlockerError > for PyErr {
200206fn from ( err : BlockerError ) ->Self {
@@ -517,12 +523,12 @@ impl Engine {
517523match result{
518524Ok ( _) =>Ok ( ( ) ) ,
519525Err ( err) =>match err{
520- RustAddResourceError :: InvalidBase64Content =>Err ( AddResourceError :: new_err (
521- "invalid base64 content" . to_string ( ) ,
526+ RustAddResourceError :: InvalidBase64Content =>Err (
527+ InvalidBase64ContentError :: new_err ( "invalid base64 content" . to_string ( ) ) ,
528+ ) ,
529+ RustAddResourceError :: InvalidUtf8Content =>Err ( InvalidUtf8ContentError :: new_err (
530+ "invalid utf content" . to_string ( ) ,
522531) ) ,
523- RustAddResourceError :: InvalidUtf8Content =>{
524- Err ( AddResourceError :: new_err ( "invalid utf content" . to_string ( ) ) )
525- }
526532} ,
527533}
528534}