Beispiel #1
0
    def parseSetting(self, key, value):
        """
        Parse a single setting for this object.

        Settings are written in text files in a key=value fashion.
        For each such setting that belongs to this object this method will be called.

        After all settings have been given, the method checkSettings will be called.

        If a setting does not parse correctly, this method raises an Exception with a descriptive message.

        Subclassers should first parse their own settings and then call this implementation to have the
        generic settings parsed and to have any unknown settings raise an Exception.
        
        @param  key     The name of the parameter, i.e. the key from the key=value pair.
        @param  value   The value of the parameter, i.e. the value from the key=value pair.
        """
        if key == 'listenAddress':
            if self.listenAddress:
                parseError( "listenAddress is already set: {0}".format( self.listenAddress ) )
            if containsSpace(value):
                parseError( "listenAddress may not contain any whitespace" )
            self.listenAddress = value
        elif key == 'listenPort':
            if self.listenPort:
                parseError( "listenPort is already set: {0}".format( self.listenPort ) )
            if not isPositiveInt( value, True ):
                parseError( "listenPort must be a positive integer" )
            self.listenPort = int(value)
        elif key == 'tracker':
            if self.tracker:
                parseError( "tracker is already set: {0}".format( self.tracker ) )
            if containsSpace(value):
                parseError( "tracker may not contain any whitespace" )
            self.tracker = value
        elif key == 'wait':
            if self.wait:
                parseError( "wait is already set: {0}".format( self.wait ) )
            if not isPositiveInt( value, True ):
                parseError( "wait must be a positive integer" )
            self.wait = int(value)
        elif key == 'chunkSize':
            if self.chunkSize:
                parseError( "chunck size is already set: {0}".format( self.chunkSize ) )
            if not isPositiveInt( value, True ):
                parseError( "chunck size must be a positive integer" )
            if int(value) % 1024 != 0:
                parseError( "chunk sizes not divisible by 1024 are not supported" )                
            self.chunkSize = int(value)
        else:
            client.parseSetting(self, key, value)
Beispiel #2
0
    def parseSetting(self, key, value):
        """
        Parse a single setting for this object.

        Settings are written in text files in a key=value fashion.
        For each such setting that belongs to this object this method will be called.

        After all settings have been given, the method checkSettings will be called.

        If a setting does not parse correctly, this method raises an Exception with a descriptive message.

        Subclassers should first parse their own settings and then call this implementation to have the
        generic settings parsed and to have any unknown settings raise an Exception.
        
        @param  key     The name of the parameter, i.e. the key from the key=value pair.
        @param  value   The value of the parameter, i.e. the value from the key=value pair.
        """
        if key == 'hostname':
            if self.hostname:
                parseError( "The hostname was already set: {0}".format( self.hostname ) )
            if containsSpace( value ):
                parseError( "A hostname must not contain spaces" )
            self.hostname = value
        elif key == 'port':
            if self.port:
                parseError( "The port was already set: {0}".format( self.port ) )
            if not isPositiveInt( value, True ):
                parseError( "The port must be a positive, non-zero integer" )
            self.port = value
        elif key == 'user':
            if self.user:
                parseError( "The user was already set: {0}".format( self.user ) )
            self.user = value
        else:
            host.parseSetting(self, key, value)