HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/sos/cleaner/parsers/__pycache__/hostname_parser.cpython-310.pyc
o

���b�
�@s,ddlmZddlmZGdd�de�ZdS)�)�SoSCleanerParser)�SoSHostnameMapcsDeZdZdZdZdgZd
�fdd�	Zdd�Zd	d
�Zdd�Z	�Z
S)�SoSHostnameParserzHostname Parser�hostname_mapz5(((\b|_)[a-zA-Z0-9-\.]{1,200}\.[a-zA-Z]{1,63}(\b|_)))NcsJt�|_tt|��|�|j��|j�|�g|_|��|j�	�dS�N)
r�mapping�superr�__init__�load_domains_from_map�load_domains_from_options�short_names�load_short_names_from_mapping�set_initial_counts)�self�config�opt_domains��	__class__��E/usr/lib/python3/dist-packages/sos/cleaner/parsers/hostname_parser.pyr	s
zSoSHostnameParser.__init__cCs>|jj��D]}t|�d��dkr||jvr|j�|�qdS)aWhen we load the mapping file into the hostname map, we have to do
        some dancing to get those loaded properly into the "intermediate" dicts
        that the map uses to hold hosts and domains. Similarly, we need to also
        extract shortnames known to the map here.
        �.�N)r�dataset�keys�len�splitr�append)r�hnamerrrr
 s
��z/SoSHostnameParser.load_short_names_from_mappingcCszd|vrdS|�d�}t|�dkr|j�|d�n|j�|�t|�dkr5d�|dd��}|j�|�|j�|�dS)z�Force add the domainname found in /sos_commands/host/hostname into
        the map. We have to do this here since the normal map prep approach
        from the parser would be ignored since the system's hostname is not
        guaranteed
        �	localhostNrrr����)rrrr�joinr�add)r�hostname_string�domains�high_domainrrr�load_hostname_into_map,s
z(SoSHostnameParser.load_hostname_into_mapcCs||��}|D]5}|�d�sd|vrq|��dd�}|D]}t|�d��dkr4|j�|�|j�|�q|j�|�qqdS)a$Parse an archive's copy of /etc/hosts, which requires handling that
        is separate from the output of the `hostname` command. Just like
        load_hostname_into_map(), this has to be done explicitly and we
        cannot rely upon the more generic methods to do this reliably.
        �#rrNr)	�
splitlines�
startswithrrrrr�add_regex_itemr")r�content�lines�line�hostln�hostrrr�load_hostname_from_etc_hosts@s��z.SoSHostnameParser.load_hostname_from_etc_hostsr)�__name__�
__module__�__qualname__�name�map_file_key�regex_patternsr	r
r&r0�
__classcell__rrrrrs�	rN)�sos.cleaner.parsersr�!sos.cleaner.mappings.hostname_maprrrrrr�<module>s