<s> """<STR_LIT>""" <EOL> from twisted . python . deprecate import deprecatedModuleAttribute <EOL> from twisted . python . versions import Version <EOL> class InvalidConfError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class InvalidInetdConfError ( InvalidConfError ) : <EOL> """<STR_LIT>""" <EOL> class InvalidServicesConfError ( InvalidConfError ) : <EOL> """<STR_LIT>""" <EOL> class InvalidRPCServicesConfError ( InvalidConfError ) : <EOL> """<STR_LIT>""" <EOL> deprecatedModuleAttribute ( <EOL> Version ( "<STR_LIT>" , <NUM_LIT:16> , <NUM_LIT:2> , <NUM_LIT:0> ) , <EOL> "<STR_LIT>" , <EOL> __name__ , "<STR_LIT>" ) <EOL> class UnknownService ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class SimpleConfFile : <EOL> """<STR_LIT>""" <EOL> commentChar = '<STR_LIT:#>' <EOL> defaultFilename = None <EOL> def parseFile ( self , file = None ) : <EOL> """<STR_LIT>""" <EOL> if file is None and self . defaultFilename : <EOL> file = open ( self . defaultFilename , '<STR_LIT:r>' ) <EOL> for line in file . readlines ( ) : <EOL> comment = line . find ( self . commentChar ) <EOL> if comment != - <NUM_LIT:1> : <EOL> line = line [ : comment ] <EOL> line = line . strip ( ) <EOL> if not line : <EOL> continue <EOL> self . parseLine ( line ) <EOL> def parseLine ( self , line ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . parseFields ( * line . split ( ) ) <EOL> except ValueError : <EOL> raise InvalidInetdConfError , '<STR_LIT>' + repr ( line ) <EOL> def parseFields ( self , * fields ) : <EOL> """<STR_LIT>""" <EOL> class InetdService : <EOL> """<STR_LIT>""" <EOL> name = None <EOL> port = None <EOL> socketType = None <EOL> protocol = None <EOL> wait = None <EOL> user = None <EOL> group = None <EOL> program = None <EOL> programArgs = None <EOL> def __init__ ( self , name , port , socketType , protocol , wait , user , group , <EOL> program , programArgs ) : <EOL> self . name = name <EOL> self . port = port <EOL> self . socketType = socketType <EOL> self . protocol = protocol <EOL> self . wait = wait <EOL> self . user = user <EOL> self . group = group <EOL> self . program = program <EOL> self . programArgs = programArgs <EOL> class InetdConf ( SimpleConfFile ) : <EOL> """<STR_LIT>""" <EOL> defaultFilename = '<STR_LIT>' <EOL> def __init__ ( self , knownServices = None ) : <EOL> self . services = [ ] <EOL> if knownServices is None : <EOL> knownServices = ServicesConf ( ) <EOL> knownServices . parseFile ( ) <EOL> self . knownServices = knownServices <EOL> def parseFields ( self , serviceName , socketType , protocol , wait , user , <EOL> program , * programArgs ) : <EOL> """<STR_LIT>""" <EOL> user , group = ( user . split ( '<STR_LIT:.>' ) + [ None ] ) [ : <NUM_LIT:2> ] <EOL> port = self . knownServices . services . get ( ( serviceName , protocol ) , None ) <EOL> if not port and not protocol . startswith ( '<STR_LIT>' ) : <EOL> try : <EOL> port = int ( serviceName ) <EOL> serviceName = '<STR_LIT>' <EOL> except : <EOL> raise UnknownService , "<STR_LIT>" % ( serviceName , protocol ) <EOL> self . services . append ( InetdService ( serviceName , port , socketType , <EOL> protocol , wait , user , group , program , <EOL> programArgs ) ) <EOL> class ServicesConf ( SimpleConfFile ) : <EOL> """<STR_LIT>""" <EOL> defaultFilename = '<STR_LIT>' <EOL> def __init__ ( self ) : <EOL> self . services = { } <EOL> def parseFields ( self , name , portAndProtocol , * aliases ) : <EOL> try : <EOL> port , protocol = portAndProtocol . split ( '<STR_LIT:/>' ) <EOL> port = long ( port ) <EOL> except : <EOL> raise InvalidServicesConfError , '<STR_LIT>' + repr ( portAndProtocol ) <EOL> self . services [ ( name , protocol ) ] = port <EOL> for alias in aliases : <EOL> self . services [ ( alias , protocol ) ] = port <EOL> class RPCServicesConf ( SimpleConfFile ) : <EOL> """<STR_LIT>""" <EOL> deprecatedModuleAttribute ( <EOL> Version ( "<STR_LIT>" , <NUM_LIT:16> , <NUM_LIT:2> , <NUM_LIT:0> ) , <EOL> "<STR_LIT>" , <EOL> __name__ , "<STR_LIT>" ) <EOL> defaultFilename = '<STR_LIT>' <EOL> def __init__ ( self ) : <EOL> self . services = { } <EOL> def parseFields ( self , name , port , * aliases ) : <EOL> try : <EOL> port = long ( port ) <EOL> except : <EOL> raise InvalidRPCServicesConfError , '<STR_LIT>' + repr ( port ) <EOL> self . services [ name ] = port <EOL> for alias in aliases : <EOL> self . services [ alias ] = port </s>
