Ñò Tã·Jc @s¼dZddkZddkZddklZddkZddklZeie ƒZ ddgZ dd„Z defd „ƒYZeƒiZeid eieiBƒZd „ZdS( s1 .. testoutput:: :hide: >>> # This is so the doctests start from a clean state >>> from tw.core.util import install_framework; install_framework(True) ToscaWidgets can inject resources that have been registered for injection in the current request. Usually widgets register them when they're displayed and they have instances of :class:`tw.api.Resource` declared at their :attr:`tw.api.Widget.javascript` or :attr:`tw.api.Widget.css` attributes. Resources can also be registered manually from a controller or template by calling their :meth:`tw.api.Resource.inject` method. When a page including widgets is rendered, Resources that are registered for injection arre collected in request-local storage area (this means any thing stored here is only visible to one single thread of execution and that its contents are freed when the request is finished) where they can be rendered and injected in the resulting html. ToscaWidgets' middleware can take care of injecting them automatically (default) but they can also be injected explicitly, example:: >>> from tw.api import JSLink, inject_resources >>> JSLink(link="http://example.com").inject() >>> html = "" >>> inject_resources(html) '' Once resources have been injected they are popped from request local and cannot be injected again (in the same request). This is useful in case :class:`injector_middleware` is stacked so it doesn't inject them again. Injecting them explicitly is neccesary if the response's body is being cached before the middleware has a chance to inject them because when the cached version is served no widgets are being rendered so they will not have a chance to register their resources. iÿÿÿÿN(tRequest(tMultipleReplacertinject_resourcestinjector_middlewarecs‡‡fd†}|S(sE Middleware that injects resources (if any) into the page whenever the output is html (peeks into Content-Type header). Normally you don't have to stack thi yourself because :class:`tw.core.middleware.ToscaWidgetsMiddleware` does it when it is passed the ``inject_resources`` flag as True (default). cst|ƒ}|iˆƒ}|iiddƒiƒ}d|jo?tiiƒ}|o%t|i ||i dˆƒ|_ q‚n|||ƒS(Ns Content-Types text/plainthtmlt render_filter( Rt get_responsetheaderstgettlowerttwt frameworkt pop_resourcesRtbodytcharset(tenvirontstart_responsetreqtrespt content_typet resources(Rtapp(s=/usr/lib/python2.6/site-packages/tw/core/resource_injector.pyt _injectorBs  )((RRR((RRs=/usr/lib/python2.6/site-packages/tw/core/resource_injector.pyR9s t_ResourceInjectorcBs2eZd„Zed„Zddddd„ZRS(cCscti|h|idƒd6|idtƒd6|idƒd6|idtƒd6titiBƒS( Ntheads t headbottoms tbodytops t bodybottoms (Rt__init__t_injector_for_locationtFalsetretItM(tself((s=/usr/lib/python2.6/site-packages/tw/core/resource_injector.pyRTs  cs‡‡fd†}|S(Ncs€|djo d„}ndig}|iˆgƒD]}||||ƒq7~ƒ}|i|ƒ}ˆo ||S||S(NcSs |iƒS(N(trender(t_environtresource((s=/usr/lib/python2.6/site-packages/tw/core/resource_injector.pyR_su (tNonetjoinRtencode(tgroupRtencodingRRt_[1]trtinj(tkeytafter(s=/usr/lib/python2.6/site-packages/tw/core/resource_injector.pytinject]s  ? ((R"R.R/R0((R/R.s=/usr/lib/python2.6/site-packages/tw/core/resource_injector.pyR\s c Csm|djotiiƒ}n|oB|pt|ƒpd}ti||||d|ddƒ}n|S(s—Injects resources, if any, into html string when called. .. note:: Ignore the ``self`` parameter if seeing this as :func:`tw.core.resource_injector.inject_resources` docstring since it is an alias for an instance method of a private class. ``html`` must be a ``encoding`` encoded string. If ``encoding`` is not given it will be tried to be derived from a . Resources for current request can be obtained by calling ``tw.framework.pop_resources()``. This will remove resources from request and a further call to ``pop_resources()`` will return an empty dict. tasciiRRN(R&R R R t find_charsetRt__call__(R"RRR*RR((s=/usr/lib/python2.6/site-packages/tw/core/resource_injector.pyR3hs  (N(t__name__t __module__RtTrueRR&R3(((s=/usr/lib/python2.6/site-packages/tw/core/resource_injector.pyRSs  s)charset\s*=\s*(?P[\w-]+)([^\>])*cCs.ti|ƒ}|o|idƒiƒSdS(NR(t _charset_retsearchR)R (tstringtm((s=/usr/lib/python2.6/site-packages/tw/core/resource_injector.pyR2Œs(t__doc__RtloggingtwebobRR t tw.core.utilRt getLoggerR4tlogt__all__R&RRR3RtcompileR R!R7R2(((s=/usr/lib/python2.6/site-packages/tw/core/resource_injector.pyt*s     4