
    Ϫf                         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y)z
Parser for inetd.conf files
    )Optionalc                       e Zd ZdZy)InvalidConfErrorz$
    Invalid configuration file
    N__name__
__module____qualname____doc__     :/usr/lib/python3/dist-packages/twisted/runner/inetdconf.pyr   r          r   r   c                       e Zd ZdZy)InvalidInetdConfErrorz!
    Invalid inetd.conf file
    Nr   r   r   r   r   r      r   r   r   c                       e Zd ZdZy)InvalidServicesConfErrorz
    Invalid services file
    Nr   r   r   r   r   r      r   r   r   c                       e Zd ZdZy)UnknownServicez
    Unknown service name
    Nr   r   r   r   r   r      r   r   r   c                   >    e Zd ZU dZdZdZee   ed<   ddZ	d Z
d Zy)	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                 h   d}|#| j                   rt        | j                         }d}	 |j                         D ]K  }|j                  | j                        }|dk7  r|d| }|j                         }|s;| j                  |       M 	 |r|j                          yy# |r|j                          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0,,-DE	( %))D$4$45b=>D zz| t$% 

 u

 s   AB B1c                     	  | j                   |j                           y# 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   sD    	GDdjjl+ 	G'(84:(EFF	Gs	     !Ac                      y)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   %   s,     K%)OXc])>
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y)InetdServicez3
    A simple description of an inetd service.
    Nc
                     || _         || _        || _        || _        || _        || _        || _        || _        |	| _        y 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   sD     		$ 		
&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y)	InetdConfz>
    Configuration parser for a traditional UNIX inetd(8)
    z/etc/inetd.confNc                 X    g | _         |t               }|j                          || _        y r.   )servicesServicesConfr&   knownServices)r"   rC   s     r   r=   zInetdConf.__init__   s*     (NM##%*r   c                 b   |j                  d      dgz   dd \  }}| j                  j                  j                  ||fd      }	|	s|j	                  d      s	 t        |      }	d}| j                  j                  t        ||	|||||||	             y# t        $ r t        d| d| d      w xY w)	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H//7U;'' 	
	
 ! U$'8RzQR%STTUs   B B.r.   r   r   r	   r
   r   r=   r(   r   r   r   r?   r?      s     (O+"
r   r?   c                        e Zd ZdZdZd Zd Zy)rB   zj
    /etc/services parser

    @ivar services: dict mapping service names to (port, protocol) tuples.
    z/etc/servicesc                     i | _         y r.   )rA   )r"   s    r   r=   zServicesConf.__init__   s	    r   c                     	 |j                  d      \  }}t        |      }|| j
                  ||f<   |D ]  }|| j
                  ||f<    y # t        $ r t        dt	        |             w xY w)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7ND(t9D +/tX&' 	4E/3DMM5(+,	4  	*)$*?)@A 	s   A !A,NrO   r   r   r   rB   rB      s     &O4r   rB   N)r
   typingr   	Exceptionr   r   r   r   r   r2   r?   rB   r   r   r   <module>rY      so   
 y , / Y ; ;|' ':1
 1
h4> 4r   