Andriy Kornatskyy avatar Andriy Kornatskyy committed 47e2d7b

Applied few minor optimizations

Comments (0)

Files changed (4)

demos/public/src/membership/models.py

 
 
 class Credential(object):
-
-    def __init__(self):
-        self.username = u('')
-        self.password = u('')
+    username = u('')
+    password = u('')
 
 
 class Account(object):
-
-    def __init__(self):
-        self.email = u('')
-        self.display_name = u('')
-        self.account_type = 'user'
+    email = u('')
+    display_name = u('')
+    account_type = 'user'
 
 
 class Registration(object):
+    questionid = 0
+    answer = u('')
+    date_of_birth = date.min
 
     def __init__(self):
         self.credential = Credential()
         self.account = Account()
-        self.questionid = 0
-        self.answer = u('')
-        self.date_of_birth = date.min

src/wheezy/web/handlers/base.py

     def path_for(self, name, **kwargs):
         route_args = dict(self.route_args)
         route_args.update(kwargs)
-        return self.request.root_path + self.options['path_router'].path_for(
+        return self.request.root_path + self.options['path_for'](
                 name, **route_args)
 
     def absolute_url_for(self, name, **kwargs):

src/wheezy/web/middleware/__init__.py

             options['path_router'] = path_router = PathRouter()
         else:
             path_router = options['path_router']
+        if 'path_for' not in options:
+            options['path_for'] = path_router.path_for
         if url_mapping:
             path_router.add_routes(url_mapping)
         if 'render_template' not in options:
 def http_error_middleware_factory(options):
     """ HTTP error middleware factory.
     """
-    path_router = options['path_router']
+    path_for = options['path_for']
     try:
         error_mapping = options['http_errors']
         assert isinstance(error_mapping, defaultdict)
-        assert path_router.path_for(error_mapping.default_factory())
+        assert path_for(error_mapping.default_factory())
         for route_name in error_mapping.values():
-            assert path_router.path_for(route_name)
+            assert path_for(route_name)
     except KeyError:
         error_mapping = defaultdict(str)
     return HTTPErrorMiddleware(

src/wheezy/web/middleware/routing.py

 """
 
 from wheezy.core.collections import defaultattrdict
-from wheezy.core.collections import defaultdict
 
 
 class PathRoutingMiddleware(object):
 
     def __init__(self, path_router):
         assert path_router
-        self.path_router = path_router
+        self.match = path_router.match
 
     def __call__(self, request, following):
         environ = request.environ
-        handler, route_args = self.path_router.match(
-                environ['PATH_INFO'].lstrip('/'))
+        handler, route_args = self.match(environ['PATH_INFO'].lstrip('/'))
         environ['route_args'] = defaultattrdict(str, route_args)
         if handler is None:
             if following is not None:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.