Esempio n. 1
0
 def map_nonclass(self, view):
     # We do more work here than appears necessary to avoid wrapping the
     # view unless it actually requires wrapping (to avoid function call
     # overhead).
     mapped_view = view
     ronly = requestonly(view, self.attr)
     if ronly:
         mapped_view = self.map_nonclass_requestonly(view)
     elif self.attr:
         mapped_view = self.map_nonclass_attr(view)
     if inspect.isroutine(mapped_view):
         # This branch will be true if the view is a function or a method.
         # We potentially mutate an unwrapped object here if it's a
         # function.  We do this to avoid function call overhead of
         # injecting another wrapper.  However, we must wrap if the
         # function is a bound method because we can't set attributes on a
         # bound method.
         if is_bound_method(view):
             _mapped_view = mapped_view
             def mapped_view(context, request):
                 return _mapped_view(context, request)
         if self.attr is not None:
             mapped_view.__text__ = 'attr %s of %s' % (
                 self.attr, object_description(view))
         else:
             mapped_view.__text__ = object_description(view)
     return mapped_view
Esempio n. 2
0
    def map_nonclass(self, view):
        # We do more work here than appears necessary to avoid wrapping the
        # view unless it actually requires wrapping (to avoid function call
        # overhead).
        mapped_view = view
        ronly = requestonly(view, self.attr)
        if ronly:
            mapped_view = self.map_nonclass_requestonly(view)
        elif self.attr:
            mapped_view = self.map_nonclass_attr(view)
        if inspect.isroutine(mapped_view):
            # This branch will be true if the view is a function or a method.
            # We potentially mutate an unwrapped object here if it's a
            # function.  We do this to avoid function call overhead of
            # injecting another wrapper.  However, we must wrap if the
            # function is a bound method because we can't set attributes on a
            # bound method.
            if is_bound_method(view):
                _mapped_view = mapped_view

                def mapped_view(context, request):
                    return _mapped_view(context, request)

            if self.attr is not None:
                mapped_view.__text__ = 'attr %s of %s' % (
                    self.attr, object_description(view))
            else:
                mapped_view.__text__ = object_description(view)
        return mapped_view