(self)
Save any outstanding items. This returns a Deferred which will
        errback if Tor was unhappy with anything, or callback with
        this TorConfig object on success.
Save any outstanding items. This returns a Deferred which will
        errback if Tor was unhappy with anything, or callback with
        this TorConfig object on success.
Save any outstanding items . This returns a Deferred which will errback if Tor was unhappy with anything or callback with this TorConfig object on success .
def save(self):
        """
        Save any outstanding items. This returns a Deferred which will
        errback if Tor was unhappy with anything, or callback with
        this TorConfig object on success.
        """

        if not self.needs_save():
            return defer.succeed(self)

        args = []
        directories = []
        for (key, value) in self.unsaved.items():
            if key == 'HiddenServices':
                self.config['HiddenServices'] = value
                # using a list here because at least one unit-test
                # cares about order -- and conceivably order *could*
                # matter here, to Tor...
                services = list()
                # authenticated services get flattened into the HiddenServices list...
                for hs in value:
                    if IOnionClient.providedBy(hs):
                        parent = IOnionClient(hs).parent
                        if parent not in services:
                            services.append(parent)
                    elif isinstance(hs, (EphemeralOnionService, EphemeralHiddenService)):
                        raise ValueError(
                            "Only filesystem based Onion services may be added"
                            " via TorConfig.hiddenservices; ephemeral services"
                            " must be created with 'create_onion_service'."
                        )
                    else:
                        if hs not in services:
                            services.append(hs)

                for hs in services:
                    for (k, v) in hs.config_attributes():
                        if k == 'HiddenServiceDir':
                            if v not in directories:
                                directories.append(v)
                                args.append(k)
                                args.append(v)
                            else:
                                raise RuntimeError("Trying to add hidden service with same HiddenServiceDir: %s" % v)
                        else:
                            args.append(k)
                            args.append(v)
                continue

            if isinstance(value, list):
                for x in value:
                    # FIXME XXX
                    if x is not DEFAULT_VALUE:
                        args.append(key)
                        args.append(str(x))

            else:
                args.append(key)
                args.append(value)

            # FIXME in future we should wait for CONF_CHANGED and
            # update then, right?
            real_name = self._find_real_name(key)
            if not isinstance(value, list) and real_name in self.parsers:
                value = self.parsers[real_name].parse(value)
            self.config[real_name] = value

        # FIXME might want to re-think this, but currently there's no
        # way to put things into a config and get them out again
        # nicely...unless you just don't assign a protocol
        if self.protocol:
            d = self.protocol.set_conf(*args)
            d.addCallback(self._save_completed)
            return d

        else:
            self._save_completed()
            return defer.succeed(self)
def save ( self ) : if not self . needs_save ( ) : return defer . succeed ( self ) args = [ ] directories = [ ] for ( key , value ) in self . unsaved . items ( ) : if key == 'HiddenServices' : self . config [ 'HiddenServices' ] = value # using a list here because at least one unit-test # cares about order -- and conceivably order *could* # matter here, to Tor... services = list ( ) # authenticated services get flattened into the HiddenServices list... for hs in value : if IOnionClient . providedBy ( hs ) : parent = IOnionClient ( hs ) . parent if parent not in services : services . append ( parent ) elif isinstance ( hs , ( EphemeralOnionService , EphemeralHiddenService ) ) : raise ValueError ( "Only filesystem based Onion services may be added" " via TorConfig.hiddenservices; ephemeral services" " must be created with 'create_onion_service'." ) else : if hs not in services : services . append ( hs ) for hs in services : for ( k , v ) in hs . config_attributes ( ) : if k == 'HiddenServiceDir' : if v not in directories : directories . append ( v ) args . append ( k ) args . append ( v ) else : raise RuntimeError ( "Trying to add hidden service with same HiddenServiceDir: %s" % v ) else : args . append ( k ) args . append ( v ) continue if isinstance ( value , list ) : for x in value : # FIXME XXX if x is not DEFAULT_VALUE : args . append ( key ) args . append ( str ( x ) ) else : args . append ( key ) args . append ( value ) # FIXME in future we should wait for CONF_CHANGED and # update then, right? real_name = self . _find_real_name ( key ) if not isinstance ( value , list ) and real_name in self . parsers : value = self . parsers [ real_name ] . parse ( value ) self . config [ real_name ] = value # FIXME might want to re-think this, but currently there's no # way to put things into a config and get them out again # nicely...unless you just don't assign a protocol if self . protocol : d = self . protocol . set_conf ( * args ) d . addCallback ( self . _save_completed ) return d else : self . _save_completed ( ) return defer . succeed ( self )