fixes for mutable default arguments

modify the default argument from list to None,
because default value {}/[] as argument is dangerous.

Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Minoru TAKAHASHI 2016-01-06 17:35:16 +09:00 committed by FUJITA Tomonori
parent 7826290ba6
commit ecfd21e5f9
11 changed files with 124 additions and 61 deletions

View File

@ -78,7 +78,7 @@ class BFDSession(object):
detect_mult=3,
desired_min_tx_interval=1000000,
required_min_rx_interval=1000000,
auth_type=0, auth_keys={}):
auth_type=0, auth_keys=None):
"""
Initialize a BFD session.
@ -128,6 +128,7 @@ class BFDSession(object):
auth_keys={1: "secret key 1",
2: "secret key 2"})
"""
auth_keys = auth_keys if auth_keys else {}
assert not (auth_type and len(auth_keys) == 0)
# RyuApp reference to BFDLib
@ -787,7 +788,7 @@ class BFDLib(app_manager.RyuApp):
def add_bfd_session(self, dpid, ofport, src_mac, src_ip,
dst_mac="FF:FF:FF:FF:FF:FF", dst_ip="255.255.255.255",
auth_type=0, auth_keys={}):
auth_type=0, auth_keys=None):
"""
Establish a new BFD session and return My Discriminator of new session.
@ -822,6 +823,7 @@ class BFDLib(app_manager.RyuApp):
auth_keys={1: "secret key 1",
2: "secret key 2"})
"""
auth_keys = auth_keys if auth_keys else {}
# Generate a unique discriminator
while True:
# Generate My Discriminator

View File

@ -261,7 +261,8 @@ class OVSBridge(object):
return command.result[0]
return None
def set_qos(self, port_name, type='linux-htb', max_rate=None, queues=[]):
def set_qos(self, port_name, type='linux-htb', max_rate=None, queues=None):
queues = queues if queues else []
command_qos = ovs_vsctl.VSCtlCommand(
'set-qos',
[port_name, type, max_rate])

View File

@ -417,7 +417,7 @@ class SimplePassword(BFDAuth):
return self.serialize_hdr() + \
struct.pack(self._PACK_STR, self.auth_key_id) + self.password
def authenticate(self, prev=None, auth_keys={}):
def authenticate(self, prev=None, auth_keys=None):
"""Authenticate the password for this packet.
This method can be invoked only when ``self.password`` is defined.
@ -431,6 +431,7 @@ class SimplePassword(BFDAuth):
``auth_keys`` is a dictionary of authentication key chain which
key is an integer of *Auth Key ID* and value is a string of *Password*.
"""
auth_keys = auth_keys if auth_keys else {}
assert isinstance(prev, bfd)
if self.auth_key_id in auth_keys and \
self.password == auth_keys[self.auth_key_id]:
@ -520,7 +521,7 @@ class KeyedMD5(BFDAuth):
return auth_hdr_bin + struct.pack(self._PACK_STR, self.auth_key_id, 0,
self.seq, self.digest)
def authenticate(self, prev, auth_keys={}):
def authenticate(self, prev, auth_keys=None):
"""Authenticate the MD5 digest for this packet.
This method can be invoked only when ``self.digest`` is defined.
@ -536,6 +537,7 @@ class KeyedMD5(BFDAuth):
``auth_keys`` is a dictionary of authentication key chain which
key is an integer of *Auth Key ID* and value is a string of *Auth Key*.
"""
auth_keys = auth_keys if auth_keys else {}
assert isinstance(prev, bfd)
if self.digest is None:
@ -670,7 +672,7 @@ class KeyedSHA1(BFDAuth):
return auth_hdr_bin + struct.pack(self._PACK_STR, self.auth_key_id, 0,
self.seq, self.auth_hash)
def authenticate(self, prev, auth_keys={}):
def authenticate(self, prev, auth_keys=None):
"""Authenticate the SHA1 hash for this packet.
This method can be invoked only when ``self.auth_hash`` is defined.
@ -686,6 +688,7 @@ class KeyedSHA1(BFDAuth):
``auth_keys`` is a dictionary of authentication key chain which
key is an integer of *Auth Key ID* and value is a string of *Auth Key*.
"""
auth_keys = auth_keys if auth_keys else {}
assert isinstance(prev, bfd)
if self.auth_hash is None:

