diff --git a/sopel/modules/tld.py b/sopel/modules/tld.py index 28b9599d9..d8f6f2b95 100644 --- a/sopel/modules/tld.py +++ b/sopel/modules/tld.py @@ -13,6 +13,7 @@ from html.parser import HTMLParser import logging import re +from typing import Dict import pytz import requests @@ -100,6 +101,7 @@ def __init__(self): self.current_cell = '' self.rows = [] self.tables = [] + self.parsed: Dict[str, Dict[str, str]] = {} self.finished = False def handle_starttag(self, tag, attrs): @@ -158,7 +160,7 @@ def get_processed_data(self): LOGGER.debug("Processed TLD data requested.") if self.finished: LOGGER.debug("Returning stored previously-processed data.") - return self.tables + return self.parsed LOGGER.debug("Ensuring all buffered data has been parsed.") self.close() @@ -202,8 +204,12 @@ def get_processed_data(self): tld_list[idn_key] = zipped LOGGER.debug("Finished processing TLD data; returning it.") - self.tables = tld_list self.finished = True + # clear working data + del self.tables + # cache parsed data for future requests to this parser + self.parsed = tld_list + return self.tables