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