View File

@ -780,7 +780,8 @@ class _LabelledAddrPrefix(_AddrPrefix):
#
_WITHDRAW_LABEL = 0x800000
def __init__(self, length, addr, labels=[], **kwargs):
def __init__(self, length, addr, labels=None, **kwargs):
labels = labels if labels else []
assert isinstance(labels, list)
is_tuple = isinstance(addr, tuple)
if is_tuple:
@ -2246,8 +2247,9 @@ class BGPOpen(BGPMessage):
}
def __init__(self, my_as, bgp_identifier, type_=BGP_MSG_OPEN,
opt_param_len=0, opt_param=[],
opt_param_len=0, opt_param=None,
version=_VERSION, hold_time=0, len_=None, marker=None):
opt_param = opt_param if opt_param else []
super(BGPOpen, self).__init__(marker=marker, len_=len_, type_=type_)
self.version = version
self.my_as = my_as
@ -2332,11 +2334,14 @@ class BGPUpdate(BGPMessage):
def __init__(self, type_=BGP_MSG_UPDATE,
withdrawn_routes_len=None,
withdrawn_routes=[],
withdrawn_routes=None,
total_path_attribute_len=None,
path_attributes=[],
nlri=[],
path_attributes=None,
nlri=None,
len_=None, marker=None):
withdrawn_routes = withdrawn_routes if withdrawn_routes else []
path_attributes = path_attributes if path_attributes else []
nlri = nlri if nlri else []
super(BGPUpdate, self).__init__(marker=marker, len_=len_, type_=type_)
self.withdrawn_routes_len = withdrawn_routes_len
self.withdrawn_routes = withdrawn_routes

View File

@ -280,7 +280,8 @@ class RouterLSA(LSA):
def __init__(self, ls_age=0, options=0, type_=OSPF_ROUTER_LSA,
id_='0.0.0.0', adv_router='0.0.0.0', ls_seqnum=0,
checksum=None, length=None, flags=0, links=[]):
checksum=None, length=None, flags=0, links=None):
links = links if links else []
self.flags = flags
self.links = links
super(RouterLSA, self).__init__(ls_age, options, type_, id_,
@ -320,7 +321,8 @@ class NetworkLSA(LSA):
def __init__(self, ls_age=0, options=0, type_=OSPF_NETWORK_LSA,
id_='0.0.0.0', adv_router='0.0.0.0', ls_seqnum=0,
checksum=None, length=None, mask='0.0.0.0', routers=[]):
checksum=None, length=None, mask='0.0.0.0', routers=None):
routers = routers if routers else []
self.mask = mask
self.routers = routers
super(NetworkLSA, self).__init__(ls_age, options, type_, id_,
@ -439,7 +441,8 @@ class ASExternalLSA(LSA):
def __init__(self, ls_age=0, options=0, type_=OSPF_AS_EXTERNAL_LSA,
id_='0.0.0.0', adv_router='0.0.0.0', ls_seqnum=0,
checksum=None, length=None, extnws=[]):
checksum=None, length=None, extnws=None):
extnws = extnws if extnws else []
self.extnws = extnws
super(ASExternalLSA, self).__init__(ls_age, options, type_, id_,
adv_router, ls_seqnum, checksum,
@ -539,7 +542,8 @@ class PrefixSIDSubTLV(ExtendedPrefixTLV):
class OpaqueBody(StringifyMixin, _TypeDisp):
def __init__(self, tlvs=[]):
def __init__(self, tlvs=None):
tlvs = tlvs if tlvs else []
self.tlvs = tlvs
def serialize(self):
@ -718,7 +722,8 @@ class OSPFHello(OSPFMessage):
au_type=1, authentication=0, checksum=None, version=_VERSION,
mask='0.0.0.0', hello_interval=10, options=0, priority=1,
dead_interval=40, designated_router='0.0.0.0',
backup_router='0.0.0.0', neighbors=[]):
backup_router='0.0.0.0', neighbors=None):
neighbors = neighbors if neighbors else []
super(OSPFHello, self).__init__(OSPF_MSG_HELLO, length, router_id,
area_id, au_type, authentication,
checksum, version)
@ -782,7 +787,8 @@ class OSPFDBDesc(OSPFMessage):
def __init__(self, length=None, router_id='0.0.0.0', area_id='0.0.0.0',
au_type=1, authentication=0, checksum=None, version=_VERSION,
mtu=1500, options=0, i_flag=0, m_flag=0, ms_flag=0,
sequence_number=0, lsa_headers=[]):
sequence_number=0, lsa_headers=None):
lsa_headers = lsa_headers if lsa_headers else []
super(OSPFDBDesc, self).__init__(OSPF_MSG_DB_DESC, length, router_id,
area_id, au_type, authentication,
checksum, version)
@ -865,7 +871,8 @@ class OSPFLSReq(OSPFMessage):
def __init__(self, length=None, router_id='0.0.0.0', area_id='0.0.0.0',
au_type=1, authentication=0, checksum=None, version=_VERSION,
lsa_requests=[]):
lsa_requests=None):
lsa_requests = lsa_requests if lsa_requests else []
super(OSPFLSReq, self).__init__(OSPF_MSG_LS_REQ, length, router_id,
area_id, au_type, authentication,
checksum, version)
@ -894,7 +901,8 @@ class OSPFLSUpd(OSPFMessage):
def __init__(self, length=None, router_id='0.0.0.0', area_id='0.0.0.0',
au_type=1, authentication=0, checksum=None, version=_VERSION,
lsas=[]):
lsas=None):
lsas = lsas if lsas else []
super(OSPFLSUpd, self).__init__(OSPF_MSG_LS_UPD, length, router_id,
area_id, au_type, authentication,
checksum, version)
@ -930,7 +938,8 @@ class OSPFLSAck(OSPFMessage):
def __init__(self, length=None, router_id='0.0.0.0', area_id='0.0.0.0',
au_type=1, authentication=0, checksum=None, version=_VERSION,
lsa_headers=[]):
lsa_headers=None):
lsa_headers = lsa_headers if lsa_headers else []
super(OSPFLSAck, self).__init__(OSPF_MSG_LS_ACK, length, router_id,
area_id, au_type, authentication,
checksum, version)

