@@ -33,6 +33,21 @@ inline nb::str to_str(std::string_view sv) {
3333 return nb::str{ sv.data (), sv.length () };
3434}
3535
36+ class public_suffix_list_py : public upa ::public_suffix_list {
37+ public:
38+ inline void push_line (std::string_view line) {
39+ upa::public_suffix_list::push_line (ctx_, line);
40+ }
41+ inline void push (std::string_view buff) {
42+ upa::public_suffix_list::push (ctx_, buff);
43+ }
44+ inline bool finalize () {
45+ return upa::public_suffix_list::finalize (ctx_);
46+ }
47+ private:
48+ push_context ctx_;
49+ };
50+
3651} // namespace
3752
3853NB_MODULE (upa_url, m) {
@@ -181,29 +196,36 @@ NB_MODULE(upa_url, m) {
181196 ;
182197
183198 // PSL class
184- nb::class_<upa::public_suffix_list>(m, " PSL" )
199+ nb::class_<public_suffix_list_py>(m, " PSL" )
200+ // Load Public Suffix List using push interface
201+ .def (nb::init<>())
202+ .def (" push_line" , &public_suffix_list_py::push_line, nb::arg (" line" ))
203+ .def (" push" , &public_suffix_list_py::push, nb::arg (" buff" ))
204+ .def (" finalize" , &public_suffix_list_py::finalize)
205+
185206 // Load Public Suffix List from file
186207 .def_static (" load" , [](std::string_view filename)
187- -> std::optional<upa::public_suffix_list > {
188- upa::public_suffix_list psl;
208+ -> std::optional<public_suffix_list_py > {
209+ public_suffix_list_py psl;
189210 if (psl.load (filename))
190211 return psl;
191212 return std::nullopt ;
192213 }, nb::arg (" filename" ))
214+
193215 // Get public suffix
194- .def (" public_suffix" , [](const upa::public_suffix_list & self,
216+ .def (" public_suffix" , [](const public_suffix_list_py & self,
195217 std::string_view str_host, bool ascii) {
196218 if (ascii) {
197219 return to_str (self.get_suffix (str_host));
198220 }
199221 return to_str (self.get_suffix_view (str_host));
200222 }, nb::arg (" host" ), nb::arg (" ascii" ) = true )
201- .def (" public_suffix" , [](const upa::public_suffix_list & self,
223+ .def (" public_suffix" , [](const public_suffix_list_py & self,
202224 const upa::url& url) {
203225 return self.get_suffix_view (url);
204226 }, nb::arg (" url" ))
205227 // Get registrable domain
206- .def (" registrable_domain" , [](const upa::public_suffix_list & self,
228+ .def (" registrable_domain" , [](const public_suffix_list_py & self,
207229 std::string_view str_host, bool ascii) {
208230 if (ascii) {
209231 return to_str (self.get_suffix (str_host,
@@ -212,7 +234,7 @@ NB_MODULE(upa_url, m) {
212234 return to_str (self.get_suffix_view (str_host,
213235 upa::public_suffix_list::option::registrable_domain));
214236 }, nb::arg (" host" ), nb::arg (" ascii" ) = true )
215- .def (" registrable_domain" , [](const upa::public_suffix_list & self,
237+ .def (" registrable_domain" , [](const public_suffix_list_py & self,
216238 const upa::url& url) {
217239 return self.get_suffix_view (url,
218240 upa::public_suffix_list::option::registrable_domain);
0 commit comments