
    \d                         d Z ddlmZ  G d de          Z G d de          Z G d de          Z G d	 d
e          Z G d d          Z G d d          Z	 G d de          Z
 G 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__     8lib/python3.11/site-packages/twisted/runner/inetdconf.pyr   r                 r   r   c                       e Zd ZdZdS )InvalidInetdConfErrorz!
    Invalid inetd.conf file
    Nr   r   r   r   r   r      r   r   r   c                       e Zd ZdZdS )InvalidServicesConfErrorz
    Invalid services file
    Nr   r   r   r   r   r      r   r   r   c                       e Zd ZdZdS )UnknownServicez
    Unknown service name
    Nr   r   r   r   r   r      r   r   r   c                   F    e Zd ZU dZdZdZee         ed<   ddZ	d Z
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                    d}|| j         rt          | j                   }d}	 |                                D ]X}|                    | j                  }|dk    r
|d|         }|                                }|sC|                     |           Y	 |r|                                 dS dS # |r|                                 w w xY 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comments        r   	parseFilezSimpleConfFile.parseFile2   s     <D0<,--DE	(( % %))D$455b==>D zz||  t$$$$%  

 u 

s   A-B+ +Cc                     	  | j         |                                  dS # t          $ r  t          dt	          |          z             w xY 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$   s     r   r    zSimpleConfFile.parseLineQ   s_    	GDdjjll++++ 	G 	G 	G'(84::(EFFF	Gs	     *A
c                     dS )z 
        Override this.
        Nr   )r"   fieldss     r   r(   zSimpleConfFile.parseFields]   s      r   N)r   r   r	   r
   r   r   r   str__annotations__r&   r    r(   r   r   r   r   r   %   sp           K%)OXc])))   >
G 
G 
G    r   r   c                   <    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 ZdS )InetdServicez3
    A simple description of an inetd service.
    Nc
                     || _         || _        || _        || _        || _        || _        || _        || _        |	| _        d S r.   )	nameport
socketTypeprotocolwaitusergroupprogramprogramArgs)
r"   r4   r5   r6   r7   r8   r9   r:   r;   r<   s
             r   __init__zInetdService.__init__r   sJ     		$ 		
&r   )r   r   r	   r
   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r   r   r   r2   r2   c   s\          DDJHDDEGK' ' ' ' 'r   r2   c                   $    e Zd ZdZdZddZd ZdS )	InetdConfz>
    Configuration parser for a traditional UNIX inetd(8)
    z/etc/inetd.confNc                 j    g | _         |"t                      }|                                 || _        d S r.   )servicesServicesConfr&   knownServices)r"   rC   s     r   r=   zInetdConf.__init__   s8     (NNM##%%%*r   c                    |                     d          dgz   dd         \  }}| j        j                            ||fd          }	|	sL|                    d          s7	 t          |          }	d}n$# t          $ r t          d| d| d          w xY 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)   rC   rA   get
startswithintBaseExceptionr   appendr2   )
r"   serviceNamer6   r7   r8   r9   r;   r<   r:   r5   s
             r   r(   zInetdConf.parseFields   s    zz#$/!4e !*..X/FMM 	UH//77 	UU;'''  U U U$%S%S%S%S%S%STTTU 	
 
	
 	
 	
 	
 	
s   A1 1!Br.   r   r   r	   r
   r   r=   r(   r   r   r   r?   r?      sH          (O+ + + +"
 "
 "
 "
 "
r   r?   c                   "    e Zd ZdZdZd Zd ZdS )rB   zj
    /etc/services parser

    @ivar services: dict mapping service names to (port, protocol) tuples.
    z/etc/servicesc                     i | _         d S r.   )rA   )r"   s    r   r=   zServicesConf.__init__   s    r   c                     	 |                     d          \  }}t          |          }n-# t          $ r  t          dt	          |                     w xY w|| j        ||f<   |D ]}|| j        ||f<   d S )N/zInvalid port/protocol: )r)   rK   rL   r   r+   rA   )r"   r4   portAndProtocolaliasesr5   r7   aliass          r   r(   zServicesConf.parseFields   s    	,22377ND(t99DD 	 	 	*A$*?*?AA  	
 +/tX&' 	4 	4E/3DM5(+,,	4 	4s	   '* *ANrO   r   r   r   rB   rB      sC          &O  4 4 4 4 4r   rB   N)r
   typingr   	Exceptionr   r   r   r   r   r2   r?   rB   r   r   r   <module>rY      s}  
           y       ,       /       Y   ; ; ; ; ; ; ; ;|' ' ' ' ' ' ' ':1
 1
 1
 1
 1
 1
 1
 1
h4 4 4 4 4> 4 4 4 4 4r   