Mercurial > kallithea
changeset 3625:260a7a01b054 beta
follow Python conventions for boolean values
True and False might be singletons and the "default" values for "boolean"
expressions, but "all" values in Python has a boolean value and should be
evaluated as such. Checking with 'is True' and 'is False' is thus confusing,
error prone and unnessarily complex.
If we anywhere rely and nullable boolean fields from the database layer and
don't want the null value to be treated as False then we should check
explicitly for null with 'is None'.
line wrap: on
line diff
--- a/rhodecode/controllers/admin/notifications.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/controllers/admin/notifications.py Thu Mar 28 01:10:45 2013 +0100 @@ -159,7 +159,7 @@ # if this association to user is not valid, we don't want to show # this message if unotification: - if unotification.read is False: + if not unotification.read: unotification.mark_as_read() Session().commit() c.notification = no
--- a/rhodecode/controllers/admin/repos_groups.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/controllers/admin/repos_groups.py Thu Mar 28 01:10:45 2013 +0100 @@ -348,7 +348,7 @@ .filter(RepoGroup.group_parent_id == c.group.group_id).all() c.groups = self.scm_model.get_repos_groups(groups) - if c.visual.lightweight_dashboard is False: + if not c.visual.lightweight_dashboard: c.repos_list = self.scm_model.get_repos(all_repos=gr_filter) ## lightweight version of dashboard else:
--- a/rhodecode/controllers/files.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/controllers/files.py Thu Mar 28 01:10:45 2013 +0100 @@ -416,7 +416,7 @@ try: dbrepo = RepoModel().get_by_repo_name(repo_name) - if dbrepo.enable_downloads is False: + if not dbrepo.enable_downloads: return _('downloads disabled') if c.rhodecode_repo.alias == 'hg':
--- a/rhodecode/controllers/home.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/controllers/home.py Thu Mar 28 01:10:45 2013 +0100 @@ -52,7 +52,7 @@ c.groups = self.scm_model.get_repos_groups() c.group = None - if c.visual.lightweight_dashboard is False: + if not c.visual.lightweight_dashboard: c.repos_list = self.scm_model.get_repos() ## lightweight version of dashboard else:
--- a/rhodecode/controllers/login.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/controllers/login.py Thu Mar 28 01:10:45 2013 +0100 @@ -76,7 +76,7 @@ Session().commit() # If they want to be remembered, update the cookie - if c.form_result['remember'] is not False: + if c.form_result['remember']: _year = (datetime.datetime.now() + datetime.timedelta(seconds=60 * 60 * 24 * 365)) session._set_cookie_expires(_year)
--- a/rhodecode/lib/auth.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/lib/auth.py Thu Mar 28 01:10:45 2013 +0100 @@ -381,7 +381,7 @@ if not is_user_loaded: # if we cannot authenticate user try anonymous - if self.anonymous_user.active is True: + if self.anonymous_user.active: user_model.fill_data(self, user_id=self.anonymous_user.user_id) # then we set this user is logged in self.is_authenticated = True
--- a/rhodecode/lib/celerylib/__init__.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/lib/celerylib/__init__.py Thu Mar 28 01:10:45 2013 +0100 @@ -124,7 +124,7 @@ ret = func(*fargs, **fkwargs) return ret finally: - if CELERY_ON and CELERY_EAGER is False: + if CELERY_ON and not CELERY_EAGER: meta.Session.remove() return decorator(__wrapper, func)
--- a/rhodecode/lib/db_manage.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/lib/db_manage.py Thu Mar 28 01:10:45 2013 +0100 @@ -69,9 +69,9 @@ self.init_db() global ask_ok - if self.cli_args.get('force_ask') is True: + if self.cli_args.get('force_ask'): ask_ok = lambda *args, **kwargs: True - elif self.cli_args.get('force_ask') is False: + elif not self.cli_args.get('force_ask'): ask_ok = lambda *args, **kwargs: False def init_db(self): @@ -589,7 +589,7 @@ if retries == 0: sys.exit('max retries reached') - if path_ok is False: + if not path_ok: retries -= 1 return self.config_prompt(test_repo_path, retries)
--- a/rhodecode/lib/diffs.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/lib/diffs.py Thu Mar 28 01:10:45 2013 +0100 @@ -421,7 +421,7 @@ sorter = lambda info: {'A': 0, 'M': 1, 'D': 2}.get(info['operation']) - if inline_diff is False: + if not inline_diff: return diff_container(sorted(_files, key=sorter)) # highlight inline changes
--- a/rhodecode/lib/hooks.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/lib/hooks.py Thu Mar 28 01:10:45 2013 +0100 @@ -143,7 +143,7 @@ kw.update(ex) callback(**kw) - if ex.make_lock is True: + if ex.make_lock: Repository.lock(Repository.get_by_repo_name(ex.repository), user.user_id) #msg = 'Made lock on repo `%s`' % repository #sys.stdout.write(msg) @@ -202,7 +202,7 @@ kw.update(ex) callback(**kw) - if ex.make_lock is False: + if not ex.make_lock: Repository.unlock(Repository.get_by_repo_name(ex.repository)) msg = 'Released lock on repo `%s`\n' % ex.repository sys.stdout.write(msg)
--- a/rhodecode/lib/middleware/simplegit.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/lib/middleware/simplegit.py Thu Mar 28 01:10:45 2013 +0100 @@ -126,7 +126,7 @@ return HTTPInternalServerError()(environ, start_response) # quick check if that dir exists... - if is_valid_repo(repo_name, self.basepath, 'git') is False: + if not is_valid_repo(repo_name, self.basepath, 'git'): return HTTPNotFound()(environ, start_response) #====================================================================== @@ -143,11 +143,11 @@ anonymous_perm = self._check_permission(action, anonymous_user, repo_name, ip_addr) - if anonymous_perm is not True or anonymous_user.active is False: - if anonymous_perm is not True: + if not anonymous_perm or not anonymous_user.active: + if not anonymous_perm: log.debug('Not enough credentials to access this ' 'repository as anonymous user') - if anonymous_user.active is False: + if not anonymous_user.active: log.debug('Anonymous access is disabled, running ' 'authentication') #============================================================== @@ -184,7 +184,7 @@ #check permissions for this repository perm = self._check_permission(action, user, repo_name, ip_addr) - if perm is not True: + if not perm: return HTTPForbidden()(environ, start_response) # extras are injected into UI object and later available
--- a/rhodecode/lib/middleware/simplehg.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/lib/middleware/simplehg.py Thu Mar 28 01:10:45 2013 +0100 @@ -89,7 +89,7 @@ return HTTPInternalServerError()(environ, start_response) # quick check if that dir exists... - if is_valid_repo(repo_name, self.basepath, 'hg') is False: + if not is_valid_repo(repo_name, self.basepath, 'hg'): return HTTPNotFound()(environ, start_response) #====================================================================== @@ -106,11 +106,11 @@ anonymous_perm = self._check_permission(action, anonymous_user, repo_name, ip_addr) - if anonymous_perm is not True or anonymous_user.active is False: - if anonymous_perm is not True: + if not anonymous_perm or not anonymous_user.active: + if not anonymous_perm: log.debug('Not enough credentials to access this ' 'repository as anonymous user') - if anonymous_user.active is False: + if not anonymous_user.active: log.debug('Anonymous access is disabled, running ' 'authentication') #============================================================== @@ -147,7 +147,7 @@ #check permissions for this repository perm = self._check_permission(action, user, repo_name, ip_addr) - if perm is not True: + if not perm: return HTTPForbidden()(environ, start_response) # extras are injected into mercurial UI object and later available
--- a/rhodecode/lib/rcmail/response.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/lib/rcmail/response.py Thu Mar 28 01:10:45 2013 +0100 @@ -444,7 +444,7 @@ try: return value.encode("ascii") except UnicodeEncodeError: - if not_email is False and VALUE_IS_EMAIL_ADDRESS(value): + if not not_email and VALUE_IS_EMAIL_ADDRESS(value): # this could have an email address, make sure we don't screw it up name, address = parseaddr(value) return '"%s" <%s>' % (
--- a/rhodecode/model/db.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/model/db.py Thu Mar 28 01:10:45 2013 +0100 @@ -1698,7 +1698,7 @@ cache_key = cls._get_cache_key(key) inv = cls._get_or_create_inv_obj(cache_key, repo_name) - if inv and inv.cache_active is False: + if inv and not inv.cache_active: return inv @classmethod
--- a/rhodecode/model/notification.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/model/notification.py Thu Mar 28 01:10:45 2013 +0100 @@ -100,7 +100,7 @@ body=body, recipients=recipients_objs, type_=type_ ) - if with_email is False: + if not with_email: return notif #don't send email to person who created this comment
--- a/rhodecode/model/permission.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/model/permission.py Thu Mar 28 01:10:45 2013 +0100 @@ -120,7 +120,7 @@ .all(): #don't reset PRIVATE repositories - if r2p.repository.private is False: + if not r2p.repository.private: r2p.permission = _def self.sa.add(r2p)
--- a/rhodecode/model/user.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/model/user.py Thu Mar 28 01:10:45 2013 +0100 @@ -132,7 +132,7 @@ new_user.username = username new_user.admin = admin # set password only if creating an user or password is changed - if edit is False or user.password != password: + if not edit or user.password != password: new_user.password = get_crypt_password(password) new_user.api_key = generate_api_key(username) new_user.email = email
--- a/rhodecode/model/users_group.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/model/users_group.py Thu Mar 28 01:10:45 2013 +0100 @@ -102,7 +102,7 @@ assigned_groups = UserGroupRepoToPerm.query()\ .filter(UserGroupRepoToPerm.users_group == users_group).all() - if assigned_groups and force is False: + if assigned_groups and not force: raise UserGroupsAssignedException('RepoGroup assigned to %s' % assigned_groups)
--- a/rhodecode/model/validators.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/model/validators.py Thu Mar 28 01:10:45 2013 +0100 @@ -280,7 +280,7 @@ if not authenticate(username, password): user = User.get_by_username(username) - if user and user.active is False: + if user and not user.active: log.warning('user %s is disabled' % username) msg = M(self, 'disabled_account', state) raise formencode.Invalid(msg, value, state, @@ -503,7 +503,7 @@ error_dict=dict(repo_type=msg) ) ## check if we can write to root location ! - elif gr is None and can_create_repos() is False: + elif gr is None and not can_create_repos(): msg = M(self, 'permission_denied_root', state) raise formencode.Invalid(msg, value, state, error_dict=dict(repo_type=msg) @@ -533,7 +533,7 @@ #we can create in root, we're fine no validations required return - forbidden_in_root = gr is None and can_create_in_root is False + forbidden_in_root = gr is None and not can_create_in_root val = HasReposGroupPermissionAny('group.admin') forbidden = not val(gr_name, 'can create group validator') if forbidden_in_root or forbidden:
--- a/rhodecode/templates/files/files_source.html Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/templates/files/files_source.html Thu Mar 28 01:10:45 2013 +0100 @@ -25,7 +25,7 @@ ${h.link_to(_('show as raw'),h.url('files_raw_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path),class_="ui-btn")} ${h.link_to(_('download as raw'),h.url('files_rawfile_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path),class_="ui-btn")} % if h.HasRepoPermissionAny('repository.write','repository.admin')(c.repo_name): - % if c.on_branch_head and c.changeset.branch and c.file.is_binary is False: + % if c.on_branch_head and c.changeset.branch and not c.file.is_binary: ${h.link_to(_('edit on branch:%s') % c.changeset.branch,h.url('files_edit_home',repo_name=c.repo_name,revision=c.changeset.branch,f_path=c.f_path),class_="ui-btn")} %else: ${h.link_to(_('edit on branch:?'), '#', class_="ui-btn disabled tooltip", title=_('Editing files allowed only when on branch head revision'))}
--- a/rhodecode/templates/index_base.html Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/templates/index_base.html Thu Mar 28 01:10:45 2013 +0100 @@ -72,7 +72,7 @@ </div> <%cnt=0%> <%namespace name="dt" file="/data_table/_dt_elements.html"/> - % if c.visual.lightweight_dashboard is False: + % if not c.visual.lightweight_dashboard: ## old full detailed version <div id='repos_list_wrap' class="yui-skin-sam"> <table id="repos_list"> @@ -131,7 +131,7 @@ % endif </div> </div> - % if c.visual.lightweight_dashboard is False: + % if not c.visual.lightweight_dashboard: <script> YUD.get('repo_count').innerHTML = ${cnt+1 if cnt else 0};
--- a/rhodecode/templates/summary/summary.html Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/templates/summary/summary.html Thu Mar 28 01:10:45 2013 +0100 @@ -146,7 +146,7 @@ <div class="input ${summary(c.show_stats)}"> %if len(c.rhodecode_repo.revisions) == 0: ${_('There are no downloads yet')} - %elif c.enable_downloads is False: + %elif not c.enable_downloads: ${_('Downloads are disabled for this repository')} %if h.HasPermissionAll('hg.admin')('enable downloads on from summary'): ${h.link_to(_('enable'),h.url('edit_repo',repo_name=c.repo_name),class_="ui-btn")}
--- a/rhodecode/tests/scripts/test_concurency.py Thu Mar 28 01:10:45 2013 +0100 +++ b/rhodecode/tests/scripts/test_concurency.py Thu Mar 28 01:10:45 2013 +0100 @@ -183,7 +183,7 @@ else: stdout, stderr = Command(cwd).execute(backend, method, clone_url, dest) print stdout,'sdasdsadsa' - if no_errors is False: + if not no_errors: if backend == 'hg': assert """adding file changes""" in stdout, 'no messages about cloning' assert """abort""" not in stderr , 'got error from clone'