# HG changeset patch # User Jiří Suchan # Date 2015-10-14 21:08:18 # Node ID 32cdc6f70f1320fc56518e08511b70688829031f # Parent 2d5f442e5abc94907ce3b0f5f48d1896de195263 cleanup: stop using mutable default params diff --git a/CONTRIBUTORS b/CONTRIBUTORS --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -22,6 +22,7 @@ List of contributors to Kallithea projec Étienne Gilli 2015 Grzegorz Krason 2015 Jan Heylen 2015 + Jiří Suchan 2015 Kazunari Kobayashi 2015 Kevin Bullock 2015 kobanari 2015 diff --git a/kallithea/lib/compat.py b/kallithea/lib/compat.py --- a/kallithea/lib/compat.py +++ b/kallithea/lib/compat.py @@ -540,7 +540,8 @@ else: return cmp(type(self), type(other)) return cmp(list(self), list(other)) - def __repr__(self, _track=[]): + def __repr__(self, _track=None): + _track = _track or [] if id(self) in _track: return '...' _track.append(id(self)) @@ -560,8 +561,9 @@ else: def __copy__(self): return self.__class__(self) - def __deepcopy__(self, memo={}): + def __deepcopy__(self, memo=None): from copy import deepcopy + memo = memo or {} result = self.__class__() memo[id(self)] = result result.__init__(deepcopy(tuple(self), memo)) diff --git a/kallithea/lib/db_manage.py b/kallithea/lib/db_manage.py --- a/kallithea/lib/db_manage.py +++ b/kallithea/lib/db_manage.py @@ -61,14 +61,14 @@ def notify(msg): class DbManage(object): - def __init__(self, log_sql, dbconf, root, tests=False, SESSION=None, cli_args={}): + def __init__(self, log_sql, dbconf, root, tests=False, SESSION=None, cli_args=None): self.dbname = dbconf.split('/')[-1] self.tests = tests self.root = root self.dburi = dbconf self.log_sql = log_sql self.db_exists = False - self.cli_args = cli_args + self.cli_args = cli_args or {} self.init_db(SESSION=SESSION) force_ask = self.cli_args.get('force_ask') diff --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py +++ b/kallithea/lib/helpers.py @@ -979,18 +979,17 @@ class Page(_Page): show_if_single_page=False, separator=' ', onclick=None, symbol_first='<<', symbol_last='>>', symbol_previous='<', symbol_next='>', - link_attr={'class': 'pager_link', 'rel': 'prerender'}, - curpage_attr={'class': 'pager_curpage'}, - dotdot_attr={'class': 'pager_dotdot'}, **kwargs): - - self.curpage_attr = curpage_attr + link_attr=None, + curpage_attr=None, + dotdot_attr=None, **kwargs): + self.curpage_attr = curpage_attr or {'class': 'pager_curpage'} self.separator = separator self.pager_kwargs = kwargs self.page_param = page_param self.partial_param = partial_param self.onclick = onclick - self.link_attr = link_attr - self.dotdot_attr = dotdot_attr + self.link_attr = link_attr or {'class': 'pager_link', 'rel': 'prerender'} + self.dotdot_attr = dotdot_attr or {'class': 'pager_dotdot'} # Don't show navigator if there is no more than one page if self.page_count == 0 or (self.page_count == 1 and not show_if_single_page): diff --git a/kallithea/lib/middleware/simplegit.py b/kallithea/lib/middleware/simplegit.py --- a/kallithea/lib/middleware/simplegit.py +++ b/kallithea/lib/middleware/simplegit.py @@ -294,12 +294,11 @@ class SimpleGit(BaseVCSController): if action == 'pull' and _hooks.get(Ui.HOOK_PULL): log_pull_action(ui=baseui, repo=_repo._repo) - def __inject_extras(self, repo_path, baseui, extras={}): + def __inject_extras(self, repo_path, baseui, extras=None): """ Injects some extra params into baseui instance :param baseui: baseui instance :param extras: dict with extra params to put into baseui """ - - _set_extras(extras) + _set_extras(extras or {}) diff --git a/kallithea/lib/middleware/simplehg.py b/kallithea/lib/middleware/simplehg.py --- a/kallithea/lib/middleware/simplehg.py +++ b/kallithea/lib/middleware/simplehg.py @@ -272,7 +272,7 @@ class SimpleHg(BaseVCSController): raise Exception('Unable to detect pull/push action !!' 'Are you using non standard command or client ?') - def __inject_extras(self, repo_path, baseui, extras={}): + def __inject_extras(self, repo_path, baseui, extras=None): """ Injects some extra params into baseui instance @@ -291,4 +291,4 @@ class SimpleHg(BaseVCSController): for section in ui_sections: for k, v in repoui.configitems(section): baseui.setconfig(section, k, v) - _set_extras(extras) + _set_extras(extras or {}) diff --git a/kallithea/lib/rcmail/smtp_mailer.py b/kallithea/lib/rcmail/smtp_mailer.py --- a/kallithea/lib/rcmail/smtp_mailer.py +++ b/kallithea/lib/rcmail/smtp_mailer.py @@ -60,9 +60,9 @@ class SmtpMailer(object): self.debug = debug self.auth = smtp_auth - def send(self, recipients=[], subject='', body='', html='', + def send(self, recipients=None, subject='', body='', html='', attachment_files=None, headers=None): - + recipients = recipients or [] if isinstance(recipients, basestring): recipients = [recipients] if headers is None: diff --git a/kallithea/lib/vcs/subprocessio.py b/kallithea/lib/vcs/subprocessio.py --- a/kallithea/lib/vcs/subprocessio.py +++ b/kallithea/lib/vcs/subprocessio.py @@ -156,8 +156,8 @@ class BufferedGenerator(object): """ def __init__(self, source, buffer_size=65536, chunk_size=4096, - starting_values=[], bottomless=False): - + starting_values=None, bottomless=False): + starting_values = starting_values or [] if bottomless: maxlen = int(buffer_size / chunk_size) else: @@ -326,7 +326,7 @@ class SubprocessIOChunker(object): """ def __init__(self, cmd, inputstream=None, buffer_size=65536, - chunk_size=4096, starting_values=[], **kwargs): + chunk_size=4096, starting_values=None, **kwargs): """ Initializes SubprocessIOChunker @@ -336,7 +336,7 @@ class SubprocessIOChunker(object): :param chunk_size: (Default: 4096) A max size of a chunk. Actual chunk may be smaller. :param starting_values: (Default: []) An array of strings to put in front of output que. """ - + starting_values = starting_values or [] if inputstream: input_streamer = StreamFeeder(inputstream) input_streamer.start() diff --git a/kallithea/lib/vcs/utils/compat.py b/kallithea/lib/vcs/utils/compat.py --- a/kallithea/lib/vcs/utils/compat.py +++ b/kallithea/lib/vcs/utils/compat.py @@ -120,7 +120,8 @@ else: return cmp(type(self), type(other)) return cmp(list(self), list(other)) - def __repr__(self, _track=[]): + def __repr__(self, _track=None): + _track = _track or [] if id(self) in _track: return '...' _track.append(id(self)) @@ -140,8 +141,9 @@ else: def __copy__(self): return self.__class__(self) - def __deepcopy__(self, memo={}): + def __deepcopy__(self, memo=None): from copy import deepcopy + memo = memo or {} result = self.__class__() memo[id(self)] = result result.__init__(deepcopy(tuple(self), memo)) diff --git a/kallithea/model/forms.py b/kallithea/model/forms.py --- a/kallithea/model/forms.py +++ b/kallithea/model/forms.py @@ -86,7 +86,8 @@ def PasswordChangeForm(username): return _PasswordChangeForm -def UserForm(edit=False, old_data={}): +def UserForm(edit=False, old_data=None): + old_data = old_data or {} class _UserForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = True @@ -125,7 +126,9 @@ def UserForm(edit=False, old_data={}): return _UserForm -def UserGroupForm(edit=False, old_data={}, available_members=[]): +def UserGroupForm(edit=False, old_data=None, available_members=None): + old_data = old_data or {} + available_members = available_members or [] class _UserGroupForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = True @@ -148,8 +151,10 @@ def UserGroupForm(edit=False, old_data={ return _UserGroupForm -def RepoGroupForm(edit=False, old_data={}, repo_groups=[], +def RepoGroupForm(edit=False, old_data=None, repo_groups=None, can_create_in_root=False): + old_data = old_data or {} + repo_groups = repo_groups or [] repo_group_ids = [rg[0] for rg in repo_groups] class _RepoGroupForm(formencode.Schema): allow_extra_fields = True @@ -178,7 +183,7 @@ def RepoGroupForm(edit=False, old_data={ return _RepoGroupForm -def RegisterForm(edit=False, old_data={}): +def RegisterForm(edit=False, old_data=None): class _RegisterForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = True @@ -227,8 +232,11 @@ def PasswordResetConfirmationForm(): 'password_confirm')] return _PasswordResetConfirmationForm -def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(), - repo_groups=[], landing_revs=[]): +def RepoForm(edit=False, old_data=None, supported_backends=BACKENDS.keys(), + repo_groups=None, landing_revs=None): + old_data = old_data or {} + repo_groups = repo_groups or [] + landing_revs = landing_revs or [] repo_group_ids = [rg[0] for rg in repo_groups] class _RepoForm(formencode.Schema): allow_extra_fields = True @@ -302,8 +310,11 @@ def RepoFieldForm(): return _RepoFieldForm -def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(), - repo_groups=[], landing_revs=[]): +def RepoForkForm(edit=False, old_data=None, supported_backends=BACKENDS.keys(), + repo_groups=None, landing_revs=None): + old_data = old_data or {} + repo_groups = repo_groups or [] + landing_revs = landing_revs or [] repo_group_ids = [rg[0] for rg in repo_groups] class _RepoForkForm(formencode.Schema): allow_extra_fields = True @@ -421,7 +432,7 @@ def CustomDefaultPermissionsForm(): return _CustomDefaultPermissionsForm -def DefaultsForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()): +def DefaultsForm(edit=False, old_data=None, supported_backends=BACKENDS.keys()): class _DefaultsForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = True diff --git a/kallithea/model/notification.py b/kallithea/model/notification.py --- a/kallithea/model/notification.py +++ b/kallithea/model/notification.py @@ -59,7 +59,7 @@ class NotificationModel(BaseModel): def create(self, created_by, subject, body, recipients=None, type_=Notification.TYPE_MESSAGE, with_email=True, - email_kwargs={}): + email_kwargs=None): """ Creates notification of given type @@ -75,7 +75,7 @@ class NotificationModel(BaseModel): :param email_kwargs: additional dict to pass as args to email template """ from kallithea.lib.celerylib import tasks, run_task - + email_kwargs = email_kwargs or {} if recipients and not getattr(recipients, '__iter__', False): raise Exception('recipients must be a list or iterable') diff --git a/kallithea/model/user.py b/kallithea/model/user.py --- a/kallithea/model/user.py +++ b/kallithea/model/user.py @@ -206,9 +206,9 @@ class UserModel(BaseModel): type_=Notification.TYPE_REGISTRATION, email_kwargs=email_kwargs) - def update(self, user_id, form_data, skip_attrs=[]): + def update(self, user_id, form_data, skip_attrs=None): from kallithea.lib.auth import get_crypt_password - + skip_attrs = skip_attrs or [] user = self.get(user_id, cache=False) if user.username == User.DEFAULT_USER: raise DefaultUserException( diff --git a/kallithea/model/validators.py b/kallithea/model/validators.py --- a/kallithea/model/validators.py +++ b/kallithea/model/validators.py @@ -89,7 +89,8 @@ def UniqueListFromString(): return _UniqueListFromString -def ValidUsername(edit=False, old_data={}): +def ValidUsername(edit=False, old_data=None): + old_data = old_data or {} class _validator(formencode.validators.FancyValidator): messages = { 'username_exists': _('Username "%(username)s" already exists'), @@ -146,7 +147,8 @@ def ValidRepoUser(): return _validator -def ValidUserGroup(edit=False, old_data={}): +def ValidUserGroup(edit=False, old_data=None): + old_data = old_data or {} class _validator(formencode.validators.FancyValidator): messages = { 'invalid_group': _('Invalid user group name'), @@ -187,7 +189,9 @@ def ValidUserGroup(edit=False, old_data= return _validator -def ValidRepoGroup(edit=False, old_data={}): +def ValidRepoGroup(edit=False, old_data=None): + old_data = old_data or {} + class _validator(formencode.validators.FancyValidator): messages = { 'group_parent_id': _('Cannot assign this group as parent'), @@ -338,7 +342,9 @@ def ValidAuthToken(): return _validator -def ValidRepoName(edit=False, old_data={}): +def ValidRepoName(edit=False, old_data=None): + old_data = old_data or {} + class _validator(formencode.validators.FancyValidator): messages = { 'invalid_repo_name': @@ -373,7 +379,6 @@ def ValidRepoName(edit=False, old_data={ return value def validate_python(self, value, state): - repo_name = value.get('repo_name') repo_name_full = value.get('repo_name_full') group_path = value.get('group_path') @@ -483,7 +488,9 @@ def ValidCloneUri(): return _validator -def ValidForkType(old_data={}): +def ValidForkType(old_data=None): + old_data = old_data or {} + class _validator(formencode.validators.FancyValidator): messages = { 'invalid_fork_type': _('Fork has to be the same type as parent') @@ -699,7 +706,9 @@ def ValidPath(): return _validator -def UniqSystemEmail(old_data={}): +def UniqSystemEmail(old_data=None): + old_data = old_data or {} + class _validator(formencode.validators.FancyValidator): messages = { 'email_taken': _('This email address is already in use') diff --git a/kallithea/templates/about.html b/kallithea/templates/about.html --- a/kallithea/templates/about.html +++ b/kallithea/templates/about.html @@ -49,6 +49,7 @@
  • Copyright © 2015, Étienne Gilli
  • Copyright © 2015, Grzegorz Krason
  • Copyright © 2015, Jan Heylen
  • +
  • Copyright © 2015, Jiří Suchan
  • Copyright © 2015, Kazunari Kobayashi
  • Copyright © 2015, Kevin Bullock
  • Copyright © 2015, kobanari