def _check_single_ip(self, ip):
     ip = ip2int(ip)
     if self.deny:
         for ip_mask in self.deny:
             if ip in ip_mask:
                 return False
     if self.allow:
         for ip_mask in self.allow:
             if ip in ip_mask:
                 return True
     return False
 def __call__(self, environ, start_response):
     addr = ip4.ip2int(environ['REMOTE_ADDR'], False)
     remove_user = False
     add_roles = []
     for range, (username, roles) in self.ip_map:
         if addr in range:
             if roles:
                 add_roles.extend(roles)
             if username == '__remove__':
                 remove_user = True
             elif username:
                 if (not environ.get('REMOTE_USER')
                     or self.clobber_username):
                     environ['REMOTE_USER'] = username
     if (remove_user and 'REMOTE_USER' in environ):
         del environ['REMOTE_USER']
     if roles:
         self._set_roles(environ, add_roles)
     return self.app(environ, start_response)