예제 #1
0
    def __call__(self, environ, start_response):
        old_cookie = environ.get('HTTP_COOKIE', 'nothing')

        domain = environ['PATH_INFO'].split("/")[1][0]

        if construct_url(environ).endswith('/index.html') :
            return self.app(environ, start_response)

        status, headers, body = intercept_output(environ, self.app)
        headers.append(('Set-Cookie', 'name=%s' % domain))

        start_response('200 OK', headers)
        return ["<html><head></head><body>Had %s. Setting cookie from %s</body></html>" % (old_cookie, domain)]
예제 #2
0
    def __call__(self, environ, start_response):
        if environ['PATH_INFO'].strip("/").startswith("_debug"):
            return self.app(environ, start_response)
        
	username = ''
        environ['topp.user_info'] = dict(username = '', roles = ['Anonymous'], email = '*****@*****.**')
	try:
	    authenticated = self.authenticate(environ)
        except BadCookieError:
            status = "401 Unauthorized"
            start_response(status, [])
            return ["Please delete your brower's cookies and login again."]

        if authenticated:
            username = environ.get('REMOTE_USER', '').lower()

        if 'topp.project_name' in environ:
            project_name = environ['topp.project_name']

            environ['topp.project_members'] = umapper = UserMapper(environ, project_name,
                                                                   self.openplans_instance,
                                                                   self.admin_info, self.profile_uri)
            if username in umapper.project_member_names():
                environ['topp.user_info']['roles'].extend(umapper.project_member_roles(username))

            try:
                info = get_info_for_project(project_name, self.openplans_instance, self.admin_info)
                environ['topp.project_permission_level'] = info['policy']
                environ['topp.app_installed'] = info['installed']
            except ProjectNotFoundError: #assume the most restrictive
                environ['topp.project_permission_level'] = dict(policy='closed_policy')
                environ['topp.app_installed'] = True # this should prob be false, but i don't want to change behavior

        status, headers, body = intercept_output(environ, self.app, self.needs_redirection, start_response)

        if status:
            if status.startswith('401'):
                status = "303 See Other"
                url = construct_url(environ)
                headers = [('Location', '%s?came_from=%s' % (self.login_uri, quote(url)))]
                start_response(status, headers)
                return []
            elif status.startswith('403'):
                status = "303 See Other"
                url = construct_url(environ)
                headers = [('Location', '%s?portal_status_message=You+have+insufficient+privileges.' % self.homepage_uri)]
                start_response(status, headers)
            return []        
        else:
            return body
예제 #3
0
 def __call__(self, environ, start_response):
     status, headers, body = intercept_output(environ, self.app, start_response=start_response)
     for item in headers:
         if item[0] == 'X-Content-Length':
             headers.append(('Content-Length', str(item[1]) ))
             headers.remove(item)
         if item[0] == 'X-Content-Type':
             for entry in headers:
                 if entry[0] == 'Content-Type':
                     headers.remove(entry)
             headers.append(('Content-Type', str(item[1]) ))
             headers.remove(item)
     start_response(status, headers)
     return [body]
예제 #4
0
 def __call__(self, environ, start_response):
     global _threadedprint_installed
     if environ.get('paste.testing'):
         # In a testing environment this interception isn't
         # useful:
         return self.app(environ, start_response)
     if (not _threadedprint_installed
         or self._threaded_print_stdout is not sys.stdout):
         # @@: Not strictly threadsafe
         _threadedprint_installed = True
         threadedprint.install(leave_stdout=not self.replace_stdout)
         self._threaded_print_stdout = sys.stdout
     removed = []
     def remove_printdebug():
         removed.append(None)
     environ['paste.remove_printdebug'] = remove_printdebug
     logged = StringIO()
     listeners = [logged]
     environ['paste.printdebug_listeners'] = listeners
     if self.print_wsgi_errors:
         listeners.append(environ['wsgi.errors'])
     replacement_stdout = TeeFile(listeners)
     threadedprint.register(replacement_stdout)
     try:
         status, headers, body = wsgilib.intercept_output(
             environ, self.app)
         if status is None:
             # Some error occurred
             status = '500 Server Error'
             headers = [('Content-type', 'text/html')]
             start_response(status, headers)
             if not body:
                 body = 'An error occurred'
         content_type = response.header_value(headers, 'content-type')
         if (removed or
             (not self.force_content_type and
              (not content_type
               or not content_type.startswith('text/html')))):
             if replacement_stdout == logged:
                 # Then the prints will be lost, unless...
                 environ['wsgi.errors'].write(logged.getvalue())
             start_response(status, headers)
             return [body]
         response.remove_header(headers, 'content-length')
         body = self.add_log(body, logged.getvalue())
         start_response(status, headers)
         return [body]
     finally:
         threadedprint.deregister()
예제 #5
0
    def __call__(self, environ, start_response):

        path = environ['PATH_INFO']

        if not path:
            path = environ['PATH_INFO'] = '/'

        status, headers, body = intercept_output(environ, self.app,
                                                 self.should_intercept,
                                                 start_response)

        # self.should_intercept returned nada
        if status is None:
            return body

        # don't style if the url should not be styled
        for pattern in self.ignore_paths:
            if pattern.match(path):
                start_response(status, headers)
                return [body]

        # short circuit from theming if this is not likely to be HTML
        content_url = construct_url(environ)
        if self.should_ignore_url(content_url):
            start_response(status, headers)
            return [body]

        # short circuit if we have a 3xx, 204 or 401 error code
        status_code = status.split()[0]
        if status_code.startswith(
                '3') or status_code == '204' or status_code == '401':
            start_response(status, headers)
            return [body]

        # all good - apply the transform
        body = self.apply_transform(environ, body)

        replace_header(headers, 'content-length', str(len(body)))
        replace_header(headers, 'content-type', 'text/html; charset=utf-8')

        start_response(status, headers)
        return [body]
예제 #6
0
 def __call__(self, environ, start_response):
     
     path = environ['PATH_INFO']
     
     if not path:
         path = environ['PATH_INFO'] = '/'
     
     status, headers, body = intercept_output(environ, self.app,
                                              self.should_intercept,
                                              start_response)
                                              
     # self.should_intercept returned nada
     if status is None:
         return body
     
     # don't style if the url should not be styled
     for pattern in self.ignore_paths:
         if pattern.match(path):
             start_response(status, headers)
             return [body]
     
     # short circuit from theming if this is not likely to be HTML
     content_url = construct_url(environ)
     if self.should_ignore_url(content_url):
         start_response(status, headers)
         return [body]
         
     # short circuit if we have a 3xx, 204 or 401 error code
     status_code = status.split()[0]
     if status_code.startswith('3') or status_code == '204' or status_code == '401':
         start_response(status, headers)
         return [body]
     
     # all good - apply the transform
     body = self.apply_transform(environ, body)
     
     replace_header(headers, 'content-length', str(len(body)))
     replace_header(headers, 'content-type', 'text/html; charset=utf-8')
     
     start_response(status, headers)
     return [body]