File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,10 @@ inline std::string_view to_string_view(nb::str str) {
2929 return {};
3030}
3131
32+ inline std::string_view to_string_view (nb::bytes bytes) {
33+ return { bytes.c_str (), bytes.size () };
34+ }
35+
3236inline nb::str to_str (std::string_view sv) {
3337 return nb::str{ sv.data (), sv.length () };
3438}
@@ -41,6 +45,9 @@ class public_suffix_list_py : public upa::public_suffix_list {
4145 inline void push (std::string_view buff) {
4246 upa::public_suffix_list::push (ctx_, buff);
4347 }
48+ inline void push_bytes (nb::bytes bytes) {
49+ upa::public_suffix_list::push (ctx_, to_string_view (bytes));
50+ }
4451 inline bool finalize () {
4552 return upa::public_suffix_list::finalize (ctx_);
4653 }
@@ -201,6 +208,7 @@ NB_MODULE(upa_url, m) {
201208 .def (nb::init<>())
202209 .def (" push_line" , &public_suffix_list_py::push_line, nb::arg (" line" ))
203210 .def (" push" , &public_suffix_list_py::push, nb::arg (" buff" ))
211+ .def (" push" , &public_suffix_list_py::push_bytes, nb::arg (" buff" ))
204212 .def (" finalize" , &public_suffix_list_py::finalize)
205213
206214 // Load Public Suffix List from file
Original file line number Diff line number Diff line change @@ -16,7 +16,9 @@ def test_psl_push(self):
1616 psl = PSL ()
1717 psl .push ('githu' )
1818 psl .push ('b.io' )
19+ psl .push (b'\n gov.lt' )
1920 self .assertTrue (psl .finalize ())
21+ self .assertEqual (psl .public_suffix ('data.gov.lt' ), 'gov.lt' )
2022 self .assertEqual (psl .public_suffix ('upa-url.github.io.' ), 'github.io.' )
2123 self .assertEqual (psl .public_suffix ('abc.io.' ), 'io.' )
2224
You can’t perform that action at this time.
0 commit comments