Changeset - 63bed817308c
[Not reviewed]
default
0 19 0
Mads Kiilerich - 10 years ago 2015-07-24 16:37:40
madski@unity3d.com
cleanup: check for None object identity in cases where that is what the 'contract' says

Avoid applying bool() on complex objects - it might return something unexpected
such as the key (which might be 0 and thus be false). Checking for None is more
safe and faster.
19 files changed with 40 insertions and 40 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/auth_settings.py
Show inline comments
 
@@ -76,7 +76,7 @@ class AuthSettingsController(BaseControl
 
                    c.defaults[fullname] = v["default"]
 
                # Current values will be the default on the form, if there are any
 
                setting = Setting.get_by_name(fullname)
 
                if setting:
 
                if setting is not None:
 
                    c.defaults[fullname] = setting.app_settings_value
 
        # we want to show , separated list of enabled plugins
 
        c.defaults['auth_plugins'] = ','.join(c.enabled_plugins)
kallithea/controllers/admin/my_account.py
Show inline comments
 
@@ -259,7 +259,7 @@ class MyAccountController(BaseController
 
        user_id = self.authuser.user_id
 
        if request.POST.get('del_api_key_builtin'):
 
            user = User.get(user_id)
 
            if user:
 
            if user is not None:
 
                user.api_key = generate_api_key()
 
                Session().add(user)
 
                Session().commit()
kallithea/controllers/admin/notifications.py
Show inline comments
 
@@ -160,7 +160,7 @@ class NotificationsController(BaseContro
 

	
 
            # if this association to user is not valid, we don't want to show
 
            # this message
 
            if unotification:
 
            if unotification is not None:
 
                if not unotification.read:
 
                    unotification.mark_as_read()
 
                    Session().commit()
kallithea/controllers/admin/repos.py
Show inline comments
 
@@ -217,7 +217,7 @@ class ReposController(BaseRepoController
 
                                     h.url('summary_home',
 
                                           repo_name=repo.repo_name))
 
                fork = repo.fork
 
                if fork:
 
                if fork is not None:
 
                    fork_name = fork.repo_name
 
                    h.flash(h.literal(_('Forked repository %s as %s')
 
                            % (fork_name, repo_url)), category='success')
kallithea/controllers/admin/users.py
Show inline comments
 
@@ -316,7 +316,7 @@ class UsersController(BaseController):
 
        api_key = request.POST.get('del_api_key')
 
        if request.POST.get('del_api_key_builtin'):
 
            user = User.get(c.user.user_id)
 
            if user:
 
            if user is not None:
 
                user.api_key = generate_api_key()
 
                Session().add(user)
 
                Session().commit()
kallithea/controllers/api/api.py
Show inline comments
 
@@ -463,7 +463,7 @@ class ApiController(JSONRPCController):
 
            if time_:
 
                _api_data = r.get_api_data()
 
                # if we use userfilter just show the locks for this user
 
                if user:
 
                if user is not None:
 
                    if safe_int(userid) == user.user_id:
 
                        ret.append(_api_data)
 
                else:
kallithea/controllers/changeset.py
Show inline comments
 
@@ -398,7 +398,7 @@ class ChangesetController(BaseRepoContro
 
        data = {
 
           'target_id': h.safeid(h.safe_unicode(request.POST.get('f_path'))),
 
        }
 
        if comment:
 
        if comment is not None:
 
            data.update(comment.get_dict())
 
            data.update({'rendered_text':
 
                         render('changeset/changeset_comment_block.html')})
kallithea/controllers/pullrequests.py
Show inline comments
 
@@ -751,7 +751,7 @@ class PullrequestsController(BaseRepoCon
 
        data = {
 
           'target_id': h.safeid(h.safe_unicode(request.POST.get('f_path'))),
 
        }
 
        if comment:
 
        if comment is not None:
 
            c.comment = comment
 
            data.update(comment.get_dict())
 
            data.update({'rendered_text':
kallithea/model/__init__.py
Show inline comments
 
@@ -94,7 +94,7 @@ class BaseModel(object):
 
        elif isinstance(instance, (int, long)) or safe_str(instance).isdigit():
 
            return cls.get(instance)
 
        else:
 
            if instance:
 
            if instance is not None:
 
                if callback is None:
 
                    raise Exception(
 
                        'given object must be int, long or Instance of %s '
kallithea/model/api_key.py
Show inline comments
 
@@ -65,7 +65,7 @@ class ApiKeyModel(BaseModel):
 
        """
 
        api_key = UserApiKeys.query().filter(UserApiKeys.api_key == api_key)
 

	
 
        if user:
 
        if user is not None:
 
            user = self._get_user(user)
 
            api_key = api_key.filter(UserApiKeys.user_id == user.user_id)
 

	
kallithea/model/comment.py
Show inline comments
 
@@ -181,9 +181,9 @@ class ChangesetCommentsModel(BaseModel):
 
        comment.f_path = f_path
 
        comment.line_no = line_no
 

	
 
        if revision:
 
        if revision is not None:
 
            comment.revision = revision
 
        elif pull_request:
 
        elif pull_request is not None:
 
            pull_request = self.__get_pull_request(pull_request)
 
            comment.pull_request = pull_request
 
        else:
kallithea/model/db.py
Show inline comments
 
@@ -130,7 +130,7 @@ class BaseModel(object):
 
            raise HTTPNotFound
 

	
 
        res = cls.query().get(id_)
 
        if not res:
 
        if res is None:
 
            raise HTTPNotFound
 
        return res
 

	
 
@@ -232,7 +232,7 @@ class Setting(Base, BaseModel):
 
    @classmethod
 
    def get_by_name_or_create(cls, key, val='', type='unicode'):
 
        res = cls.get_by_name(key)
 
        if not res:
 
        if res is None:
 
            res = cls(key, val, type)
 
        return res
 

	
 
@@ -248,7 +248,7 @@ class Setting(Base, BaseModel):
 
        :return:
 
        """
 
        res = cls.get_by_name(key)
 
        if not res:
 
        if res is None:
 
            val = Optional.extract(val)
 
            type = Optional.extract(type)
 
            res = cls(key, val, type)
 
@@ -270,7 +270,7 @@ class Setting(Base, BaseModel):
 
        if cache:
 
            ret = ret.options(FromCache("sql_cache_short", "get_hg_settings"))
 

	
 
        if not ret:
 
        if ret is None:
 
            raise Exception('Could not get application settings !')
 
        settings = {}
 
        for each in ret:
 
@@ -624,12 +624,12 @@ class User(Base, BaseModel):
 
        _email = email(author)
 
        if _email:
 
            user = cls.get_by_email(_email, case_insensitive=True)
 
            if user:
 
            if user is not None:
 
                return user
 
        # Maybe we can match by username?
 
        _author = author_name(author)
 
        user = cls.get_by_username(_author, case_insensitive=True)
 
        if user:
 
        if user is not None:
 
            return user
 

	
 
    def update_lastlogin(self):
 
@@ -2488,7 +2488,7 @@ class Gist(Base, BaseModel):
 
    @classmethod
 
    def get_or_404(cls, id_):
 
        res = cls.query().filter(cls.gist_access_id == id_).scalar()
 
        if not res:
 
        if res is None:
 
            raise HTTPNotFound
 
        return res
 

	
kallithea/model/notification.py
Show inline comments
 
@@ -53,7 +53,7 @@ class NotificationModel(BaseModel):
 
        elif isinstance(notification, (int, long)):
 
            return Notification.get(notification)
 
        else:
 
            if notification:
 
            if notification is not None:
 
                raise Exception('notification must be int, long or Instance'
 
                                ' of Notification got %s' % type(notification))
 

	
 
@@ -85,7 +85,7 @@ class NotificationModel(BaseModel):
 
        if recipients:
 
            for u in recipients:
 
                obj = self._get_user(u)
 
                if obj:
 
                if obj is not None:
 
                    recipients_objs.append(obj)
 
                else:
 
                    # TODO: inform user that requested operation couldn't be completed
kallithea/model/repo.py
Show inline comments
 
@@ -535,7 +535,7 @@ class RepoModel(BaseModel):
 
        if not cur_user:
 
            cur_user = getattr(get_current_authuser(), 'username', None)
 
        repo = self._get_repo(repo)
 
        if repo:
 
        if repo is not None:
 
            if forks == 'detach':
 
                for r in repo.forks:
 
                    r.fork = None
 
@@ -602,7 +602,7 @@ class RepoModel(BaseModel):
 
            .filter(UserRepoToPerm.repository == repo) \
 
            .filter(UserRepoToPerm.user == user) \
 
            .scalar()
 
        if obj:
 
        if obj is not None:
 
            self.sa.delete(obj)
 
            log.debug('Revoked perm on %s on %s' % (repo, user))
 

	
 
@@ -652,7 +652,7 @@ class RepoModel(BaseModel):
 
            .filter(UserGroupRepoToPerm.repository == repo) \
 
            .filter(UserGroupRepoToPerm.users_group == group_name) \
 
            .scalar()
 
        if obj:
 
        if obj is not None:
 
            self.sa.delete(obj)
 
            log.debug('Revoked perm to %s on %s' % (repo, group_name))
 

	
 
@@ -666,7 +666,7 @@ class RepoModel(BaseModel):
 
        try:
 
            obj = self.sa.query(Statistics) \
 
                .filter(Statistics.repository == repo).scalar()
 
            if obj:
 
            if obj is not None:
 
                self.sa.delete(obj)
 
        except Exception:
 
            log.error(traceback.format_exc())
kallithea/model/repo_group.py
Show inline comments
 
@@ -485,7 +485,7 @@ class RepoGroupModel(BaseModel):
 
            .filter(UserRepoGroupToPerm.user == user)\
 
            .filter(UserRepoGroupToPerm.group == repo_group)\
 
            .scalar()
 
        if obj:
 
        if obj is not None:
 
            self.sa.delete(obj)
 
            log.debug('Revoked perm on %s on %s' % (repo_group, user))
 

	
 
@@ -537,6 +537,6 @@ class RepoGroupModel(BaseModel):
 
            .filter(UserGroupRepoGroupToPerm.group == repo_group)\
 
            .filter(UserGroupRepoGroupToPerm.users_group == group_name)\
 
            .scalar()
 
        if obj:
 
        if obj is not None:
 
            self.sa.delete(obj)
 
            log.debug('Revoked perm to %s on %s' % (repo_group, group_name))
kallithea/model/scm.py
Show inline comments
 
@@ -247,7 +247,7 @@ class ScmModel(BaseModel):
 
            return cls.get(instance)
 
        elif isinstance(instance, basestring):
 
            return cls.get_by_repo_name(instance)
 
        elif instance:
 
        elif instance is not None:
 
            raise Exception('given object must be int, basestr or Instance'
 
                            ' of %s got %s' % (type(cls), type(instance)))
 

	
 
@@ -340,7 +340,7 @@ class ScmModel(BaseModel):
 
        """
 
        CacheInvalidation.set_invalidate(repo_name, delete=delete)
 
        repo = Repository.get_by_repo_name(repo_name)
 
        if repo:
 
        if repo is not None:
 
            repo.update_changeset_cache()
 

	
 
    def toggle_following_repo(self, follow_repo_id, user_id):
 
@@ -807,7 +807,7 @@ class ScmModel(BaseModel):
 
        repo = self.__get_repo(repo)
 
        hist_l.append(['rev:tip', _('latest tip')])
 
        choices.append('rev:tip')
 
        if not repo:
 
        if repo is None:
 
            return choices, hist_l
 

	
 
        repo = repo.scm_instance
kallithea/model/user.py
Show inline comments
 
@@ -249,7 +249,7 @@ class UserModel(BaseModel):
 
        return user
 

	
 
    def delete(self, user, cur_user=None):
 
        if not cur_user:
 
        if cur_user is None:
 
            cur_user = getattr(get_current_authuser(), 'username', None)
 
        user = self._get_user(user)
 

	
 
@@ -287,7 +287,7 @@ class UserModel(BaseModel):
 

	
 
        user_email = data['email']
 
        user = User.get_by_email(user_email)
 
        if user:
 
        if user is not None:
 
            log.debug('password reset user found %s' % user)
 
            link = h.canonical_url('reset_password_confirmation',
 
                                   key=user.api_key)
 
@@ -316,7 +316,7 @@ class UserModel(BaseModel):
 
        user = User.get_by_email(user_email)
 
        new_passwd = auth.PasswordGenerator().gen_password(
 
            8, auth.PasswordGenerator.ALPHABETS_BIG_SMALL)
 
        if user:
 
        if user is not None:
 
            user.password = auth.get_crypt_password(new_passwd)
 
            Session().add(user)
 
            Session().commit()
 
@@ -433,7 +433,7 @@ class UserModel(BaseModel):
 
        """
 
        user = self._get_user(user)
 
        obj = UserEmailMap.query().get(email_id)
 
        if obj:
 
        if obj is not None:
 
            self.sa.delete(obj)
 

	
 
    def add_extra_ip(self, user, ip):
kallithea/model/user_group.py
Show inline comments
 
@@ -253,7 +253,7 @@ class UserGroupModel(BaseModel):
 
        obj = UserGroupToPerm.query()\
 
            .filter(UserGroupToPerm.users_group == user_group)\
 
            .filter(UserGroupToPerm.permission == perm).scalar()
 
        if obj:
 
        if obj is not None:
 
            self.sa.delete(obj)
 

	
 
    def grant_user_permission(self, user_group, user, perm):
 
@@ -302,7 +302,7 @@ class UserGroupModel(BaseModel):
 
            .filter(UserUserGroupToPerm.user == user)\
 
            .filter(UserUserGroupToPerm.user_group == user_group)\
 
            .scalar()
 
        if obj:
 
        if obj is not None:
 
            self.sa.delete(obj)
 
            log.debug('Revoked perm on %s on %s' % (user_group, user))
 

	
 
@@ -351,7 +351,7 @@ class UserGroupModel(BaseModel):
 
            .filter(UserGroupUserGroupToPerm.target_user_group == target_user_group)\
 
            .filter(UserGroupUserGroupToPerm.user_group == user_group)\
 
            .scalar()
 
        if obj:
 
        if obj is not None:
 
            self.sa.delete(obj)
 
            log.debug('Revoked perm on %s on %s' % (target_user_group, user_group))
 

	
kallithea/model/validators.py
Show inline comments
 
@@ -228,7 +228,7 @@ def ValidRepoGroup(edit=False, old_data=
 
                      .filter(RepoGroup.group_parent_id == group_parent_id)\
 
                      .scalar()
 

	
 
                if gr:
 
                if gr is not None:
 
                    msg = M(self, 'group_exists', state, group_name=slug)
 
                    raise formencode.Invalid(msg, value, state,
 
                            error_dict=dict(group_name=msg)
 
@@ -239,7 +239,7 @@ def ValidRepoGroup(edit=False, old_data=
 
                      .filter(Repository.repo_name == slug)\
 
                      .scalar()
 

	
 
                if repo:
 
                if repo is not None:
 
                    msg = M(self, 'repo_exists', state, group_name=slug)
 
                    raise formencode.Invalid(msg, value, state,
 
                            error_dict=dict(group_name=msg)
 
@@ -715,7 +715,7 @@ def UniqSystemEmail(old_data={}):
 
        def validate_python(self, value, state):
 
            if (old_data.get('email') or '').lower() != value:
 
                user = User.get_by_email(value, case_insensitive=True)
 
                if user:
 
                if user is not None:
 
                    msg = M(self, 'email_taken', state)
 
                    raise formencode.Invalid(msg, value, state,
 
                        error_dict=dict(email=msg)
0 comments (0 inline, 0 general)