Skip to content

Commit f2561d3

Browse files
committed
Refactor base_url validation
1 parent 90df45c commit f2561d3

File tree

1 file changed

+48
-46
lines changed

1 file changed

+48
-46
lines changed

src/lib.rs

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ impl UrlPattern {
4444
None => (None, options),
4545
};
4646

47-
if matches!(input, Some(UrlPatternInput::Init(_))) && base_url.is_some() {
48-
return Err(PyTypeError::new_err("cannot use dict input with baseURL"));
49-
}
50-
5147
let init: ::urlpattern::UrlPatternInit = match input {
5248
Some(UrlPatternInput::String(input)) => {
5349
::urlpattern::UrlPatternInit::parse_constructor_string::<regex::Regex>(
@@ -56,48 +52,54 @@ impl UrlPattern {
5652
)
5753
.map_err(Error)?
5854
}
59-
Some(UrlPatternInput::Init(init)) => ::urlpattern::UrlPatternInit {
60-
protocol: init
61-
.get_item("protocol")?
62-
.map(|v| v.extract::<String>())
63-
.transpose()?,
64-
username: init
65-
.get_item("username")?
66-
.map(|v| v.extract::<String>())
67-
.transpose()?,
68-
password: init
69-
.get_item("password")?
70-
.map(|v| v.extract::<String>())
71-
.transpose()?,
72-
hostname: init
73-
.get_item("hostname")?
74-
.map(|v| v.extract::<String>())
75-
.transpose()?,
76-
port: init
77-
.get_item("port")?
78-
.map(|v| v.extract::<String>())
79-
.transpose()?,
80-
pathname: init
81-
.get_item("pathname")?
82-
.map(|v| v.extract::<String>())
83-
.transpose()?,
84-
search: init
85-
.get_item("search")?
86-
.map(|v| v.extract::<String>())
87-
.transpose()?,
88-
hash: init
89-
.get_item("hash")?
90-
.map(|v| v.extract::<String>())
91-
.transpose()?,
92-
base_url: init
93-
.get_item("baseURL")?
94-
.map(|v| v.extract::<String>())
95-
.transpose()?
96-
.map(|v| v.parse::<url::Url>())
97-
.transpose()
98-
.map_err(::urlpattern::Error::Url)
99-
.map_err(Error)?,
100-
},
55+
Some(UrlPatternInput::Init(init)) => {
56+
if base_url.is_some() {
57+
return Err(PyTypeError::new_err("cannot use dict input with baseURL"));
58+
}
59+
60+
::urlpattern::UrlPatternInit {
61+
protocol: init
62+
.get_item("protocol")?
63+
.map(|v| v.extract::<String>())
64+
.transpose()?,
65+
username: init
66+
.get_item("username")?
67+
.map(|v| v.extract::<String>())
68+
.transpose()?,
69+
password: init
70+
.get_item("password")?
71+
.map(|v| v.extract::<String>())
72+
.transpose()?,
73+
hostname: init
74+
.get_item("hostname")?
75+
.map(|v| v.extract::<String>())
76+
.transpose()?,
77+
port: init
78+
.get_item("port")?
79+
.map(|v| v.extract::<String>())
80+
.transpose()?,
81+
pathname: init
82+
.get_item("pathname")?
83+
.map(|v| v.extract::<String>())
84+
.transpose()?,
85+
search: init
86+
.get_item("search")?
87+
.map(|v| v.extract::<String>())
88+
.transpose()?,
89+
hash: init
90+
.get_item("hash")?
91+
.map(|v| v.extract::<String>())
92+
.transpose()?,
93+
base_url: init
94+
.get_item("baseURL")?
95+
.map(|v| v.extract::<String>())
96+
.transpose()?
97+
.map(|v| v.parse::<url::Url>())
98+
.transpose()
99+
.map_err(::urlpattern::Error::Url)
100+
.map_err(Error)?,
101+
}
102+
}
101103
None => ::urlpattern::UrlPatternInit::default(),
102104
};
103105
let options = if let Some(options) = options {

0 commit comments

Comments
 (0)