o
    ¯bµ  ã                   @   s�   d Z ddlmZ G dd„ deƒZG dd„ deƒZG dd„ deƒZG d	d
„ d
eƒZG dd„ dƒZG dd„ dƒZ	G dd„ deƒZ
G dd„ deƒZdS )z
Parser for inetd.conf files
é    )ÚOptionalc                   @   ó   e Zd ZdZdS )ÚInvalidConfErrorz$
    Invalid configuration file
    N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r
   r
   ú:/usr/lib/python3/dist-packages/twisted/runner/inetdconf.pyr      ó    r   c                   @   r   )ÚInvalidInetdConfErrorz!
    Invalid inetd.conf file
    Nr   r
   r
   r
   r   r      r   r   c                   @   r   )ÚInvalidServicesConfErrorz
    Invalid services file
    Nr   r
   r
   r
   r   r      r   r   c                   @   r   )ÚUnknownServicez
    Unknown service name
    Nr   r
   r
   r
   r   r      r   r   c                   @   s@   e Zd ZU dZdZdZee ed< ddd„Z	dd„ Z
d	d
„ ZdS )ÚSimpleConfFilezÒ
    Simple configuration file parser superclass.

    Filters out comments and empty lines (which includes lines that only
    contain comments).

    To use this class, override parseLine or parseFields.
    ú#NÚdefaultFilenamec                 C   sŽ   d}|du r| j rt| j ƒ}d}z.| ¡ D ]}| | j¡}|dkr'|d|… }| ¡ }|s.q|  |¡ qW |r=| ¡  dS dS |rF| ¡  w w )z—
        Parse a configuration file

        If file is None and self.defaultFilename is set, it will open
        defaultFilename and use it.
        FNTéÿÿÿÿ)r   ÚopenÚ	readlinesÚfindÚcommentCharÚstripÚ	parseLineÚclose)ÚselfÚfiler   ÚlineÚcommentr
   r
   r   Ú	parseFile2   s&   
óÿ
ÿzSimpleConfFile.parseFilec                 C   s4   z
| j | ¡ Ž  W dS  ty   tdt|ƒ ƒ‚w )z•
        Override this.

        By default, this will split the line on whitespace and call
        self.parseFields (catching any errors).
        zInvalid line: N)ÚparseFieldsÚsplitÚ
ValueErrorr   Úrepr)r   r   r
   r
   r   r   Q   s
   ÿzSimpleConfFile.parseLinec                 G   s   dS )z 
        Override this.
        Nr
   )r   Úfieldsr
   r
   r   r    ]   s    zSimpleConfFile.parseFields©N)r   r   r   r	   r   r   r   ÚstrÚ__annotations__r   r   r    r
   r
   r
   r   r   %   s   
 	
r   c                   @   s<   e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdd„ ZdS )ÚInetdServicez3
    A simple description of an inetd service.
    Nc
           
      C   s:   || _ || _|| _|| _|| _|| _|| _|| _|	| _d S r%   )	ÚnameÚportÚ
socketTypeÚprotocolÚwaitÚuserÚgroupÚprogramÚprogramArgs)
r   r)   r*   r+   r,   r-   r.   r/   r0   r1   r
   r
   r   Ú__init__r   s   
zInetdService.__init__)r   r   r   r	   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r
   r
   r
   r   r(   c   s    r(   c                   @   s&   e Zd ZdZdZddd„Zdd„ ZdS )	Ú	InetdConfz>
    Configuration parser for a traditional UNIX inetd(8)
    z/etc/inetd.confNc                 C   s&   g | _ |d u rtƒ }| ¡  || _d S r%   )ÚservicesÚServicesConfr   ÚknownServices)r   r6   r
   r
   r   r2   ‡   s
   
zInetdConf.__init__c           
      G   s˜   |  d¡dg dd… \}}| jj ||fd¡}	|	s:| d¡s:zt|ƒ}	d}W n ty9   td|› d|› d�ƒ‚w | j t	||	|||||||ƒ	¡ dS )	zx
        Parse an inetd.conf file.

        Implemented from the description in the Debian inetd.conf man page.
        Ú.Né   zrpc/ÚunknownzUnknown service: z (ú))
r!   r6   r4   ÚgetÚ
startswithÚintÚBaseExceptionr   Úappendr(   )
r   ÚserviceNamer+   r,   r-   r.   r0   r1   r/   r*   r
   r
   r   r    �   s,   	ÿ÷ÿzInetdConf.parseFieldsr%   ©r   r   r   r	   r   r2   r    r
   r
   r
   r   r3   €   s
    
r3   c                   @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )r5   zj
    /etc/services parser

    @ivar services: dict mapping service names to (port, protocol) tuples.
    z/etc/servicesc                 C   s
   i | _ d S r%   )r4   )r   r
   r
   r   r2   ½   s   
zServicesConf.__init__c                 G   sf   z|  d¡\}}t|ƒ}W n ty   tdt|ƒ› �ƒ‚w || j||f< |D ]	}|| j||f< q'd S )Nú/zInvalid port/protocol: )r!   r=   r>   r   r#   r4   )r   r)   ÚportAndProtocolÚaliasesr*   r,   Úaliasr
   r
   r   r    À   s   ÿÿÿzServicesConf.parseFieldsNrA   r
   r
   r
   r   r5   ´   s
    r5   N)r	   Útypingr   Ú	Exceptionr   r   r   r   r   r(   r3   r5   r
   r
   r
   r   Ú<module>   s   >4