debuggers.hg
changeset 6968:578a73fdeb2f
Changed dangerous default parameter values where used to use None instead.
Renamed variables type and ord since these clash with built-in names. Renamed
unused variables to mark them as such. Changed scheduler.py to use *args and
**kwargs rather than the strange non-idiomatic imitation of the same.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
Renamed variables type and ord since these clash with built-in names. Renamed
unused variables to mark them as such. Changed scheduler.py to use *args and
**kwargs rather than the strange non-idiomatic imitation of the same.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | emellor@ewan |
---|---|
date | Sun Sep 18 22:41:12 2005 +0100 (2005-09-18) |
parents | f7a09745ca56 |
children | 8f9dfc5fb51c |
files | tools/python/xen/xend/Args.py tools/python/xen/xend/EventServer.py tools/python/xen/xend/Vifctl.py tools/python/xen/xend/scheduler.py tools/python/xen/xend/xenstore/xswatch.py |
line diff
1.1 --- a/tools/python/xen/xend/Args.py Sun Sep 18 18:21:12 2005 +0100 1.2 +++ b/tools/python/xen/xend/Args.py Sun Sep 18 22:41:12 2005 +0100 1.3 @@ -32,12 +32,12 @@ class Args: 1.4 self.arg_dict = {} 1.5 self.key_ord = [] 1.6 self.key_dict = {} 1.7 - for (name, type) in paramspec: 1.8 + for (name, typ) in paramspec: 1.9 self.arg_ord.append(name) 1.10 - self.arg_dict[name] = type 1.11 - for (name, type) in keyspec: 1.12 + self.arg_dict[name] = typ 1.13 + for (name, typ) in keyspec: 1.14 self.key_ord.append(name) 1.15 - self.key_dict[name] = type 1.16 + self.key_dict[name] = typ 1.17 1.18 def get_args(self, d, xargs=None): 1.19 args = {} 1.20 @@ -56,12 +56,12 @@ class Args: 1.21 def split_args(self, d, args, keys): 1.22 for (k, v) in d.items(): 1.23 if k in self.arg_dict: 1.24 - type = self.arg_dict[k] 1.25 - val = self.coerce(type, v) 1.26 + typ = self.arg_dict[k] 1.27 + val = self.coerce(typ, v) 1.28 args[k] = val 1.29 elif k in self.key_dict: 1.30 - type = self.key_dict[k] 1.31 - val = self.coerce(type, v) 1.32 + typ = self.key_dict[k] 1.33 + val = self.coerce(typ, v) 1.34 keys[k] = val 1.35 else: 1.36 raise ArgError('Invalid parameter: %s' % k) 1.37 @@ -85,20 +85,20 @@ class Args: 1.38 d[k] = val 1.39 return self.get_args(d, xargs=xargs) 1.40 1.41 - def coerce(self, type, v): 1.42 + def coerce(self, typ, v): 1.43 try: 1.44 - if type == 'int': 1.45 + if typ == 'int': 1.46 val = int(v) 1.47 - elif type == 'long': 1.48 + elif typ == 'long': 1.49 val = long(v) 1.50 - elif type == 'str': 1.51 + elif typ == 'str': 1.52 val = str(v) 1.53 - elif type == 'sxpr': 1.54 + elif typ == 'sxpr': 1.55 val = self.sxpr(v) 1.56 - elif type == 'bool': 1.57 + elif typ == 'bool': 1.58 val = self.bool(v) 1.59 else: 1.60 - raise ArgError('invalid type:' + str(type)) 1.61 + raise ArgError('invalid type:' + str(typ)) 1.62 return val 1.63 except ArgError: 1.64 raise 1.65 @@ -142,7 +142,9 @@ class ArgFn(Args): 1.66 Used on the client. 1.67 """ 1.68 1.69 - def __init__(self, fn, paramspec, keyspec={}): 1.70 + def __init__(self, fn, paramspec, keyspec = None): 1.71 + if keyspec == None: 1.72 + keyspec = {} 1.73 Args.__init__(self, paramspec, keyspec) 1.74 self.fn = fn 1.75 1.76 @@ -154,7 +156,9 @@ class FormFn(Args): 1.77 Used in the HTTP server. 1.78 """ 1.79 1.80 - def __init__(self, fn, paramspec, keyspec={}): 1.81 + def __init__(self, fn, paramspec, keyspec = None): 1.82 + if keyspec == None: 1.83 + keyspec = {} 1.84 Args.__init__(self, paramspec, keyspec) 1.85 self.fn = fn 1.86
2.1 --- a/tools/python/xen/xend/EventServer.py Sun Sep 18 18:21:12 2005 +0100 2.2 +++ b/tools/python/xen/xend/EventServer.py Sun Sep 18 22:41:12 2005 +0100 2.3 @@ -145,7 +145,7 @@ class EventServer: 2.4 self.lock.release() 2.5 2.6 if async: 2.7 - scheduler.now(self.call_handlers, [event, val]) 2.8 + scheduler.now(self.call_handlers, event, val) 2.9 else: 2.10 self.call_handlers(event, val) 2.11
3.1 --- a/tools/python/xen/xend/Vifctl.py Sun Sep 18 18:21:12 2005 +0100 3.2 +++ b/tools/python/xen/xend/Vifctl.py Sun Sep 18 22:41:12 2005 +0100 3.3 @@ -13,13 +13,13 @@ 3.4 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 3.5 #============================================================================ 3.6 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com> 3.7 +# Copyright (C) 2005 XenSource Ltd 3.8 #============================================================================ 3.9 3.10 """Xend interface to networking control scripts. 3.11 """ 3.12 import os 3.13 import os.path 3.14 -import sys 3.15 import xen.util.process 3.16 3.17 from xen.xend import XendRoot 3.18 @@ -71,7 +71,7 @@ def set_vif_name(vif_old, vif_new): 3.19 vif = vif_old 3.20 return vif 3.21 3.22 -def vifctl(op, vif=None, script=None, domain=None, mac=None, bridge=None, ipaddr=[]): 3.23 +def vifctl(op, vif=None, script=None, domain=None, mac=None, bridge=None, ipaddr=None): 3.24 """Call a vif control script. 3.25 Xend calls this when bringing vifs up or down. 3.26
4.1 --- a/tools/python/xen/xend/scheduler.py Sun Sep 18 18:21:12 2005 +0100 4.2 +++ b/tools/python/xen/xend/scheduler.py Sun Sep 18 22:41:12 2005 +0100 4.3 @@ -13,11 +13,12 @@ 4.4 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 4.5 #============================================================================ 4.6 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com> 4.7 +# Copyright (C) 2005 XenSource Ltd 4.8 #============================================================================ 4.9 4.10 import threading 4.11 4.12 -def later(delay, fn, args=(), kwargs={}): 4.13 +def later(delay, fn, *args, **kwargs): 4.14 """Schedule a function to be called later. 4.15 4.16 @param delay: delay in seconds 4.17 @@ -29,7 +30,7 @@ def later(delay, fn, args=(), kwargs={}) 4.18 timer.start() 4.19 return timer 4.20 4.21 -def now(fn, args=(), kwargs={}): 4.22 +def now(fn, *args, **kwargs): 4.23 """Schedule a function to be called now. 4.24 4.25 @param fn: function
5.1 --- a/tools/python/xen/xend/xenstore/xswatch.py Sun Sep 18 18:21:12 2005 +0100 5.2 +++ b/tools/python/xen/xend/xenstore/xswatch.py Sun Sep 18 22:41:12 2005 +0100 5.3 @@ -1,4 +1,5 @@ 5.4 # Copyright (C) 2005 Christian Limpach <Christian.Limpach@cl.cam.ac.uk> 5.5 +# Copyright (C) 2005 XenSource Ltd 5.6 5.7 # This file is subject to the terms and conditions of the GNU General 5.8 # Public License. See the file "COPYING" in the main directory of 5.9 @@ -15,7 +16,7 @@ class xswatch: 5.10 xs = None 5.11 xslock = threading.Lock() 5.12 5.13 - def __init__(self, path, fn, args=(), kwargs={}): 5.14 + def __init__(self, path, fn, *args, **kwargs): 5.15 self.fn = fn 5.16 self.args = args 5.17 self.kwargs = kwargs 5.18 @@ -46,11 +47,11 @@ class xswatch: 5.19 cls.threadcond.release() 5.20 while True: 5.21 try: 5.22 - (ord, owr, oer) = select.select([ cls.xs ], [], []) 5.23 + (fd, _1, _2) = select.select([ cls.xs ], [], []) 5.24 cls.xslock.acquire() 5.25 # reconfirm ready to read with lock 5.26 - (ord, owr, oer) = select.select([ cls.xs ], [], [], 0.001) 5.27 - if not cls.xs in ord: 5.28 + (fd, _1, _2) = select.select([ cls.xs ], [], [], 0.001) 5.29 + if not cls.xs in fd: 5.30 cls.xslock.release() 5.31 continue 5.32 we = cls.xs.read_watch()