View File

@ -931,7 +931,8 @@ class OFPFlowMod(MsgBase):
buffer_id=ofproto.OFP_NO_BUFFER,
out_port=0, out_group=0, flags=0,
match=None,
instructions=[]):
instructions=None):
instructions = instructions if instructions else []
super(OFPFlowMod, self).__init__(datapath)
self.cookie = cookie
self.cookie_mask = cookie_mask
@ -1725,7 +1726,8 @@ class OFPGroupMod(MsgBase):
datapath.send_msg(req)
"""
def __init__(self, datapath, command=ofproto.OFPGC_ADD,
type_=ofproto.OFPGT_ALL, group_id=0, buckets=[]):
type_=ofproto.OFPGT_ALL, group_id=0, buckets=None):
buckets = buckets if buckets else []
super(OFPGroupMod, self).__init__(datapath)
self.command = command
self.type = type_

View File

@ -99,7 +99,8 @@ class OFPHello(MsgBase):
elements list of ``OFPHelloElemVersionBitmap`` instance
========== =========================================================
"""
def __init__(self, datapath, elements=[]):
def __init__(self, datapath, elements=None):
elements = elements if elements else []
super(OFPHello, self).__init__(datapath)
self.elements = elements
@ -2607,7 +2608,8 @@ class OFPFlowMod(MsgBase):
buffer_id=ofproto.OFP_NO_BUFFER,
out_port=0, out_group=0, flags=0,
match=None,
instructions=[]):
instructions=None):
instructions = instructions if instructions else []
super(OFPFlowMod, self).__init__(datapath)
self.cookie = cookie
self.cookie_mask = cookie_mask
@ -3504,7 +3506,8 @@ class OFPGroupMod(MsgBase):
datapath.send_msg(req)
"""
def __init__(self, datapath, command=ofproto.OFPGC_ADD,
type_=ofproto.OFPGT_ALL, group_id=0, buckets=[]):
type_=ofproto.OFPGT_ALL, group_id=0, buckets=None):
buckets = buckets if buckets else []
super(OFPGroupMod, self).__init__(datapath)
self.command = command
self.type = type_
@ -3635,7 +3638,8 @@ class OFPMeterMod(MsgBase):
================ ======================================================
"""
def __init__(self, datapath, command=ofproto.OFPMC_ADD,
flags=ofproto.OFPMF_KBPS, meter_id=1, bands=[]):
flags=ofproto.OFPMF_KBPS, meter_id=1, bands=None):
bands = bands if bands else []
super(OFPMeterMod, self).__init__(datapath)
self.command = command
self.flags = flags
@ -5133,7 +5137,8 @@ class OFPInstructionId(StringifyMixin):
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_INSTRUCTIONS)
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_INSTRUCTIONS_MISS)
class OFPTableFeaturePropInstructions(OFPTableFeatureProp):
def __init__(self, type_=None, length=None, instruction_ids=[]):
def __init__(self, type_=None, length=None, instruction_ids=None):
instruction_ids = instruction_ids if instruction_ids else []
super(OFPTableFeaturePropInstructions, self).__init__(type_, length)
self.instruction_ids = instruction_ids
@ -5159,7 +5164,8 @@ class OFPTableFeaturePropInstructions(OFPTableFeatureProp):
class OFPTableFeaturePropNextTables(OFPTableFeatureProp):
_TABLE_ID_PACK_STR = '!B'
def __init__(self, type_=None, length=None, table_ids=[]):
def __init__(self, type_=None, length=None, table_ids=None):
table_ids = table_ids if table_ids else []
super(OFPTableFeaturePropNextTables, self).__init__(type_, length)
self.table_ids = table_ids
@ -5219,7 +5225,8 @@ class OFPActionId(StringifyMixin):
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_APPLY_ACTIONS)
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_APPLY_ACTIONS_MISS)
class OFPTableFeaturePropActions(OFPTableFeatureProp):
def __init__(self, type_=None, length=None, action_ids=[]):
def __init__(self, type_=None, length=None, action_ids=None):
action_ids = action_ids if action_ids else []
super(OFPTableFeaturePropActions, self).__init__(type_, length)
self.action_ids = action_ids
@ -5327,7 +5334,8 @@ class OFPExperimenterOxmId(OFPOxmId):
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_APPLY_SETFIELD)
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_APPLY_SETFIELD_MISS)
class OFPTableFeaturePropOxm(OFPTableFeatureProp):
def __init__(self, type_=None, length=None, oxm_ids=[]):
def __init__(self, type_=None, length=None, oxm_ids=None):
oxm_ids = oxm_ids if oxm_ids else []
super(OFPTableFeaturePropOxm, self).__init__(type_, length)
self.oxm_ids = oxm_ids
@ -5369,8 +5377,9 @@ class OFPTableFeaturesStatsRequest(OFPMultipartRequest):
================ ======================================================
"""
def __init__(self, datapath, flags=0,
body=[],
body=None,
type_=None):
body = body if body else []
super(OFPTableFeaturesStatsRequest, self).__init__(datapath, flags)
self.body = body
@ -5586,8 +5595,9 @@ class ONFFlowMonitorStatsRequest(OFPExperimenterStatsRequestBase):
body List of ONFFlowMonitorRequest instances
================ ======================================================
"""
def __init__(self, datapath, flags, body=[],
def __init__(self, datapath, flags, body=None,
type_=None, experimenter=None, exp_type=None):
body = body if body else []
super(ONFFlowMonitorStatsRequest,
self).__init__(datapath, flags,
experimenter=ofproto_common.ONF_EXPERIMENTER_ID,

View File

@ -71,7 +71,8 @@ class OFPHello(MsgBase):
elements list of ``OFPHelloElemVersionBitmap`` instance
========== =========================================================
"""
def __init__(self, datapath, elements=[]):
def __init__(self, datapath, elements=None):
elements = elements if elements else []
super(OFPHello, self).__init__(datapath)
self.elements = elements
@ -1466,7 +1467,8 @@ class OFPMeterMod(MsgBase):
================ ======================================================
"""
def __init__(self, datapath, command=ofproto.OFPMC_ADD,
flags=ofproto.OFPMF_KBPS, meter_id=1, bands=[]):
flags=ofproto.OFPMF_KBPS, meter_id=1, bands=None):
bands = bands if bands else []
super(OFPMeterMod, self).__init__(datapath)
self.command = command
self.flags = flags
@ -1786,7 +1788,8 @@ class OFPInstructionId(StringifyMixin):
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_INSTRUCTIONS)
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_INSTRUCTIONS_MISS)
class OFPTableFeaturePropInstructions(OFPTableFeatureProp):
def __init__(self, type_=None, length=None, instruction_ids=[]):
def __init__(self, type_=None, length=None, instruction_ids=None):
instruction_ids = instruction_ids if instruction_ids else []
super(OFPTableFeaturePropInstructions, self).__init__(type_, length)
self.instruction_ids = instruction_ids
@ -1838,7 +1841,8 @@ class OFPActionId(StringifyMixin):
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_APPLY_ACTIONS)
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_APPLY_ACTIONS_MISS)
class OFPTableFeaturePropActions(OFPTableFeatureProp):
def __init__(self, type_=None, length=None, action_ids=[]):
def __init__(self, type_=None, length=None, action_ids=None):
action_ids = action_ids if action_ids else []
super(OFPTableFeaturePropActions, self).__init__(type_, length)
self.action_ids = action_ids
@ -1864,7 +1868,8 @@ class OFPTableFeaturePropActions(OFPTableFeatureProp):
class OFPTableFeaturePropNextTables(OFPTableFeatureProp):
_TABLE_ID_PACK_STR = '!B'
def __init__(self, type_=None, length=None, table_ids=[]):
def __init__(self, type_=None, length=None, table_ids=None):
table_ids = table_ids if table_ids else []
super(OFPTableFeaturePropNextTables, self).__init__(type_, length)
self.table_ids = table_ids
@ -1975,7 +1980,8 @@ class OFPExperimenterOxmId(OFPOxmId):
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_APPLY_SETFIELD)
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_APPLY_SETFIELD_MISS)
class OFPTableFeaturePropOxm(OFPTableFeatureProp):
def __init__(self, type_=None, length=None, oxm_ids=[]):
def __init__(self, type_=None, length=None, oxm_ids=None):
oxm_ids = oxm_ids if oxm_ids else []
super(OFPTableFeaturePropOxm, self).__init__(type_, length)
self.oxm_ids = oxm_ids
@ -2016,7 +2022,8 @@ class OFPTableFeaturesStatsRequest(OFPMultipartRequest):
The default is [].
================ ======================================================
"""
def __init__(self, datapath, flags=0, body=[], type_=None):
def __init__(self, datapath, flags=0, body=None, type_=None):
body = body if body else []
super(OFPTableFeaturesStatsRequest, self).__init__(datapath, flags)
self.body = body
@ -3055,7 +3062,8 @@ class OFPFlowUpdateHeader(OFPFlowUpdate):
class OFPFlowUpdateFull(OFPFlowUpdateHeader):
def __init__(self, length=None, event=None, table_id=None, reason=None,
idle_timeout=None, hard_timeout=None, priority=None,
cookie=None, match=None, instructions=[]):
cookie=None, match=None, instructions=None):
instructions = instructions if instructions else []
super(OFPFlowUpdateFull, self).__init__(length, event)
self.table_id = table_id
self.reason = reason
@ -4266,7 +4274,8 @@ class OFPFlowMod(MsgBase):
buffer_id=ofproto.OFP_NO_BUFFER,
out_port=0, out_group=0, flags=0, importance=0,
match=None,
instructions=[]):
instructions=None):
instructions = instructions if instructions else []
super(OFPFlowMod, self).__init__(datapath)
self.cookie = cookie
self.cookie_mask = cookie_mask
@ -5036,7 +5045,8 @@ class OFPGroupMod(MsgBase):
datapath.send_msg(req)
"""
def __init__(self, datapath, command=ofproto.OFPGC_ADD,
type_=ofproto.OFPGT_ALL, group_id=0, buckets=[]):
type_=ofproto.OFPGT_ALL, group_id=0, buckets=None):
buckets = buckets if buckets else []
super(OFPGroupMod, self).__init__(datapath)
self.command = command
self.type = type_

