ϪfdZddlmZGddeZGddeZGddeZGd d eZGd d ZGd dZ GddeZ GddeZ y)z Parser for inetd.conf files )OptionalceZdZdZy)InvalidConfErrorz$ Invalid configuration file N__name__ __module__ __qualname____doc__:/usr/lib/python3/dist-packages/twisted/runner/inetdconf.pyrr r rceZdZdZy)InvalidInetdConfErrorz! Invalid inetd.conf file Nrr r r rrrr rceZdZdZy)InvalidServicesConfErrorz Invalid services file Nrr r r rrrr rceZdZdZy)UnknownServicez Unknown service name Nrr r r rrrr rc>eZdZUdZdZdZeeed<ddZ dZ dZ 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. #NdefaultFilenamechd}|#|jrt|j}d} |jD]K}|j|j}|dk7r|d|}|j }|s;|j |M |r|jyy#|r|jwwxYw)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)selffiler!linecomments r parseFilezSimpleConfFile.parseFile2s Dzz|t$ % u s ABB1c |j|jy#t$rtdt |zwxYw)z Override this. By default, this will split the line on whitespace and call self.parseFields (catching any errors). zInvalid line: N) parseFieldssplit ValueErrorrrepr)r"r$s r r zSimpleConfFile.parseLineQsD G D  djjl + G'(84:(EF F Gs  !Acy)z Override this. Nr )r"fieldss r r(zSimpleConfFile.parseFields]sr N) rrr r rrrstr__annotations__r&r r(r r r rr%s,K%)OXc])> G r rc:eZdZdZdZdZdZdZdZdZ dZ dZ dZ dZ y) InetdServicez3 A simple description of an inetd service. Nc ||_||_||_||_||_||_||_||_| |_yr.) nameport socketTypeprotocolwaitusergroupprogram programArgs) r"r4r5r6r7r8r9r:r;r<s r __init__zInetdService.__init__rsD  $      &r )rrr r r4r5r6r7r8r9r:r;r<r=r r r r2r2cs; D DJH D D EGK 'r r2c"eZdZdZdZddZdZy) InetdConfz> Configuration parser for a traditional UNIX inetd(8) z/etc/inetd.confNcXg|_|t}|j||_yr.)services ServicesConfr& knownServices)r"rCs r r=zInetdConf.__init__s*  (NM  # # %*r c b|jddgzdd\}}|jjj||fd} | s|j ds t |} d}|jjt|| ||||||| y#t $rtd|d|dwxYw) zx Parse an inetd.conf file. Implemented from the description in the Debian inetd.conf man page. .Nzrpc/unknownzUnknown service: z ()) r)rCrAget startswithint BaseExceptionrappendr2) r" serviceNamer6r7r8r9r;r<r:r5s r r(zInetdConf.parseFieldsszz#$/!4 e!!**.. X/FMH//7 U;''     ! U$'8 RzQR%STT Us  BB.r.rrr r rr=r(r r r r?r?s(O+" r r?c eZdZdZdZdZdZy)rBzj /etc/services parser @ivar services: dict mapping service names to (port, protocol) tuples. z /etc/servicesci|_yr.)rA)r"s r r=zServicesConf.__init__s  r c |jd\}}t|}||j ||f<|D]}||j ||f<y#t$rtdt |wxYw)N/zInvalid port/protocol: )r)rKrLrr+rA)r"r4portAndProtocolaliasesr5r7aliass r r(zServicesConf.parseFieldss ,2237ND(t9D +/ tX&' 4E/3DMM5(+ , 4  *)$*?)@A  s A !A,NrOr r r rBrBs &O 4r rBN) r typingr Exceptionrrrrrr2r?rBr r r rYso y , / Y ; ; |'':1 1 h4>4r