import json
import api

class WWWDomain(api.API):

    def __init__(self, auth_handler):
        self.url = auth_handler.url
        self.sessid = auth_handler.sessid
        self.func = 'wwwdomain.edit'
        self.out = 'json'
        self.params = {
            'auth' : self.sessid,
            'out'  : self.out,
            'func' : self.func,
        }

    def list(self, domain=None):
        """List all www domains. If domains is used, list details about this one."""
        if domain:
            self.params['elid'] = domain
        else:
            self.params['func'] = 'wwwdomain'
        data = self.process_api(self.url, self.params)
        out = json.load(data)
        try:
            return out['elem']
        except KeyError:
            return out

    def add(self, domain='',  owner='', admin='', ip='', **kwargs):
        """Add a new wwwdomain to configuration. If a DNS server is configurated, API adds
        domain there too."""
        self.params['sok']    = 'yes'
        self.params['domain'] = domain
        self.params['owner']  = owner
        self.params['admin']  = admin
        self.params['ip']     = ip
        for key in kwargs:
            self.params[key] = kwargs[key]

        data = self.process_api(self.url, self.params)
        out = json.load(data)
        return out


@@ -223,16 +223,163 @@
  'json'%0A
+        self._clear_params()%0A%0A    def _clear_params(self):%0A        try:%0A            self.params.clear()%0A        except NameError:%0A            pass%0A
         
@@ -394,16 +394,16 @@
 ams = %7B%0A
-
         
@@ -449,24 +449,22 @@
 out'  : 
-self.out
+'json'
 ,%0A      
@@ -533,16 +533,16 @@
 =None):%0A
-
         
@@ -614,24 +614,53 @@
 his one.%22%22%22%0A
+        self._clear_params()%0A
         if d
@@ -1129,24 +1129,53 @@
 ere too.%22%22%22%0A
+        self._clear_params()%0A
         self

Clear parameters before editing/adding. Before it was been unpossible to call two functions in sequence.