1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-27 07:06:13 +01:00

Fix dangerous (mutable) default values

This commit is contained in:
Daniel Mach 2022-08-29 15:32:41 +02:00
parent f54ff7f9c3
commit f12c72a69f
5 changed files with 35 additions and 22 deletions

View File

@ -202,8 +202,8 @@ class OscConfigParser(configparser.ConfigParser):
In order to keep the order and the format it makes use of the ConfigLineOrder() In order to keep the order and the format it makes use of the ConfigLineOrder()
class. class.
""" """
def __init__(self, defaults={}): def __init__(self, defaults=None):
super().__init__(defaults) super().__init__(defaults or {})
self._sections = ConfigLineOrder() self._sections = ConfigLineOrder()
# XXX: unfortunately we have to override the _read() method from the ConfigParser() # XXX: unfortunately we have to override the _read() method from the ConfigParser()

View File

@ -69,7 +69,8 @@ if hostarch == 'parisc':
class Buildinfo: class Buildinfo:
"""represent the contents of a buildinfo file""" """represent the contents of a buildinfo file"""
def __init__(self, filename, apiurl, buildtype = 'spec', localpkgs = [], binarytype = 'rpm'): def __init__(self, filename, apiurl, buildtype='spec', localpkgs=None, binarytype='rpm'):
localpkgs = localpkgs or []
try: try:
tree = ET.parse(filename) tree = ET.parse(filename)
except: except:
@ -211,8 +212,8 @@ class Pac:
We build a map that's later used to fill our URL templates We build a map that's later used to fill our URL templates
""" """
def __init__(self, node, buildarch, pacsuffix, apiurl, localpkgs = []): def __init__(self, node, buildarch, pacsuffix, apiurl, localpkgs=None):
localpkgs = localpkgs or []
self.mp = {} self.mp = {}
for i in ['binary', 'package', for i in ['binary', 'package',
'epoch', 'version', 'release', 'hdrmd5', 'epoch', 'version', 'release', 'hdrmd5',
@ -1074,7 +1075,6 @@ def main(apiurl, opts, argv):
fetcher = Fetcher(cache_dir, fetcher = Fetcher(cache_dir,
urllist = urllist, urllist = urllist,
api_host_options = config['api_host_options'],
offline = opts.noinit or opts.offline, offline = opts.noinit or opts.offline,
http_debug = config['http_debug'], http_debug = config['http_debug'],
modules = bi.modules, modules = bi.modules,

View File

@ -25,7 +25,8 @@ class Checker:
self.ts.setVSFlags(0) self.ts.setVSFlags(0)
#self.ts.Debug(1) #self.ts.Debug(1)
def readkeys(self, keys=[]): def readkeys(self, keys=None):
keys = keys or []
rpm.addMacro('_dbpath', self.dbdir) rpm.addMacro('_dbpath', self.dbdir)
for key in keys: for key in keys:
try: try:

View File

@ -987,7 +987,8 @@ class Project:
finally: finally:
self.write_packages() self.write_packages()
def commit(self, pacs = (), msg = '', files = {}, verbose = False, skip_local_service_run = False, can_branch=False, force=False): def commit(self, pacs=(), msg='', files=None, verbose=False, skip_local_service_run=False, can_branch=False, force=False):
files = files or {}
if pacs: if pacs:
try: try:
for pac in pacs: for pac in pacs:
@ -1034,8 +1035,9 @@ class Project:
finally: finally:
self.write_packages() self.write_packages()
def commitNewPackage(self, pac, msg = '', files = [], verbose = False, skip_local_service_run = False): def commitNewPackage(self, pac, msg='', files=None, verbose=False, skip_local_service_run=False):
"""creates and commits a new package if it does not exist on the server""" """creates and commits a new package if it does not exist on the server"""
files = files or []
if pac in self.pacs_available: if pac in self.pacs_available:
print('package \'%s\' already exists' % pac) print('package \'%s\' already exists' % pac)
else: else:
@ -1083,8 +1085,9 @@ class Project:
delete_package(self.apiurl, self.name, pac) delete_package(self.apiurl, self.name, pac)
self.del_package_node(pac) self.del_package_node(pac)
def commitExtPackage(self, pac, msg, files = [], verbose=False, skip_local_service_run=False): def commitExtPackage(self, pac, msg, files=None, verbose=False, skip_local_service_run=False):
"""commits a package from an external project""" """commits a package from an external project"""
files = files or []
if os_path_samefile(os.path.join(self.dir, pac), os.getcwd()): if os_path_samefile(os.path.join(self.dir, pac), os.getcwd()):
pac_path = '.' pac_path = '.'
else: else:
@ -3326,7 +3329,7 @@ def pathjoin(a, *p):
return path return path
def makeurl(baseurl, l, query=[]): def makeurl(baseurl, l, query=None):
"""Given a list of path compoments, construct a complete URL. """Given a list of path compoments, construct a complete URL.
Optional parameters for a query string can be given as a list, as a Optional parameters for a query string can be given as a list, as a
@ -3334,7 +3337,7 @@ def makeurl(baseurl, l, query=[]):
In case of a dictionary, the parameters will be urlencoded by this In case of a dictionary, the parameters will be urlencoded by this
function. In case of a list not -- this is to be backwards compatible. function. In case of a list not -- this is to be backwards compatible.
""" """
query = query or []
if conf.config['debug']: if conf.config['debug']:
print('makeurl:', baseurl, l, query) print('makeurl:', baseurl, l, query)
@ -4434,8 +4437,9 @@ def get_exact_request_list(apiurl, src_project, dst_project, src_package=None, d
requests.append(r) requests.append(r)
return requests return requests
def get_request_list(apiurl, project='', package='', req_who='', req_state=('new', 'review', 'declined'), req_type=None, exclude_target_projects=[], def get_request_list(apiurl, project='', package='', req_who='', req_state=('new', 'review', 'declined'), req_type=None, exclude_target_projects=None,
withfullhistory=False): withfullhistory=False):
exclude_target_projects = exclude_target_projects or []
xpath = '' xpath = ''
if not 'all' in req_state: if not 'all' in req_state:
for state in req_state: for state in req_state:
@ -4476,9 +4480,11 @@ def get_request_list(apiurl, project='', package='', req_who='', req_state=('new
return requests return requests
# old style search, this is to be removed # old style search, this is to be removed
def get_user_projpkgs_request_list(apiurl, user, req_state=('new', 'review', ), req_type=None, exclude_projects=[], projpkgs={}): def get_user_projpkgs_request_list(apiurl, user, req_state=('new', 'review', ), req_type=None, exclude_projects=None, projpkgs=None):
"""OBSOLETE: user involved request search is supported by OBS 2.2 server side in a better way """OBSOLETE: user involved request search is supported by OBS 2.2 server side in a better way
Return all running requests for all projects/packages where is user is involved""" Return all running requests for all projects/packages where is user is involved"""
exclude_projects = exclude_projects or []
projpkgs = projpkgs or {}
if not projpkgs: if not projpkgs:
res = get_user_projpkgs(apiurl, user, exclude_projects=exclude_projects) res = get_user_projpkgs(apiurl, user, exclude_projects=exclude_projects)
projects = [] projects = []
@ -5717,7 +5723,9 @@ def get_binarylist_published(apiurl, prj, repo, arch):
return r return r
def show_results_meta(apiurl, prj, package=None, lastbuild=None, repository=[], arch=[], oldstate=None, multibuild=False, locallink=False, code=None): def show_results_meta(apiurl, prj, package=None, lastbuild=None, repository=None, arch=None, oldstate=None, multibuild=False, locallink=False, code=None):
repository = repository or []
arch = arch or []
query = [] query = []
if package: if package:
query.append('package=%s' % quote_plus(package)) query.append('package=%s' % quote_plus(package))
@ -6729,7 +6737,7 @@ def checkRevision(prj, pac, revision, apiurl=None, meta=False):
except (ValueError, TypeError): except (ValueError, TypeError):
return False return False
def build_table(col_num, data = [], headline = [], width=1, csv = False): def build_table(col_num, data=None, headline=None, width=1, csv=False):
""" """
This method builds a simple table. This method builds a simple table.
@ -6741,6 +6749,8 @@ def build_table(col_num, data = [], headline = [], width=1, csv = False):
foo bar foo bar
suse osc suse osc
""" """
data = data or []
headline = headline or []
longest_col = [] longest_col = []
for i in range(col_num): for i in range(col_num):
@ -7364,7 +7374,8 @@ def get_commit_message_template(pac):
return template return template
def parse_diff_for_commit_message(diff, template = []): def parse_diff_for_commit_message(diff, template=None):
template = template or []
date_re = re.compile(r'\+(Mon|Tue|Wed|Thu|Fri|Sat|Sun) ([A-Z][a-z]{2}) ( ?[0-9]|[0-3][0-9]) .*') date_re = re.compile(r'\+(Mon|Tue|Wed|Thu|Fri|Sat|Sun) ([A-Z][a-z]{2}) ( ?[0-9]|[0-3][0-9]) .*')
diff = diff.split('\n') diff = diff.split('\n')
@ -7744,8 +7755,9 @@ def edit_submitrequest(apiurl, project, orequest, new_request=None):
new_action.opt_sourceupdate = 'cleanup' new_action.opt_sourceupdate = 'cleanup'
return r return r
def get_user_projpkgs(apiurl, user, role=None, exclude_projects=[], proj=True, pkg=True, maintained=False, metadata=False): def get_user_projpkgs(apiurl, user, role=None, exclude_projects=None, proj=True, pkg=True, maintained=False, metadata=False):
"""Return all project/packages where user is involved.""" """Return all project/packages where user is involved."""
exclude_projects = exclude_projects or []
xpath = 'person/@userid = \'%s\'' % user xpath = 'person/@userid = \'%s\'' % user
excl_prj = '' excl_prj = ''
excl_pkg = '' excl_pkg = ''

View File

@ -21,9 +21,9 @@ from .util.helper import decode_it
class Fetcher: class Fetcher:
def __init__(self, cachedir='/tmp', api_host_options={}, urllist=[], def __init__(self, cachedir='/tmp', urllist=None,
http_debug=False, cookiejar=None, offline=False, http_debug=False, cookiejar=None, offline=False,
enable_cpio=True, modules=[], download_api_only=False): enable_cpio=True, modules=None, download_api_only=False):
# set up progress bar callback # set up progress bar callback
self.progress_obj = None self.progress_obj = None
if sys.stdout.isatty(): if sys.stdout.isatty():
@ -31,8 +31,8 @@ class Fetcher:
self.cachedir = cachedir self.cachedir = cachedir
# generic download URL lists # generic download URL lists
self.urllist = urllist self.urllist = urllist or []
self.modules = modules self.modules = modules or []
self.http_debug = http_debug self.http_debug = http_debug
self.offline = offline self.offline = offline
self.cpio = {} self.cpio = {}