o
    Chs                     @   s   d dl Z d dlmZ d dlmZmZmZmZ d dl	m
Z
 ddlmZmZ ddlmZ dZd	Zd
ZdZe eZG dd deZG dd dedZdS )    N)open)Dict	ItemsViewOptionalUnion)urlopen   )TldImproperlyConfigured
TldIOError)project_dirzArtur Barseghyanz2013-2025 Artur Barseghyanz,MPL-1.1 OR GPL-2.0-only OR LGPL-2.1-or-later)BaseTLDSourceParserRegistryc                	   @   s   e Zd ZU i Zeedf ed< dd ZedefddZ	e
dd	d
Ze
	ddeddded fddZe
deedf fddZdS )r   r   REGISTRYc                 C   s,   t | |||}t|dd r|| j|j< |S )N_uid)type__new__getattrr   r   )mcsnamebasesattrsnew_cls r   I/home/air/segue/gemini/back/venv/lib/python3.10/site-packages/tld/base.pyr      s   zRegistry.__new__returnc                 C   s   t | d| jS )Nuid)r   __name__clsr   r   r   r       s   zRegistry._uidNc                 C   s
   i | _ d S N)r   r   r   r   r   reset$      
zRegistry.resetkeydefault)r   Nc                 C   s   | j ||S r   )r   get)r   r#   r$   r   r   r   r%   (   s   zRegistry.getc                 C   s
   | j  S r   )r   itemsr    r   r   r   r&   .   r"   zRegistry.items)r   Nr   )r   
__module____qualname__r   r   str__annotations__r   propertyr   classmethodr!   r   r%   r   r&   r   r   r   r   r      s$   
 r   c                   @   sz   e Zd ZU dZdZee ed< eed< eed< dZe	ed< e
dd	 Ze
dde	defddZe
dde	de	fddZdS )r   zBase TLD source parser.Nr   
source_url
local_pathTinclude_privatec                 C   s   | j stddS )zConstructor.z=The `uid` property of the TLD source parser shall be defined.N)r   r	   r   r   r   r   validateC   s
   zBaseTLDSourceParser.validateFr   fail_silentlyretry_countc                 C   s   |    td)zcGet tld names.

        :param fail_silently:
        :param retry_count:
        :return:
        z>Your TLD source parser shall implement `get_tld_names` method.)r0   NotImplementedError)r   r1   r2   r   r   r   get_tld_namesK   s   z!BaseTLDSourceParser.get_tld_namesr   c              
   C   s   z3t | j}t| j}t|ddd}|| d |  |  t	
d| j d| d W dS  tyZ } zt	d| j dt|  |rRW Y d	}~d
S t|d	}~ww )z_Update the local copy of the TLD file.

        :param fail_silently:
        :return:
        wbutf8)encodingz	Fetched 'z' as ''zFailed fetching 'z'. Reason: NFT)r   r-   r   r.   codecs_openwritereaddecodecloseLOGGERinfo	Exceptionerrorr)   r
   )r   r1   remote_filelocal_file_abs_path
local_fileerrr   r   r   update_tld_namesX   s(   

z$BaseTLDSourceParser.update_tld_names)Fr   )F)r   r'   r(   __doc__r   r   r)   r*   r/   boolr,   r0   intr4   rF   r   r   r   r   r   ;   s   
 
r   )	metaclass)loggingcodecsr   r9   typingr   r   r   r   urllib.requestr   
exceptionsr	   r
   helpersr   
__author____copyright____license____all__	getLoggerr   r>   r   r   r   r   r   r   r   <module>   s    
'