o b@sdZddlmZGdddeZGdddeZGdddeZGd d d eZGd d d ZGd ddZ GdddeZ GdddeZ dS)z Parser for inetd.conf files )Optionalc@eZdZdZdS)InvalidConfErrorz$ Invalid configuration file N__name__ __module__ __qualname____doc__r r :/usr/lib/python3/dist-packages/twisted/runner/inetdconf.pyr rc@r)InvalidInetdConfErrorz! Invalid inetd.conf file Nrr r r r r r r c@r)InvalidServicesConfErrorz Invalid services file Nrr r r r rr rc@r)UnknownServicez Unknown service name Nrr r r r rr rc@s@eZdZUdZdZdZeeed<d ddZ ddZ d d Z dS) 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. #NdefaultFilenamecCsd}|dur|jrt|j}d}z.|D]}||j}|dkr'|d|}|}|s.q||qW|r=|dSdS|rF|ww)z Parse a configuration file If file is None and self.defaultFilename is set, it will open defaultFilename and use it. FNT)ropen readlinesfind commentCharstrip parseLineclose)selffilerlinecommentr r r parseFile2s&       zSimpleConfFile.parseFilecCs4z |j|WdStytdt|w)z Override this. By default, this will split the line on whitespace and call self.parseFields (catching any errors). zInvalid line: N) parseFieldssplit ValueErrorr repr)rrr r r rQs  zSimpleConfFile.parseLinecGsdS)z Override this. Nr )rfieldsr r r r ]szSimpleConfFile.parseFieldsN) rrrr rrrstr__annotations__rrr r r r r r%s    rc@s<eZdZdZdZdZdZdZdZdZ dZ dZ dZ ddZ dS) InetdServicez3 A simple description of an inetd service. Nc Cs:||_||_||_||_||_||_||_||_| |_dSr%) nameport socketTypeprotocolwaitusergroupprogram programArgs) rr)r*r+r,r-r.r/r0r1r r r __init__rs zInetdService.__init__)rrrr r)r*r+r,r-r.r/r0r1r2r r r r r(cs r(c@s&eZdZdZdZdddZddZdS) InetdConfz> Configuration parser for a traditional UNIX inetd(8) z/etc/inetd.confNcCs&g|_|durt}|||_dSr%)services ServicesConfr knownServices)rr6r r r r2s  zInetdConf.__init__c Gs|ddgdd\}}|jj||fd} | s:|ds:zt|} d}Wnty9td|d|dw|jt || ||||||| dS) zx Parse an inetd.conf file. Implemented from the description in the Debian inetd.conf man page. .Nzrpc/unknownzUnknown service: z ()) r!r6r4get startswithint BaseExceptionrappendr() r serviceNamer+r,r-r.r0r1r/r*r r r r s,  zInetdConf.parseFieldsr%rrrr rr2r r r r r r3s   r3c@s$eZdZdZdZddZddZdS)r5zj /etc/services parser @ivar services: dict mapping service names to (port, protocol) tuples. z /etc/servicescCs i|_dSr%)r4)rr r r r2s zServicesConf.__init__cGsfz |d\}}t|}Wntytdt|w||j||f<|D] }||j||f<q'dS)N/zInvalid port/protocol: )r!r=r>rr#r4)rr)portAndProtocolaliasesr*r,aliasr r r r s   zServicesConf.parseFieldsNrAr r r r r5s  r5N) r typingr Exceptionrr rrrr(r3r5r r r r s >4