@@ -208,8 +208,10 @@ def fromDomainStringToTld(domain: str, internationalized: bool, verbose: bool =
208208 return tld , d
209209
210210
211- def validateWeKnowTheToplevelDomain (tld ): # may raise UnknownTld
211+ def validateWeKnowTheToplevelDomain (tld , return_raw_text_for_unsupported_tld : bool = False ): # may raise UnknownTld
212212 if tld not in TLD_RE .keys ():
213+ if return_raw_text_for_unsupported_tld :
214+ return None
213215 a = f"The TLD { tld } is currently not supported by this package."
214216 b = "Use validTlds() to see what toplevel domains are supported."
215217 msg = f"{ a } { b } "
@@ -244,6 +246,45 @@ def doSlowdownHintForThisTld(tld: str, thisTld, slow_down: int, verbose: bool =
244246 return slow_down
245247
246248
249+ def doUnsupportedTldAnyway (
250+ tld : str ,
251+ dl : Dict ,
252+ ignore_returncode : bool = False ,
253+ slow_down : int = 0 ,
254+ server : Optional [str ] = None ,
255+ verbose : bool = False ,
256+ ):
257+ include_raw_whois_text = True
258+
259+ # we will not hunt for possible valid first level domains as we have no actual feedback
260+
261+ whois_str = do_query (
262+ dl = dl ,
263+ slow_down = slow_down ,
264+ ignore_returncode = ignore_returncode ,
265+ server = server ,
266+ verbose = verbose ,
267+ )
268+
269+ # we will only return minimal data
270+ data = {
271+ "tld" : tld ,
272+ "domain_name" : "" ,
273+ }
274+ data ["domain_name" ] = ["." .join (dl )] # note the fields are default all array, except tld
275+
276+ if verbose :
277+ print (data , file = sys .stderr )
278+
279+ return Domain (
280+ data = data ,
281+ whois_str = whois_str ,
282+ verbose = verbose ,
283+ include_raw_whois_text = include_raw_whois_text ,
284+ return_raw_text_for_unsupported_tld = True ,
285+ )
286+
287+
247288def query (
248289 domain : str ,
249290 force : bool = False ,
@@ -255,6 +296,7 @@ def query(
255296 with_cleanup_results = False ,
256297 internationalized : bool = False ,
257298 include_raw_whois_text : bool = False ,
299+ return_raw_text_for_unsupported_tld : bool = False ,
258300) -> Optional [Domain ]:
259301 """
260302 force=True Don't use cache.
@@ -270,15 +312,28 @@ def query(
270312 verbose: if true, print relevant information on steps taken to standard error
271313 include_raw_whois_text:
272314 if reqested the full response is also returned.
315+ return_raw_text_for_unsupported_tld:
316+ if the tld is unsupported, just try it anyway but return only the raw text.
273317 """
274318
275319 assert isinstance (domain , str ), Exception ("`domain` - must be <str>" )
320+ return_raw_text_for_unsupported_tld = bool (return_raw_text_for_unsupported_tld )
276321
277322 tld , dl = fromDomainStringToTld (domain , internationalized , verbose )
278323 if tld is None :
279324 return None
280325
281- thisTld = validateWeKnowTheToplevelDomain (tld ) # may raise UnknownTld
326+ thisTld = validateWeKnowTheToplevelDomain (tld , return_raw_text_for_unsupported_tld ) # may raise UnknownTld
327+ if thisTld is None :
328+ return doUnsupportedTldAnyway (
329+ tld ,
330+ dl ,
331+ ignore_returncode = ignore_returncode ,
332+ slow_down = slow_down ,
333+ server = server ,
334+ verbose = verbose ,
335+ )
336+
282337 verifyPrivateREgistry (thisTld ) # may raise WhoisPrivateRegistry
283338 server = doServerHintsForThisTld (tld , thisTld , server , verbose )
284339
0 commit comments