Ticket #14557: base.py.diff

File base.py.diff, 1.7 KB (added by pyrou, 5 years ago)
  • base.py

     
    3030        # Go through keyword arguments, and either save their values to our
    3131        # instance, or raise an error.
    3232        for key, value in kwargs.iteritems():
     33            # sanitize keyword arguments
     34            if key in self.http_method_names:
     35                raise TypeError(u"You tried to pass in the %s method name as a "
     36                                u"keyword argument to %s(). Don't do that."
     37                                % (key, self.__class__.__name__))
     38            if not hasattr(self, key):
     39                raise TypeError(u"%s() received an invalid keyword %r" % (
     40                    self.__class__.__name__, key))
     41           
    3342            setattr(self, key, value)
    3443
     44           
     45    def __call__(self, request, *args, **kwargs):
     46        return self.dispatch(request, *args, **kwargs)
     47   
    3548    @classonlymethod
    3649    def as_view(cls, **initkwargs):
    3750        """
    3851        Main entry point for a request-response process.
    3952        """
    40         # sanitize keyword arguments
    41         for key in initkwargs:
    42             if key in cls.http_method_names:
    43                 raise TypeError(u"You tried to pass in the %s method name as a "
    44                                 u"keyword argument to %s(). Don't do that."
    45                                 % (key, cls.__name__))
    46             if not hasattr(cls, key):
    47                 raise TypeError(u"%s() received an invalid keyword %r" % (
    48                     cls.__name__, key))
    49 
    5053        def view(request, *args, **kwargs):
    5154            self = cls(**initkwargs)
    5255            return self.dispatch(request, *args, **kwargs)
Back to Top