From 8850da99188621be969dac447b29bd9b19d6c646 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Fri, 5 Nov 2010 17:59:14 -0400 Subject: [PATCH] Don't specify {} as the default argument to any method. This is dangerous because it ends up being a class variable so later callers may not get the default empty dict they were expecting. --- pykickstart/base.py | 20 ++++++++++++-------- pykickstart/options.py | 7 +++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pykickstart/base.py b/pykickstart/base.py index ee38cba..57e0c44 100644 --- a/pykickstart/base.py +++ b/pykickstart/base.py @@ -42,6 +42,7 @@ import gettext gettext.textdomain("pykickstart") _ = lambda x: gettext.ldgettext("pykickstart", x) +import types import warnings from pykickstart.errors import * from pykickstart.ko import * @@ -200,8 +201,8 @@ class BaseHandler(KickstartObject): """ version = None - def __init__(self, mapping={}, dataMapping={}, commandUpdates={}, - dataUpdates={}, *args, **kwargs): + def __init__(self, mapping=None, dataMapping=None, commandUpdates=None, + dataUpdates=None, *args, **kwargs): """Create a new BaseHandler instance. This method must be provided by all subclasses, but subclasses must call BaseHandler.__init__ first. @@ -328,22 +329,25 @@ class BaseHandler(KickstartObject): else: self._writeOrder[cmdObj.writePriority] = [cmdObj] - def _registerCommands(self, mapping={}, dataMapping={}, commandUpdates={}, - dataUpdates={}): - if mapping == {}: + def _registerCommands(self, mapping=None, dataMapping=None, commandUpdates=None, + dataUpdates=None): + if mapping == {} or mapping == None: from pykickstart.handlers.control import commandMap cMap = commandMap[self.version] else: cMap = mapping - if dataMapping == {}: + if dataMapping == {} or dataMapping == None: from pykickstart.handlers.control import dataMap dMap = dataMap[self.version] else: dMap = dataMapping - cMap.update(commandUpdates) - dMap.update(dataUpdates) + if type(commandUpdates) == types.DictType: + cMap.update(commandUpdates) + + if type(dataUpdates) == types.DictType: + dMap.update(dataUpdates) for (cmdName, cmdClass) in cMap.iteritems(): # First make sure we haven't instantiated this command handler diff --git a/pykickstart/options.py b/pykickstart/options.py index f747861..2b24fef 100644 --- a/pykickstart/options.py +++ b/pykickstart/options.py @@ -105,7 +105,7 @@ class KSOptionParser(OptionParser): return OptionParser.parse_args(self, **kwargs) - def __init__(self, mapping={}, version=None): + def __init__(self, mapping=None, version=None): """Create a new KSOptionParser instance. Each KickstartCommand subclass should create one instance of KSOptionParser, providing at least the lineno attribute. mapping and version are not required. @@ -118,7 +118,10 @@ class KSOptionParser(OptionParser): OptionParser.__init__(self, option_class=KSOption, add_help_option=False, conflict_handler="resolve") - self.map = mapping + if mapping is None: + self.map = {} + else: + self.map = mapping self.version = version def _check_ksboolean(option, opt, value): -- 2.11.4.GIT