Ticket #14557: base.py.diff
File base.py.diff, 1.7 KB (added by , 14 years ago) |
---|
-
base.py
30 30 # Go through keyword arguments, and either save their values to our 31 31 # instance, or raise an error. 32 32 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 33 42 setattr(self, key, value) 34 43 44 45 def __call__(self, request, *args, **kwargs): 46 return self.dispatch(request, *args, **kwargs) 47 35 48 @classonlymethod 36 49 def as_view(cls, **initkwargs): 37 50 """ 38 51 Main entry point for a request-response process. 39 52 """ 40 # sanitize keyword arguments41 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 50 53 def view(request, *args, **kwargs): 51 54 self = cls(**initkwargs) 52 55 return self.dispatch(request, *args, **kwargs)