comparison rhodecode/lib/middleware/simplehg.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 238486bb71ab
children 10b4e34841a4
comparison
equal deleted inserted replaced
3624:4dddb7ee8865 3625:260a7a01b054
87 log.debug('Extracted repo name is %s' % repo_name) 87 log.debug('Extracted repo name is %s' % repo_name)
88 except: 88 except:
89 return HTTPInternalServerError()(environ, start_response) 89 return HTTPInternalServerError()(environ, start_response)
90 90
91 # quick check if that dir exists... 91 # quick check if that dir exists...
92 if is_valid_repo(repo_name, self.basepath, 'hg') is False: 92 if not is_valid_repo(repo_name, self.basepath, 'hg'):
93 return HTTPNotFound()(environ, start_response) 93 return HTTPNotFound()(environ, start_response)
94 94
95 #====================================================================== 95 #======================================================================
96 # GET ACTION PULL or PUSH 96 # GET ACTION PULL or PUSH
97 #====================================================================== 97 #======================================================================
104 anonymous_user = self.__get_user('default') 104 anonymous_user = self.__get_user('default')
105 username = anonymous_user.username 105 username = anonymous_user.username
106 anonymous_perm = self._check_permission(action, anonymous_user, 106 anonymous_perm = self._check_permission(action, anonymous_user,
107 repo_name, ip_addr) 107 repo_name, ip_addr)
108 108
109 if anonymous_perm is not True or anonymous_user.active is False: 109 if not anonymous_perm or not anonymous_user.active:
110 if anonymous_perm is not True: 110 if not anonymous_perm:
111 log.debug('Not enough credentials to access this ' 111 log.debug('Not enough credentials to access this '
112 'repository as anonymous user') 112 'repository as anonymous user')
113 if anonymous_user.active is False: 113 if not anonymous_user.active:
114 log.debug('Anonymous access is disabled, running ' 114 log.debug('Anonymous access is disabled, running '
115 'authentication') 115 'authentication')
116 #============================================================== 116 #==============================================================
117 # DEFAULT PERM FAILED OR ANONYMOUS ACCESS IS DISABLED SO WE 117 # DEFAULT PERM FAILED OR ANONYMOUS ACCESS IS DISABLED SO WE
118 # NEED TO AUTHENTICATE AND ASK FOR AUTH USER PERMISSIONS 118 # NEED TO AUTHENTICATE AND ASK FOR AUTH USER PERMISSIONS
145 log.error(traceback.format_exc()) 145 log.error(traceback.format_exc())
146 return HTTPInternalServerError()(environ, start_response) 146 return HTTPInternalServerError()(environ, start_response)
147 147
148 #check permissions for this repository 148 #check permissions for this repository
149 perm = self._check_permission(action, user, repo_name, ip_addr) 149 perm = self._check_permission(action, user, repo_name, ip_addr)
150 if perm is not True: 150 if not perm:
151 return HTTPForbidden()(environ, start_response) 151 return HTTPForbidden()(environ, start_response)
152 152
153 # extras are injected into mercurial UI object and later available 153 # extras are injected into mercurial UI object and later available
154 # in hg hooks executed by rhodecode 154 # in hg hooks executed by rhodecode
155 from rhodecode import CONFIG 155 from rhodecode import CONFIG