Commits

Andriy Kornatskyy  committed c28625a

Refactoring with respect to recent changes in http package

  • Participants
  • Parent commits 5df1e95

Comments (0)

Files changed (8)

File demos/hello/helloworld.py

 class WelcomeHandler(BaseHandler):
 
     def get(self):
-        response = HTTPResponse(options=self.request.config)
+        response = HTTPResponse()
         response.write('Hello World! It is %s.'
                 % datetime.now().time().strftime('%H:%M:%S'))
         return response
 
     @handler_cache(profile=public_cache_profile, cache=cache)
     def get(self):
-        response = HTTPResponse(options=self.request.config)
+        response = HTTPResponse()
         response.write('Hello World! It is %s.'
                 % datetime.now().time().strftime('%H:%M:%S'))
         return response
 
 
 def now(request):
-    response = HTTPResponse(options=request.config)
+    response = HTTPResponse()
     response.write('It is %s.'
                 % datetime.now().time().strftime('%H:%M:%S'))
     return response
 
 @response_cache(profile=public_cache_profile, cache=cache)
 def now2(request):
-    response = HTTPResponse(options=request.config)
+    response = HTTPResponse()
     response.write('It is %s.'
                 % datetime.now().time().strftime('%H:%M:%S'))
     return response
         url('now2', now2)
 ]
 
+options = {}
 main = WSGIApplication(
         middleware=[
             bootstrap_defaults(url_mapping=all_urls),
             path_routing_middleware_factory
-        ]
+        ],
+        options=options
 )
 
 

File demos/public/Makefile

 
 benchmark:
 	$(NOSE) -qs -m benchmark src/
+
+profile:
+	$(NOSE) -qs -m benchmark --with-profile \
+		--profile-stats-file=public.pstats src/membership
+
+gropf:
+	gprof2dot.py -f pstats public.pstats | dot -Tpng -o public.png

File demos/public/src/error/web/views.py

 
 
 def test_bad_request(request):
-    return bad_request(request.config)
+    return bad_request()
 
 
 def test_forbidden(request):
-    return forbidden(request.config)
+    return forbidden()
 
 
 def test_not_found(request):
-    return not_found(request.config)
+    return not_found()
 
 
 def test_internal_error(request):

File src/wheezy/web/authorization.py

                         if role in principal_roles:
                             break
                     else:
-                        return unauthorized(handler.options)
+                        return unauthorized()
                     return func(handler, *args, **kwargs)
                 else:
-                    return unauthorized(handler.options)
+                    return unauthorized()
             return check_roles
         else:
             def check_authenticated(handler, *args, **kwargs):
                 if handler.principal:
                     return func(handler, *args, **kwargs)
                 else:
-                    return unauthorized(handler.options)
+                    return unauthorized()
             return check_authenticated
     if wrapped is None:
         return decorate

File src/wheezy/web/handlers/base.py

     def redirect_for(self, name, **kwargs):
         return redirect(
                 self.absolute_url_for(name, **kwargs),
-                permanent=False,
-                options=self.options)
+                permanent=False)
 
     # region: i18n
 
     def render_template(self, template_name, **kwargs):
         if kwargs:
             errors = self.errors
-            kwargs = dict((name, widget(value, errors))
-                    for name, value in iteritems(kwargs))
+            kwargs = dict([(name, widget(kwargs[name], errors))
+                    for name in kwargs])
         kwargs.update(self.helpers)
         return self.options['render_template'](template_name, **kwargs)
 
     def render_response(self, template_name, **kwargs):
-        response = HTTPResponse(options=self.options)
+        options = self.options
+        response = HTTPResponse(options['CONTENT_TYPE'], options['ENCODING'])
         response.write(self.render_template(
             template_name,
             **kwargs))
         if hasattr(self, '_BaseHandler__principal'):
             return self.__principal
         principal = None
-        try:
-            options = self.options
+        auth_cookie = self.request.cookies.get(
+                self.options['AUTH_COOKIE'], None)
+        if auth_cookie is not None:
             auth_ticket = self.ticket
             ticket, time_left = auth_ticket.decode(
-                self.request.cookies[options['AUTH_COOKIE']]
+                    auth_cookie
             )
             if ticket:
                 principal = Principal.load(ticket)
                     return principal
             else:
                 self.delprincipal()
-        except KeyError:  # No auth cookie
-            pass
         self.__principal = principal
         return principal
 
     def setprincipal(self, principal):
         options = self.options
-        auth_ticket = self.ticket
         self.cookies.append(HTTPCookie(
             options['AUTH_COOKIE'],
-            value=auth_ticket.encode(principal.dump()),
+            value=self.ticket.encode(principal.dump()),
             path=self.request.root_path + options['AUTH_COOKIE_PATH'],
             domain=options['AUTH_COOKIE_DOMAIN'],
             secure=options['AUTH_COOKIE_SECURE'],

File src/wheezy/web/handlers/file.py

         request = self.request
         response = HTTPResponse(
                 content_type=mime_type or 'plain/text',
-                encoding=encoding,
-                options=request.config)
+                encoding=encoding)
 
         response.cache = cache_policy = HTTPCachePolicy('public')
 

File src/wheezy/web/handlers/method.py

         return handler()
 
     def __init__(self, request):
-        self.options = request.config.options
+        self.options = request.options
         self.request = request
         self.route_args = request.environ['route_args']
         self.cookies = []
         elif method == 'HEAD':
             response = self.head()
         else:
-            response = method_not_allowed(self.request.config)
+            response = method_not_allowed()
         if self.cookies:
             response.cookies.extend(self.cookies)
         return response
     def head(self):
         """ Responds to HTTP HEAD requests.
         """
-        return method_not_allowed(self.request.config)
+        return method_not_allowed()
 
     def get(self):
         """ Responds to HTTP GET requests.
         """
-        return method_not_allowed(self.request.config)
+        return method_not_allowed()
 
     def post(self):
         """ Responds to HTTP POST requests.
         """
-        return method_not_allowed(self.request.config)
+        return method_not_allowed()

File src/wheezy/web/middleware/__init__.py

 
 from wheezy.core.collections import defaultdict
 from wheezy.core.i18n import TranslationsManager
+from wheezy.http.config import bootstrap_http_defaults
 from wheezy.routing import PathRouter
 from wheezy.security.crypto import Ticket
 from wheezy.web.middleware.errors import HTTPErrorMiddleware
     """ Defaults bootstrap.
     """
     def load(options):
+        bootstrap_http_defaults(options)
         if 'path_router' not in options:
             options['path_router'] = path_router = PathRouter()
         else: