File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -204,6 +204,11 @@ NB_MODULE(upa_url, m) {
204204 .def (" finalize" , &public_suffix_list_py::finalize)
205205
206206 // Load Public Suffix List from file
207+ .def (" __init__" , [](public_suffix_list_py* t, std::string_view filename) {
208+ new (t) public_suffix_list_py{};
209+ if (!t->load (filename))
210+ throw std::runtime_error (" Error loading Public Suffix List from file." );
211+ }, nb::arg (" filename" ))
207212 .def_static (" load" , [](std::string_view filename)
208213 -> std::optional<public_suffix_list_py> {
209214 public_suffix_list_py psl;
Original file line number Diff line number Diff line change @@ -25,6 +25,17 @@ def test_psl_push(self):
2525 psl .push ('^.com' )
2626 self .assertFalse (psl .finalize ())
2727
28+ def test_psl_construct (self ):
29+ # Use constructor to load the list
30+ dir = os .path .dirname (os .path .realpath (__file__ ))
31+ psl = PSL (os .path .join (dir , 'PSL.dat' ))
32+ # public suffix
33+ self .assertEqual (psl .public_suffix ('any.org.uk' ), 'org.uk' )
34+
35+ # Load error
36+ with self .assertRaises (RuntimeError ):
37+ PSL (os .path .join (dir , 'no_such_file.dat' ))
38+
2839 def test_psl (self ):
2940 # Load list
3041 dir = os .path .dirname (os .path .realpath (__file__ ))
You can’t perform that action at this time.
0 commit comments