python: fix mutable default arguments
authorRob van der Linde <rob@catalyst.net.nz>
Thu, 23 Feb 2023 02:54:37 +0000 (15:54 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 23 Feb 2023 23:33:46 +0000 (23:33 +0000)
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Thu Feb 23 23:33:46 UTC 2023 on atb-devel-224

26 files changed:
python/samba/descriptor.py
python/samba/emulate/traffic.py
python/samba/gp/gp_cert_auto_enroll_ext.py
python/samba/gp/gpclass.py
python/samba/gp/util/logging.py
python/samba/graph.py
python/samba/netcmd/dbcheck.py
python/samba/netcmd/dns.py
python/samba/netcmd/domain.py
python/samba/netcmd/gpo.py
python/samba/provision/common.py
python/samba/samdb.py
python/samba/schema.py
python/samba/sd_utils.py
python/samba/tests/__init__.py
python/samba/tests/dcerpc/raw_testcase.py
python/samba/tests/dns.py
python/samba/tests/domain_backup_offline.py
python/samba/tests/kcc/kcc_utils.py
python/samba/tests/samba_tool/computer.py
python/samba/tests/samba_tool/contact.py
python/samba/tests/samba_tool/group.py
python/samba/tests/samba_tool/ou.py
python/samba/tests/samba_tool/user.py
python/samba/tests/samba_tool/user_check_password_script.py
python/samba/tests/usage.py

index ac4c7e3273de71563f4bb68d60091679f576d91c..e2d1e38ccf980829073683ec11c508b72cfc64ad 100644 (file)
@@ -45,14 +45,20 @@ def sddl2binary(sddl_in, domain_sid, name_map):
     return ndr_pack(sec)
 
 
-def get_empty_descriptor(domain_sid, name_map={}):
+def get_empty_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = ""
     return sddl2binary(sddl, domain_sid, name_map)
 
 # "get_schema_descriptor" is located in "schema.py"
 
 
-def get_config_descriptor(domain_sid, name_map={}):
+def get_config_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "O:EAG:EAD:(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
            "(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
            "(OA;;CR;1131f6ac-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
@@ -71,7 +77,10 @@ def get_config_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_config_partitions_descriptor(domain_sid, name_map={}):
+def get_config_partitions_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "D:" \
         "(A;;LCLORC;;;AU)" \
         "(OA;;RP;e48d0154-bcf8-11d1-8702-00c04fb96050;;AU)" \
@@ -89,7 +98,10 @@ def get_config_partitions_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_config_sites_descriptor(domain_sid, name_map={}):
+def get_config_sites_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "D:" \
         "(A;;RPLCLORC;;;AU)" \
         "(OA;CIIO;SW;d31a8757-2447-4545-8081-3bb610cacbf2;f0f8ffab-1191-11d0-a060-00aa006c33ed;RO)" \
@@ -104,7 +116,10 @@ def get_config_sites_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_config_ntds_quotas_descriptor(domain_sid, name_map={}):
+def get_config_ntds_quotas_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "D:" \
         "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;EA)" \
         "(A;;RPLCLORC;;;BA)" \
@@ -112,7 +127,10 @@ def get_config_ntds_quotas_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_config_delete_protected1_descriptor(domain_sid, name_map={}):
+def get_config_delete_protected1_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "D:AI" \
         "(A;;RPLCLORC;;;AU)" \
         "(A;;RPWPCRCCLCLORCWOWDSW;;;EA)" \
@@ -120,7 +138,10 @@ def get_config_delete_protected1_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_config_delete_protected1wd_descriptor(domain_sid, name_map={}):
+def get_config_delete_protected1wd_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "D:AI" \
         "(A;;RPLCLORC;;;WD)" \
         "(A;;RPWPCRCCLCLORCWOWDSW;;;EA)" \
@@ -128,7 +149,10 @@ def get_config_delete_protected1wd_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_config_delete_protected2_descriptor(domain_sid, name_map={}):
+def get_config_delete_protected2_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "D:AI" \
         "(A;;RPLCLORC;;;AU)" \
         "(A;;RPWPCRCCDCLCLORCWOWDSW;;;EA)" \
@@ -136,7 +160,10 @@ def get_config_delete_protected2_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_domain_descriptor(domain_sid, name_map={}):
+def get_domain_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "O:BAG:BAD:AI(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
         "(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
         "(OA;CIIO;RP;5f202010-79a5-11d0-9020-00c04fc2d4cf;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
@@ -189,7 +216,10 @@ def get_domain_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_domain_infrastructure_descriptor(domain_sid, name_map={}):
+def get_domain_infrastructure_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "D:" \
         "(A;;RPLCLORC;;;AU)" \
         "(A;;RPWPCRCCLCLORCWOWDSW;;;DA)" \
@@ -199,7 +229,10 @@ def get_domain_infrastructure_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_domain_builtin_descriptor(domain_sid, name_map={}):
+def get_domain_builtin_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "D:" \
         "(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
         "(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
@@ -256,7 +289,10 @@ def get_domain_builtin_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_domain_computers_descriptor(domain_sid, name_map={}):
+def get_domain_computers_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "D:" \
         "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
         "(A;;RPWPCRCCDCLCLORCWOWDSW;;;DA)" \
@@ -270,7 +306,10 @@ def get_domain_computers_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_domain_users_descriptor(domain_sid, name_map={}):
+def get_domain_users_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "D:" \
         "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
         "(A;;RPWPCRCCDCLCLORCWOWDSW;;;DA)" \
@@ -283,7 +322,10 @@ def get_domain_users_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_managed_service_accounts_descriptor(domain_sid, name_map={}):
+def get_managed_service_accounts_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "D:" \
         "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
         "(A;;RPWPCRCCDCLCLORCWOWDSW;;;DA)" \
@@ -295,7 +337,10 @@ def get_managed_service_accounts_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_domain_controllers_descriptor(domain_sid, name_map={}):
+def get_domain_controllers_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "D:" \
         "(A;;RPLCLORC;;;AU)" \
         "(A;;RPWPCRCCLCLORCWOWDSW;;;DA)" \
@@ -307,7 +352,10 @@ def get_domain_controllers_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_domain_delete_protected1_descriptor(domain_sid, name_map={}):
+def get_domain_delete_protected1_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "D:AI" \
         "(A;;RPLCLORC;;;AU)" \
         "(A;;RPWPCRCCLCLORCWOWDSW;;;DA)" \
@@ -315,7 +363,10 @@ def get_domain_delete_protected1_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_domain_delete_protected2_descriptor(domain_sid, name_map={}):
+def get_domain_delete_protected2_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "D:AI" \
         "(A;;RPLCLORC;;;AU)" \
         "(A;;RPWPCRCCDCLCLORCWOWDSW;;;DA)" \
@@ -323,7 +374,10 @@ def get_domain_delete_protected2_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_dns_partition_descriptor(domain_sid, name_map={}):
+def get_dns_partition_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "O:SYG:BAD:AI" \
         "(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
         "(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
@@ -378,14 +432,20 @@ def get_dns_partition_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_dns_forest_microsoft_dns_descriptor(domain_sid, name_map={}):
+def get_dns_forest_microsoft_dns_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "O:SYG:SYD:AI" \
         "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
         "(A;CI;RPWPCRCCDCLCRCWOWDSDDTSW;;;ED)"
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_dns_domain_microsoft_dns_descriptor(domain_sid, name_map={}):
+def get_dns_domain_microsoft_dns_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "O:SYG:SYD:AI" \
         "(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;DA)" \
         "(A;CI;RPWPCRCCDCLCRCWOWDSDDTSW;;;DnsAdmins)" \
@@ -394,7 +454,10 @@ def get_dns_domain_microsoft_dns_descriptor(domain_sid, name_map={}):
     return sddl2binary(sddl, domain_sid, name_map)
 
 
-def get_paritions_crossref_subdomain_descriptor(domain_sid, name_map={}):
+def get_paritions_crossref_subdomain_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "O:SubdomainAdminsG:SubdomainAdminsD:AI" \
         "(A;;RPWPCRCCLCLORCWOWDSW;;;SubdomainAdmins)" \
         "(A;;RPLCLORC;;;AU)" \
index c141e36b6291563777a5dc65c6cb1ee8d87a0888..f314e3d3fc14d9df4706a06ea0d78fc794b15d89 100644 (file)
@@ -1188,7 +1188,9 @@ class TrafficModel(object):
         self.cumulative_duration = 0.0
         self.packet_rate = [0, 1]
 
-    def learn(self, conversations, dns_opcounts={}):
+    def learn(self, conversations, dns_opcounts=None):
+        if dns_opcounts is None:
+            dns_opcounts = {}
         prev = 0.0
         cum_duration = 0.0
         key = (NON_PACKET,) * (self.n - 1)
index 3be8931bf1ef9310128af0ce24903c89786311fd..312c8ddf467ea5dfbb8096fb16f196d2e06bc53b 100644 (file)
@@ -161,7 +161,9 @@ def fetch_certification_authorities(ldb):
         result.append(data)
     return result
 
-def fetch_template_attrs(ldb, name, attrs=['msPKI-Minimal-Key-Size']):
+def fetch_template_attrs(ldb, name, attrs=None):
+    if attrs is None:
+        attrs = ['msPKI-Minimal-Key-Size']
     basedn = ldb.get_default_basedn()
     dn = 'CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,%s' % basedn
     expr = '(cn=%s)' % name
index bec1ec5fecf8897c7caa1032ded264589774f58f..68c1050f6326d3c26f6589ed2d134424deaf3cfd 100644 (file)
@@ -475,7 +475,7 @@ class gp_applier(object):
         '''
         pass
 
-    def clean(self, guid, keep=[], remove=[], **kwargs):
+    def clean(self, guid, keep=None, remove=None, **kwargs):
         '''Cleanup old removed attributes
         keep    - A list of attributes to keep
         remove  - A single attribute to remove, or a list of attributes to
@@ -487,6 +487,11 @@ class gp_applier(object):
         '''
         # Clean syntax is, either provide a single remove attribute,
         # or a list of either removal attributes or keep attributes.
+        if keep is None:
+            keep = []
+        if remove is None:
+            remove = []
+
         if type(remove) != list:
             value = self.cache_get_attribute_value(guid, remove)
             if value is not None:
index 7373af0961e0df26b61b6eba21bc61ff16ffb3c9..a74a8707d501966f39b5c9e78f9927dfdba1bdaf 100644 (file)
@@ -42,7 +42,9 @@ class slogm(object):
     '''
     Structured log message class
     '''
-    def __init__(self, message, kwargs=dict()):
+    def __init__(self, message, kwargs=None):
+        if kwargs is None:
+            kwargs = {}
         self.message = message
         self.kwargs = kwargs
         if not isinstance(self.kwargs, dict):
@@ -64,35 +66,47 @@ def message_with_code(mtype, message):
 
 class log(object):
     @staticmethod
-    def info(message, data={}):
+    def info(message, data=None):
+        if data is None:
+            data = {}
         msg = message_with_code('I', message)
         logger.info(slogm(msg, data))
         return msg
 
     @staticmethod
-    def warning(message, data={}):
+    def warning(message, data=None):
+        if data is None:
+            data = {}
         msg = message_with_code('W', message)
         logger.warning(slogm(msg, data))
         return msg
 
     @staticmethod
-    def warn(message, data={}):
+    def warn(message, data=None):
+        if data is None:
+            data = {}
         return log.warning(message, data)
 
     @staticmethod
-    def error(message, data={}):
+    def error(message, data=None):
+        if data is None:
+            data = {}
         msg = message_with_code('E', message)
         logger.error(slogm(msg, data))
         return msg
 
     @staticmethod
-    def fatal(message, data={}):
+    def fatal(message, data=None):
+        if data is None:
+            data = {}
         msg = message_with_code('F', message)
         logger.fatal(slogm(msg, data))
         return msg
 
     @staticmethod
-    def debug(message, data={}):
+    def debug(message, data=None):
+        if data is None:
+            data = {}
         msg = message_with_code('D', message)
         logger.debug(slogm(msg, data))
         return msg
index a338fd44a8db526e55ec2a410d798b3cb21a93a3..537dc661fb38bc406a30d42aeb972f8da0772142 100644 (file)
@@ -133,7 +133,7 @@ def shorten_vertex_names(vertices, suffix=',...', aggressive=False):
     return vmap, replacements
 
 
-def compile_graph_key(key_items, nodes_above=[], elisions=None,
+def compile_graph_key(key_items, nodes_above=None, elisions=None,
                       prefix='key_', width=2):
     """Generate a dot file snippet that acts as a legend for a graph.
 
@@ -148,6 +148,8 @@ def compile_graph_key(key_items, nodes_above=[], elisions=None,
     (True) or edge (False). Style is a dot style string for the edge
     or vertex. label is the text associated with the key item.
     """
+    if nodes_above is None:
+        nodes_above = []
     edge_lines = []
     edge_names = []
     vertex_lines = []
index 215e8072f1491da43b50d7fb50be79ac0f9cea56..4d5c79ff11bf280fb83c40ad802aab4cd923f94b 100644 (file)
@@ -96,7 +96,10 @@ class cmd_dbcheck(Command):
             quick_membership_checks=False,
             reset_well_known_acls=False,
             selftest_check_expired_tombstones=False,
-            yes_rules=[]):
+            yes_rules=None):
+
+        if yes_rules is None:
+            yes_rules = []
 
         lp = sambaopts.get_loadparm()
 
index 22c961baaf35b4e1f8c9fa5528bbab7fdc47fd67..d61f121b5b9c4b78417eadee353dae22e8614342 100644 (file)
@@ -111,7 +111,10 @@ class DnsConnWrapper:
                 "DnssrvUpdateRecord2"}:
             return attr
 
-        def f(*args, messages={}):
+        def f(*args, messages=None):
+            if messages is None:
+                messages = {}
+
             try:
                 return attr(*args)
             except WERRORError as e:
index 582a17f0fff5fc25ff340919c66dc240442de28a..c386b0b8112a91b0a03c834601ba27ec4022af85 100644 (file)
@@ -3272,9 +3272,34 @@ class cmd_domain_trust_namespaces(DomainTrustCommand):
 
     def run(self, domain=None, sambaopts=None, localdcopts=None, versionopts=None,
             refresh=None, enable_all=False,
-            enable_tln=[], disable_tln=[], add_tln_ex=[], delete_tln_ex=[],
-            enable_sid_str=[], disable_sid_str=[], enable_nb=[], disable_nb=[],
-            add_upn=[], delete_upn=[], add_spn=[], delete_spn=[]):
+            enable_tln=None, disable_tln=None, add_tln_ex=None, delete_tln_ex=None,
+            enable_sid_str=None, disable_sid_str=None, enable_nb=None, disable_nb=None,
+            add_upn=None, delete_upn=None, add_spn=None, delete_spn=None):
+
+        if enable_tln is None:
+            enable_tln = []
+        if disable_tln is None:
+            disable_tln = []
+        if add_tln_ex is None:
+            add_tln_ex = []
+        if delete_tln_ex is None:
+            delete_tln_ex = []
+        if enable_sid_str is None:
+            enable_sid_str = []
+        if disable_sid_str is None:
+            disable_sid_str = []
+        if enable_nb is None:
+            enable_nb = []
+        if disable_nb is None:
+            disable_nb = []
+        if add_upn is None:
+            add_upn = []
+        if delete_upn is None:
+            delete_upn = []
+        if add_spn is None:
+            add_spn = []
+        if delete_spn is None:
+            delete_spn = []
 
         require_update = False
 
index 340f8f55e5e1aab7cad2ab4874b8b317cc22afff..9b00a9016c3c351f750c1845425fa9a1cbcf1646 100644 (file)
@@ -761,9 +761,13 @@ class cmd_load(GPOCommand):
     ]
 
     def run(self, gpo, H=None, content=None,
-            machine_exts=['{35378EAC-683F-11D2-A89A-00C04FBBCFA2}'],
-            user_exts=['{35378EAC-683F-11D2-A89A-00C04FBBCFA2}'],
+            machine_exts=None,
+            user_exts=None,
             replace=False, sambaopts=None, credopts=None, versionopts=None):
+        if machine_exts is None:
+            machine_exts = ['{35378EAC-683F-11D2-A89A-00C04FBBCFA2}']
+        if user_exts is None:
+            user_exts = ['{35378EAC-683F-11D2-A89A-00C04FBBCFA2}']
         if content is None:
             policy_defs = json.loads(sys.stdin.read())
         elif os.path.exists(content):
@@ -848,8 +852,12 @@ class cmd_remove(GPOCommand):
             help="A user extension name to remove from gPCUserExtensionNames")
     ]
 
-    def run(self, gpo, H=None, content=None, machine_exts=[], user_exts=[],
+    def run(self, gpo, H=None, content=None, machine_exts=None, user_exts=None,
             sambaopts=None, credopts=None, versionopts=None):
+        if machine_exts is None:
+            machine_exts = []
+        if user_exts is None:
+            user_exts = []
         if content is None:
             policy_defs = json.loads(sys.stdin.read())
         elif os.path.exists(content):
index 2f95492d33ae730280e002da15d07fbf1e7385ff..0c20f8d2e541feb98bc5e34a5d108caf90c834f6 100644 (file)
@@ -42,7 +42,7 @@ def setup_path(file):
     return os.path.join(setup_dir(), file)
 
 
-def setup_add_ldif(ldb, ldif_path, subst_vars=None, controls=["relax:0"]):
+def setup_add_ldif(ldb, ldif_path, subst_vars=None, controls=None):
     """Setup a ldb in the private dir.
 
     :param ldb: LDB file to import data into
@@ -50,18 +50,22 @@ def setup_add_ldif(ldb, ldif_path, subst_vars=None, controls=["relax:0"]):
     :param subst_vars: Optional variables to subsitute in LDIF.
     :param nocontrols: Optional list of controls, can be None for no controls
     """
+    if controls is None:
+        controls = ["relax:0"]
     assert isinstance(ldif_path, str)
     data = read_and_sub_file(ldif_path, subst_vars)
     ldb.add_ldif(data, controls)
 
 
-def setup_modify_ldif(ldb, ldif_path, subst_vars=None, controls=["relax:0"]):
+def setup_modify_ldif(ldb, ldif_path, subst_vars=None, controls=None):
     """Modify a ldb in the private dir.
 
     :param ldb: LDB object.
     :param ldif_path: LDIF file path.
     :param subst_vars: Optional dictionary with substitution variables.
     """
+    if controls is None:
+        controls = ["relax:0"]
     data = read_and_sub_file(ldif_path, subst_vars)
     ldb.modify_ldif(data, controls)
 
index 1cba3845fd3aace26c240a36f9462bbaab7a4d20..f6929325a91befd5096f34358a049adb18dd1284 100644 (file)
@@ -361,7 +361,7 @@ lockoutTime: 0
 
     def add_remove_group_members(self, groupname, members,
                                  add_members_operation=True,
-                                 member_types=[ 'user', 'group', 'computer' ],
+                                 member_types=None,
                                  member_base_dn=None):
         """Adds or removes group members
 
@@ -370,6 +370,8 @@ lockoutTime: 0
         :param add_members_operation: Defines if its an add or remove
             operation
         """
+        if member_types is None:
+            member_types = ['user', 'group', 'computer']
 
         groupfilter = "(&(sAMAccountName=%s)(objectCategory=%s,%s))" % (
             ldb.binary_encode(groupname), "CN=Group,CN=Schema,CN=Configuration", self.domain_dn())
@@ -473,10 +475,12 @@ member: %s
         msg.add(el)
 
     def fullname_from_names(self, given_name=None, initials=None, surname=None,
-                            old_attrs={}, fallback_default=""):
+                            old_attrs=None, fallback_default=""):
         """Prepares new combined fullname, using the name parts.
         Used for things like displayName or cn.
         Use the original name values, if no new one is specified."""
+        if old_attrs is None:
+            old_attrs = {}
 
         attrs = {"givenName": given_name,
                  "initials": initials,
index 54ed616a5572db010d5b2d2660458b23bdb32e03..1aa5a530d0050c1c7356041c4bff0dbe214eff7c 100644 (file)
@@ -33,7 +33,10 @@ from samba import dsdb
 from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL
 
 
-def get_schema_descriptor(domain_sid, name_map={}):
+def get_schema_descriptor(domain_sid, name_map=None):
+    if name_map is None:
+        name_map = {}
+
     sddl = "O:SAG:SAD:AI(OA;;CR;e12b56b6-0a95-11d1-adbb-00c04fd8d5cd;;SA)" \
            "(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
            "(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
index 26e80ee2f4ac6d4bc434b364055e1da96b249a3a..c42bc602b4d251ba1dfc877db67da42327066852 100644 (file)
@@ -77,8 +77,10 @@ class SDUtils(object):
             desc_sddl = desc_sddl + ace
         self.modify_sd_on_dn(object_dn, desc_sddl, ["show_deleted:1"])
 
-    def get_sd_as_sddl(self, object_dn, controls=[]):
+    def get_sd_as_sddl(self, object_dn, controls=None):
         """Return object nTSecutiryDescriptor in SDDL format
         """
+        if controls is None:
+            controls = []
         desc = self.read_sd_on_dn(object_dn, controls + ["show_deleted:1"])
         return desc.as_sddl(self.domain_sid)
index 3a4f48dde69f10df890f01b740967ad260d62d79..101f5922a220f406a28c8b03f57ea69270decd12 100644 (file)
@@ -257,8 +257,10 @@ class LdbTestCase(TestCase):
         self.filename = self.tempfile.name
         self.ldb = samba.Ldb(self.filename)
 
-    def set_modules(self, modules=[]):
+    def set_modules(self, modules=None):
         """Change the modules for this Ldb."""
+        if modules is None:
+            modules = []
         m = ldb.Message()
         m.dn = ldb.Dn(self.ldb, "@MODULES")
         m["@LIST"] = ",".join(modules)
index 22b56704fa33d1a81a1d5c18c15a44e9ffbe0230..61aa044fd5bbd29b5c8413a5da3b0a88e718cc1c 100644 (file)
@@ -842,9 +842,11 @@ class RawDCERPCTest(TestCase):
                      rpc_vers_minor=0,
                      pfc_flags=(samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_FIRST |
                                 samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_LAST),
-                     drep=[samba.dcerpc.dcerpc.DCERPC_DREP_LE, 0, 0, 0],
+                     drep=None,
                      ndr_print=None, hexdump=None):
 
+        if drep is None:
+            drep = [samba.dcerpc.dcerpc.DCERPC_DREP_LE, 0, 0, 0]
         if getattr(payload, 'auth_info', None):
             ai = payload.auth_info
         else:
@@ -950,9 +952,11 @@ class RawDCERPCTest(TestCase):
                    rpc_vers_minor=0,
                    pfc_flags=(samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_FIRST |
                               samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_LAST),
-                   drep=[samba.dcerpc.dcerpc.DCERPC_DREP_LE, 0, 0, 0],
+                   drep=None,
                    auth_length=None):
 
+        if drep is None:
+            drep = [samba.dcerpc.dcerpc.DCERPC_DREP_LE, 0, 0, 0]
         self.assertIsNotNone(p, "No valid pdu")
 
         if getattr(p.u, 'auth_info', None):
@@ -984,10 +988,12 @@ class RawDCERPCTest(TestCase):
                       max_xmit_frag=None,
                       max_recv_frag=None,
                       assoc_group_id=0,
-                      ctx_list=[],
+                      ctx_list=None,
                       auth_info=b"",
                       ndr_print=None, hexdump=None):
 
+        if ctx_list is None:
+            ctx_list = []
         if max_xmit_frag is None:
             max_xmit_frag=self.max_xmit_frag
         if max_recv_frag is None:
@@ -1015,10 +1021,12 @@ class RawDCERPCTest(TestCase):
                        max_xmit_frag=None,
                        max_recv_frag=None,
                        assoc_group_id=0,
-                       ctx_list=[],
+                       ctx_list=None,
                        auth_info=b"",
                        ndr_print=None, hexdump=None):
 
+        if ctx_list is None:
+            ctx_list = []
         if max_xmit_frag is None:
             max_xmit_frag=self.max_xmit_frag
         if max_recv_frag is None:
index 36d6f77decf4262db7aaad6eccfc5a1a839dacf4..899b07f2d551af700ec2fb6f4d5e4a932bd5aa02 100644 (file)
@@ -1221,7 +1221,9 @@ class TestZones(DNSTest):
                         Aging=int(bool(enable)),
                         AllowUpdate=dnsp.DNS_ZONE_UPDATE_UNSECURE)
 
-    def test_set_aging(self, enable=True, name='agingtest', txt=['test txt']):
+    def test_set_aging(self, enable=True, name='agingtest', txt=None):
+        if txt is None:
+            txt = ['test txt']
         self.set_aging(enable=True)
         settings = self.ldap_get_zone_settings()
         self.assertTrue(settings['aging_state'] is not None)
index b764fcd049bbb254a11d931e2c6e215b72cf3cc2..7c688c8560cf837c03c1cb87d9af15c389db988a 100644 (file)
@@ -152,7 +152,9 @@ class DomainBackupOfflineCmp(BlackboxTestCase):
 
         self.ldapcmp(self.prov_dir, self.extract_dir)
 
-    def ldapcmp(self, prov_dir, ex_dir, args=[]):
+    def ldapcmp(self, prov_dir, ex_dir, args=None):
+        if args is None:
+            args = []
         sam_fn = os.path.join("private", "sam.ldb")
         url1 = "tdb://" + os.path.join(os.path.realpath(prov_dir), sam_fn)
         url2 = "tdb://" + os.path.join(os.path.realpath(ex_dir), sam_fn)
index 1597240efcd037f5d627f7e5020512df036ae3eb..c1af998f402919b551c741e99781c4bb8ae5f7c3 100644 (file)
@@ -94,7 +94,9 @@ class SiteCoverageTests(samba.tests.TestCase):
         self.sites[dn] = name
         return dn, name.lower()
 
-    def _add_site_link(self, name, links=[], cost=100):
+    def _add_site_link(self, name, links=None, cost=100):
+        if links is None:
+            links = []
         dn = "CN={0},CN=IP,CN=Inter-Site Transports,CN=Sites,{1}".format(
             name, self.samdb.get_config_basedn()
         )
index 231f369c52bf9d229974070c0e0fc2d5781863e3..740aaf0d48a9c4a4c12a4d5cba6072acc77107ab 100644 (file)
@@ -277,9 +277,11 @@ class ComputerCmdTestCase(SambaToolCmdTest):
         self.assertCmdSuccess(result, out, err,
                               "Failed to delete ou '%s'" % parentou["name"])
 
-    def _randomComputer(self, base={}):
+    def _randomComputer(self, base=None):
         """create a computer with random attribute values, you can specify base
         attributes"""
+        if base is None:
+            base = {}
 
         computer = {
             "name": self.randomName(),
@@ -288,9 +290,11 @@ class ComputerCmdTestCase(SambaToolCmdTest):
         computer.update(base)
         return computer
 
-    def _randomOU(self, base={}):
+    def _randomOU(self, base=None):
         """create an ou with random attribute values, you can specify base
         attributes"""
+        if base is None:
+            base = {}
 
         ou = {
             "name": self.randomName(),
index b499a38f812ca66d4b75965f50bbb554fa80f808..7a8ff082e22f767dc36d730e85101b3dd9d25e3d 100644 (file)
@@ -392,9 +392,11 @@ class ContactCmdTestCase(SambaToolCmdTest):
                                                 "--display-name=%s" % old_displayname)
             self.assertCmdSuccess(result, out, err)
 
-    def _randomContact(self, base={}):
+    def _randomContact(self, base=None):
         """Create a contact with random attribute values, you can specify base
         attributes"""
+        if base is None:
+            base = {}
 
         # No name attributes are given here, because the object name will
         # be made from the sn, givenName and initials attributes, if no name
@@ -405,9 +407,11 @@ class ContactCmdTestCase(SambaToolCmdTest):
         contact.update(base)
         return contact
 
-    def _randomOU(self, base={}):
+    def _randomOU(self, base=None):
         """Create an ou with random attribute values, you can specify base
         attributes."""
+        if base is None:
+            base = {}
 
         ou = {
             "name": self.randomName(),
index 3019b7596d2eb51e773c6c71e0a2d4af106af01a..cee42f303d3f3e27d7d00162a5c12ef455da8bb2 100644 (file)
@@ -574,11 +574,13 @@ template """
         self.assertTrue("Total groups: {0}".format(total_groups) in out,
                         "Total groups not reported correctly")
 
-    def _random_user(self, base={}):
+    def _random_user(self, base=None):
         '''
         create a user with random attribute values, you can specify
         base attributes
         '''
+        if base is None:
+            base = {}
         user = {
             "name": self.randomName(),
             "password": self.random_password(16),
index af678b53f9b97dff4fa0cb9012068ef02adfa955..dd5fc672c2b934b549c1c28df4c06ff0ac03ab75 100644 (file)
@@ -261,10 +261,11 @@ class OUCmdTestCase(SambaToolCmdTest):
             found = self.assertMatch(out, str(obj.dn),
                                      "object '%s' not found" % obj.dn)
 
-    def _randomOU(self, base={}):
+    def _randomOU(self, base=None):
         """create an ou with random attribute values, you can specify base
         attributes"""
-
+        if base is None:
+            base = {}
         ou = {
             "name": self.randomName(),
             "description": self.randomName(count=100),
index 9b6d19b11cb6dbe4a6d8345358dadc10d6f0f16d..28fb79146fa9a804a05dd5c17c29fa513bfb8f0f 100644 (file)
@@ -1100,8 +1100,10 @@ sAMAccountName: %s
             self.assertCmdSuccess(result, out, err, "Error running user unlock")
             self.assertEqual(err, "", "Shouldn't be any error messages")
 
-    def _randomUser(self, base={}):
+    def _randomUser(self, base=None):
         """create a user with random attribute values, you can specify base attributes"""
+        if base is None:
+            base = {}
         user = {
             "name": self.randomName(),
             "password": self.random_password(16),
@@ -1117,9 +1119,11 @@ sAMAccountName: %s
         user.update(base)
         return user
 
-    def _randomPosixUser(self, base={}):
+    def _randomPosixUser(self, base=None):
         """create a user with random attribute values and additional RFC2307
         attributes, you can specify base attributes"""
+        if base is None:
+            base = {}
         user = self._randomUser({})
         user.update(base)
         posixAttributes = {
@@ -1135,9 +1139,11 @@ sAMAccountName: %s
         user.update(base)
         return user
 
-    def _randomUnixUser(self, base={}):
+    def _randomUnixUser(self, base=None):
         """create a user with random attribute values and additional RFC2307
         attributes, you can specify base attributes"""
+        if base is None:
+            base = {}
         user = self._randomUser({})
         user.update(base)
         posixAttributes = {
index 60a9add1a19677bd964e083759a45d9331161ecd..9dcb52199e10ff06b1b1a4b4c287665625bf22cb 100644 (file)
@@ -95,8 +95,10 @@ class UserCheckPwdTestCase(SambaToolCmdTest):
                                         good_password,
                                         "username")
 
-    def _randomUser(self, base={}):
+    def _randomUser(self, base=None):
         """create a user with random attribute values, you can specify base attributes"""
+        if base is None:
+            base = {}
         user = {
             "name": self.randomName(),
         }
index 3983dbc74bc622110aba9b6436eb4b0b9289d5ed..27c2810e80064d809d9b00162afe901a17daddc8 100644 (file)
@@ -161,7 +161,9 @@ is_git_file = _init_git_file_finder()
 def script_iterator(d=BASEDIR, cache=None,
                     shebang_filter=None,
                     filename_filter=None,
-                    subdirs=TEST_DIRS):
+                    subdirs=None):
+    if subdirs is None:
+        subdirs = TEST_DIRS
     if not cache:
         safename = re.compile(r'\W+').sub
         for subdir in subdirs: