@@ -5,12 +5,13 @@ use std::hash::{Hash, Hasher};
5
5
6
6
use idna:: punycode:: decode_to_string;
7
7
use pyo3:: exceptions:: PyValueError ;
8
- use pyo3:: prelude:: * ;
9
8
use pyo3:: pyclass:: CompareOp ;
10
9
use pyo3:: sync:: GILOnceCell ;
11
10
use pyo3:: types:: { PyDict , PyType } ;
11
+ use pyo3:: { intern, prelude:: * } ;
12
12
use url:: Url ;
13
13
14
+ use crate :: tools:: SchemaDict ;
14
15
use crate :: SchemaValidator ;
15
16
16
17
static SCHEMA_DEFINITION_URL : GILOnceCell < SchemaValidator > = GILOnceCell :: new ( ) ;
@@ -422,8 +423,6 @@ impl PyMultiHostUrl {
422
423
}
423
424
}
424
425
425
- #[ derive( FromPyObject ) ]
426
- #[ pyo3( from_item_all) ]
427
426
#[ cfg_attr( debug_assertions, derive( Debug ) ) ]
428
427
pub struct UrlHostParts {
429
428
username : Option < String > ,
@@ -438,6 +437,20 @@ impl UrlHostParts {
438
437
}
439
438
}
440
439
440
+ impl FromPyObject < ' _ > for UrlHostParts {
441
+ fn extract_bound ( ob : & Bound < ' _ , PyAny > ) -> PyResult < Self > {
442
+ let py = ob. py ( ) ;
443
+ let dict = ob. downcast :: < PyDict > ( ) ?;
444
+
445
+ Ok ( UrlHostParts {
446
+ username : dict. get_as :: < Option < _ > > ( intern ! ( py, "username" ) ) ?. flatten ( ) ,
447
+ password : dict. get_as :: < Option < _ > > ( intern ! ( py, "password" ) ) ?. flatten ( ) ,
448
+ host : dict. get_as :: < Option < _ > > ( intern ! ( py, "host" ) ) ?. flatten ( ) ,
449
+ port : dict. get_as :: < Option < _ > > ( intern ! ( py, "port" ) ) ?. flatten ( ) ,
450
+ } )
451
+ }
452
+ }
453
+
441
454
impl fmt:: Display for UrlHostParts {
442
455
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
443
456
match ( & self . username , & self . password ) {
0 commit comments