o 3a@svdZddlmZmZmZGdddeZddZddZdd d Z d d Z ddZ ddZ ddZ ddZddZdS)zCFunctions that help with dynamically creating decorators for views.)partialupdate_wrapperwrapscseZdZdfdd ZZS)classonlymethodNcs|durtdt||S)Nz=This method is available only on the class, not on instances.)AttributeErrorsuper__get__)selfinstancecls __class__9/usr/lib/python3/dist-packages/django/utils/decorators.pyrszclassonlymethod.__get__N)__name__ __module__ __qualname__r __classcell__rrr rrsrcCs|dd}t||dS)Nc_sdSrr)argskwargsrrrdummysz%_update_method_wrapper..dummy)r)_wrapper decoratorrrrr_update_method_wrapper s rcsPtdr dddngfdd}D]}t||qt||S)z Decorate `method` with one or more function decorators. `decorators` can be a single decorator or an iterable of decorators. __iter__Ncs4t|t|}D]}||}q ||i|Sr)rrtype)r rr bound_methoddec decoratorsmethodrrr#s z!_multi_decorate.._wrapper)hasattrrr)r!r"rrrr r_multi_decorates   r$csFfdd}tdst|tdrnj}d|j|_|S)z> Convert a function decorator into a method decorator cspt|ts t|Srt|std|ft|}t|s+td||ft|}t|||S)NzfThe keyword argument `name` must be the name of a method of the decorated class: %s. Got '%s' instead.zACannot decorate '%s' as it isn't a callable attribute of %s (%s).) isinstancerr$r# ValueErrorgetattrcallable TypeErrorsetattr)objr"rrnamerr_dec=s$     zmethod_decorator.._decrrzmethod_decorator(%s))r#rr r)rr.r/r,rr-rmethod_decorator5s    r0cCst|S)a< Like decorator_from_middleware, but return a function that accepts the arguments to be passed to the middleware_class. Use like:: cache_page = decorator_from_middleware_with_args(CacheMiddleware) # ... @cache_page(3600) def my_view(request): # ... make_middleware_decoratormiddleware_classrrr#decorator_from_middleware_with_argsYs r5cCs t|S)z Given a middleware class (not an instance), return a view decorator. This lets you use middleware functionality on a per-view basis. The middleware is created with no params passed. r1r3rrrdecorator_from_middlewareis r6csfdd}|S)Ncsfdd}|S)Ncs0gRitfdd}|S)Nc stdr}|dur|Stdr#||}|dur#|Sz g|Ri|}Wn$tyT}ztdrO|}|durO|WYd}~Sd}~wwt|dr}t|jr}tdrj|}tdr{fdd}|||Stdr |S|S) Nprocess_request process_viewprocess_exceptionrenderprocess_template_responseprocess_responsecs |Sr)r<)response) middlewarerequestrrcallbacks zomake_middleware_decorator.._make_decorator.._decorator.._wrapped_view..callback) r#r7r8 Exceptionr9r)r:r;add_post_render_callbackr<)r?rrresultr=er@r> view_func)r?r _wrapped_viewws8          z]make_middleware_decorator.._make_decorator.._decorator.._wrapped_view)r)rFrG)m_argsm_kwargsr4rEr _decoratortszFmake_middleware_decorator.._make_decorator.._decoratorr)rHrIrJr3)rHrIr_make_decoratorss#z2make_middleware_decorator.._make_decoratorr)r4rKrr3rr2rs %r2cCsd|_d|_|S)zj Mark a middleware factory as returning a hybrid middleware supporting both types of request. T sync_capable async_capablefuncrrrsync_and_async_middlewarerQcCd|_d|_|S)z\ Mark a middleware factory as returning a sync middleware. This is the default. TFrLrOrrrsync_only_middlewarerRrTcCrS)z;Mark a middleware factory as returning an async middleware.FTrLrOrrrasync_only_middlewaresrUN)r%)__doc__ functoolsrrr classmethodrrr$r0r5r6r2rQrTrUrrrrs $ )