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>
This commit is contained in:
emellor@ewan committed 2005-09-18 22:41:12 +01:00
1 parent 9fa82ce91a
commit 2c3b4d51c5
5 files changed
+32 -26

No files matched your search

+21 -17
View File
@@ -32,12 +32,12 @@ class Args:
self.arg_dict = {}
self.key_ord = []
self.key_dict = {}
for (name, type) in paramspec:
for (name, typ) in paramspec:
self.arg_ord.append(name)
self.arg_dict[name] = type
for (name, type) in keyspec:
self.arg_dict[name] = typ
for (name, typ) in keyspec:
self.key_ord.append(name)
self.key_dict[name] = type
self.key_dict[name] = typ
def get_args(self, d, xargs=None):
args = {}
@@ -56,12 +56,12 @@ class Args:
def split_args(self, d, args, keys):
for (k, v) in d.items():
if k in self.arg_dict:
type = self.arg_dict[k]
val = self.coerce(type, v)
typ = self.arg_dict[k]
val = self.coerce(typ, v)
args[k] = val
elif k in self.key_dict:
type = self.key_dict[k]
val = self.coerce(type, v)
typ = self.key_dict[k]
val = self.coerce(typ, v)
keys[k] = val
else:
raise ArgError('Invalid parameter: %s' % k)
@@ -85,20 +85,20 @@ class Args:
d[k] = val
return self.get_args(d, xargs=xargs)
def coerce(self, type, v):
def coerce(self, typ, v):
try:
if type == 'int':
if typ == 'int':
val = int(v)
elif type == 'long':
elif typ == 'long':
val = long(v)
elif type == 'str':
elif typ == 'str':
val = str(v)
elif type == 'sxpr':
elif typ == 'sxpr':
val = self.sxpr(v)
elif type == 'bool':
elif typ == 'bool':
val = self.bool(v)
else:
raise ArgError('invalid type:' + str(type))
raise ArgError('invalid type:' + str(typ))
return val
except ArgError:
raise
@@ -142,7 +142,9 @@ class ArgFn(Args):
Used on the client.
"""
def __init__(self, fn, paramspec, keyspec={}):
def __init__(self, fn, paramspec, keyspec = None):
if keyspec == None:
keyspec = {}
Args.__init__(self, paramspec, keyspec)
self.fn = fn
@@ -154,7 +156,9 @@ class FormFn(Args):
Used in the HTTP server.
"""
def __init__(self, fn, paramspec, keyspec={}):
def __init__(self, fn, paramspec, keyspec = None):
if keyspec == None:
keyspec = {}
Args.__init__(self, paramspec, keyspec)
self.fn = fn
+1 -1
View File
@@ -145,7 +145,7 @@ class EventServer:
self.lock.release()
if async:
scheduler.now(self.call_handlers, [event, val])
scheduler.now(self.call_handlers, event, val)
else:
self.call_handlers(event, val)
+2 -2
View File
@@ -13,13 +13,13 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
# Copyright (C) 2005 XenSource Ltd
#============================================================================
"""Xend interface to networking control scripts.
"""
import os
import os.path
import sys
import xen.util.process
from xen.xend import XendRoot
@@ -71,7 +71,7 @@ def set_vif_name(vif_old, vif_new):
vif = vif_old
return vif
def vifctl(op, vif=None, script=None, domain=None, mac=None, bridge=None, ipaddr=[]):
def vifctl(op, vif=None, script=None, domain=None, mac=None, bridge=None, ipaddr=None):
"""Call a vif control script.
Xend calls this when bringing vifs up or down.
+3 -2
View File
@@ -13,11 +13,12 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
# Copyright (C) 2005 XenSource Ltd
#============================================================================
import threading
def later(delay, fn, args=(), kwargs={}):
def later(delay, fn, *args, **kwargs):
"""Schedule a function to be called later.
@param delay: delay in seconds
@@ -29,7 +30,7 @@ def later(delay, fn, args=(), kwargs={}):
timer.start()
return timer
def now(fn, args=(), kwargs={}):
def now(fn, *args, **kwargs):
"""Schedule a function to be called now.
@param fn: function
+5 -4
View File
@@ -1,4 +1,5 @@
# Copyright (C) 2005 Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
# Copyright (C) 2005 XenSource Ltd
# This file is subject to the terms and conditions of the GNU General
# Public License. See the file "COPYING" in the main directory of
@@ -15,7 +16,7 @@ class xswatch:
xs = None
xslock = threading.Lock()
def __init__(self, path, fn, args=(), kwargs={}):
def __init__(self, path, fn, *args, **kwargs):
self.fn = fn
self.args = args
self.kwargs = kwargs
@@ -46,11 +47,11 @@ class xswatch:
cls.threadcond.release()
while True:
try:
(ord, owr, oer) = select.select([ cls.xs ], [], [])
(fd, _1, _2) = select.select([ cls.xs ], [], [])
cls.xslock.acquire()
# reconfirm ready to read with lock
(ord, owr, oer) = select.select([ cls.xs ], [], [], 0.001)
if not cls.xs in ord:
(fd, _1, _2) = select.select([ cls.xs ], [], [], 0.001)
if not cls.xs in fd:
cls.xslock.release()
continue
we = cls.xs.read_watch()
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.