Mercurial > kallithea
comparison rhodecode/lib/middleware/simplegit.py @ 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'.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Thu, 28 Mar 2013 01:10:45 +0100 |
parents | 11feddcd75bb |
children | 10b4e34841a4 |
comparison
equal
deleted
inserted
replaced
3624:4dddb7ee8865 | 3625:260a7a01b054 |
---|---|
124 log.debug('Extracted repo name is %s' % repo_name) | 124 log.debug('Extracted repo name is %s' % repo_name) |
125 except: | 125 except: |
126 return HTTPInternalServerError()(environ, start_response) | 126 return HTTPInternalServerError()(environ, start_response) |
127 | 127 |
128 # quick check if that dir exists... | 128 # quick check if that dir exists... |
129 if is_valid_repo(repo_name, self.basepath, 'git') is False: | 129 if not is_valid_repo(repo_name, self.basepath, 'git'): |
130 return HTTPNotFound()(environ, start_response) | 130 return HTTPNotFound()(environ, start_response) |
131 | 131 |
132 #====================================================================== | 132 #====================================================================== |
133 # GET ACTION PULL or PUSH | 133 # GET ACTION PULL or PUSH |
134 #====================================================================== | 134 #====================================================================== |
141 anonymous_user = self.__get_user('default') | 141 anonymous_user = self.__get_user('default') |
142 username = anonymous_user.username | 142 username = anonymous_user.username |
143 anonymous_perm = self._check_permission(action, anonymous_user, | 143 anonymous_perm = self._check_permission(action, anonymous_user, |
144 repo_name, ip_addr) | 144 repo_name, ip_addr) |
145 | 145 |
146 if anonymous_perm is not True or anonymous_user.active is False: | 146 if not anonymous_perm or not anonymous_user.active: |
147 if anonymous_perm is not True: | 147 if not anonymous_perm: |
148 log.debug('Not enough credentials to access this ' | 148 log.debug('Not enough credentials to access this ' |
149 'repository as anonymous user') | 149 'repository as anonymous user') |
150 if anonymous_user.active is False: | 150 if not anonymous_user.active: |
151 log.debug('Anonymous access is disabled, running ' | 151 log.debug('Anonymous access is disabled, running ' |
152 'authentication') | 152 'authentication') |
153 #============================================================== | 153 #============================================================== |
154 # DEFAULT PERM FAILED OR ANONYMOUS ACCESS IS DISABLED SO WE | 154 # DEFAULT PERM FAILED OR ANONYMOUS ACCESS IS DISABLED SO WE |
155 # NEED TO AUTHENTICATE AND ASK FOR AUTH USER PERMISSIONS | 155 # NEED TO AUTHENTICATE AND ASK FOR AUTH USER PERMISSIONS |
182 log.error(traceback.format_exc()) | 182 log.error(traceback.format_exc()) |
183 return HTTPInternalServerError()(environ, start_response) | 183 return HTTPInternalServerError()(environ, start_response) |
184 | 184 |
185 #check permissions for this repository | 185 #check permissions for this repository |
186 perm = self._check_permission(action, user, repo_name, ip_addr) | 186 perm = self._check_permission(action, user, repo_name, ip_addr) |
187 if perm is not True: | 187 if not perm: |
188 return HTTPForbidden()(environ, start_response) | 188 return HTTPForbidden()(environ, start_response) |
189 | 189 |
190 # extras are injected into UI object and later available | 190 # extras are injected into UI object and later available |
191 # in hooks executed by rhodecode | 191 # in hooks executed by rhodecode |
192 from rhodecode import CONFIG | 192 from rhodecode import CONFIG |