View File

@ -73,7 +73,8 @@ class OFPHello(MsgBase):
elements list of ``OFPHelloElemVersionBitmap`` instance
========== =========================================================
"""
def __init__(self, datapath, elements=[]):
def __init__(self, datapath, elements=None):
elements = elements if elements else []
super(OFPHello, self).__init__(datapath)
self.elements = elements
@ -1135,7 +1136,8 @@ class OFPPortDescPropOptical(OFPPortDescProp):
@OFPPortDescProp.register_type(ofproto.OFPPDPT_PIPELINE_INPUT)
@OFPPortDescProp.register_type(ofproto.OFPPDPT_PIPELINE_OUTPUT)
class OFPPortDescPropOxm(OFPPortDescProp):
def __init__(self, type_=None, length=None, oxm_ids=[]):
def __init__(self, type_=None, length=None, oxm_ids=None):
oxm_ids = oxm_ids if oxm_ids else []
super(OFPPortDescPropOxm, self).__init__(type_, length)
self.oxm_ids = oxm_ids
@ -1159,7 +1161,8 @@ class OFPPortDescPropOxm(OFPPortDescProp):
class OFPPortDescPropRecirculate(OFPPortDescProp):
_PORT_NO_PACK_STR = '!I'
def __init__(self, type_=None, length=None, port_nos=[]):
def __init__(self, type_=None, length=None, port_nos=None):
port_nos = port_nos if port_nos else []
super(OFPPortDescPropRecirculate, self).__init__(type_, length)
self.port_nos = port_nos
@ -1702,7 +1705,8 @@ class OFPMeterMod(MsgBase):
================ ======================================================
"""
def __init__(self, datapath, command=ofproto.OFPMC_ADD,
flags=ofproto.OFPMF_KBPS, meter_id=1, bands=[]):
flags=ofproto.OFPMF_KBPS, meter_id=1, bands=None):
bands = bands if bands else []
super(OFPMeterMod, self).__init__(datapath)
self.command = command
self.flags = flags
@ -2023,7 +2027,8 @@ class OFPInstructionId(StringifyMixin):
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_INSTRUCTIONS)
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_INSTRUCTIONS_MISS)
class OFPTableFeaturePropInstructions(OFPTableFeatureProp):
def __init__(self, type_=None, length=None, instruction_ids=[]):
def __init__(self, type_=None, length=None, instruction_ids=None):
instruction_ids = instruction_ids if instruction_ids else []
super(OFPTableFeaturePropInstructions, self).__init__(type_, length)
self.instruction_ids = instruction_ids
@ -2075,7 +2080,8 @@ class OFPActionId(StringifyMixin):
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_APPLY_ACTIONS)
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_APPLY_ACTIONS_MISS)
class OFPTableFeaturePropActions(OFPTableFeatureProp):
def __init__(self, type_=None, length=None, action_ids=[]):
def __init__(self, type_=None, length=None, action_ids=None):
action_ids = action_ids if action_ids else []
super(OFPTableFeaturePropActions, self).__init__(type_, length)
self.action_ids = action_ids
@ -2101,7 +2107,8 @@ class OFPTableFeaturePropActions(OFPTableFeatureProp):
class OFPTableFeaturePropNextTables(OFPTableFeatureProp):
_TABLE_ID_PACK_STR = '!B'
def __init__(self, type_=None, length=None, table_ids=[]):
def __init__(self, type_=None, length=None, table_ids=None):
table_ids = table_ids if table_ids else []
super(OFPTableFeaturePropNextTables, self).__init__(type_, length)
self.table_ids = table_ids
@ -2216,7 +2223,8 @@ class OFPExperimenterOxmId(OFPOxmId):
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_APPLY_COPYFIELD)
@OFPTableFeatureProp.register_type(ofproto.OFPTFPT_APPLY_COPYFIELD_MISS)
class OFPTableFeaturePropOxm(OFPTableFeatureProp):
def __init__(self, type_=None, length=None, oxm_ids=[]):
def __init__(self, type_=None, length=None, oxm_ids=None):
oxm_ids = oxm_ids if oxm_ids else []
super(OFPTableFeaturePropOxm, self).__init__(type_, length)
self.oxm_ids = oxm_ids
@ -2338,7 +2346,8 @@ class OFPTableFeaturesStatsRequest(OFPMultipartRequest):
The default is [].
================ ======================================================
"""
def __init__(self, datapath, flags=0, body=[], type_=None):
def __init__(self, datapath, flags=0, body=None, type_=None):
body = body if body else []
super(OFPTableFeaturesStatsRequest, self).__init__(datapath, flags)
self.body = body
@ -2789,8 +2798,10 @@ class OFPGroupStatsReply(OFPMultipartReply):
class OFPGroupDescStats(StringifyMixin):
def __init__(self, type_=None, group_id=None, buckets=[], properties=[],
def __init__(self, type_=None, group_id=None, buckets=None, properties=None,
length=None, bucket_array_len=None):
buckets = buckets if buckets else []
properties = properties if properties else []
super(OFPGroupDescStats, self).__init__()
self.length = length
self.type = type_
@ -3405,7 +3416,8 @@ class OFPFlowUpdateHeader(OFPFlowUpdate):
class OFPFlowUpdateFull(OFPFlowUpdateHeader):
def __init__(self, length=None, event=None, table_id=None, reason=None,
idle_timeout=None, hard_timeout=None, priority=None,
cookie=None, match=None, instructions=[]):
cookie=None, match=None, instructions=None):
instructions = instructions if instructions else []
super(OFPFlowUpdateFull, self).__init__(length, event)
self.table_id = table_id
self.reason = reason
@ -3716,7 +3728,8 @@ class OFPBundleFeaturesStatsRequest(OFPMultipartRequest):
datapath.send_msg(req)
"""
def __init__(self, datapath, flags=0, feature_request_flags=0,
properties=[], type_=None):
properties=None, type_=None):
properties = properties if properties else []
super(OFPBundleFeaturesStatsRequest, self).__init__(datapath, flags)
self.feature_request_flags = feature_request_flags
self.properties = properties
@ -5121,7 +5134,8 @@ class OFPFlowMod(MsgBase):
buffer_id=ofproto.OFP_NO_BUFFER,
out_port=0, out_group=0, flags=0, importance=0,
match=None,
instructions=[]):
instructions=None):
instructions = instructions if instructions else []
super(OFPFlowMod, self).__init__(datapath)
self.cookie = cookie
self.cookie_mask = cookie_mask
@ -5842,8 +5856,9 @@ class OFPActionCopyField(OFPAction):
The default is [].
================ ======================================================
"""
def __init__(self, n_bits=0, src_offset=0, dst_offset=0, oxm_ids=[],
def __init__(self, n_bits=0, src_offset=0, dst_offset=0, oxm_ids=None,
type_=None, len_=None):
oxm_ids = oxm_ids if oxm_ids else []
super(OFPActionCopyField, self).__init__()
self.n_bits = n_bits
self.src_offset = src_offset
@ -6029,7 +6044,9 @@ class OFPGroupMod(MsgBase):
"""
def __init__(self, datapath, command=ofproto.OFPGC_ADD,
type_=ofproto.OFPGT_ALL, group_id=0, command_bucket_id=0,
buckets=[], properties=[], bucket_array_len=None):
buckets=None, properties=None, bucket_array_len=None):
buckets = buckets if buckets else []
properties = properties if properties else []
super(OFPGroupMod, self).__init__(datapath)
self.command = command
self.type = type_
@ -6258,8 +6275,10 @@ class OFPGroupBucketPropExperimenter(OFPPropCommonExperimenter4ByteData):
class OFPBucket(StringifyMixin):
def __init__(self, bucket_id=0, actions=[], properties=[],
def __init__(self, bucket_id=0, actions=None, properties=None,
len_=None, action_array_len=None):
actions = actions if actions else []
properties = properties if properties else []
super(OFPBucket, self).__init__()
self.bucket_id = bucket_id
self.actions = actions

View File

@ -65,7 +65,8 @@ class OperatorApi(object):
def clear(self, **kwargs):
return self._run('clear', kw=kwargs)
def _run(self, cmd, kw={}):
def _run(self, cmd, kw=None):
kw = kw if kw else {}
params = kw.get('params', [])
fmt = kw.get('format', 'json')
root = RootCmd(api=self.internal_api, resp_formatter_name=fmt)

View File

@ -125,8 +125,9 @@ def get_reqs_from_files(requirements_files):
return []
def parse_requirements(requirements_files=['requirements.txt',
'tools/pip-requires']):
def parse_requirements(requirements_files=None):
requirements_files = requirements_files if requirements_files else [
'requirements.txt', 'tools/pip-requires']
requirements = []
for line in get_reqs_from_files(requirements_files):
# For the requirements list, we need to inject only the portion