LJc!@s~ddkZddkZddkZddkZddkZddkZddkZddklZddk l Z l Z l Z ddk lZlZlZlZddkZddklZddklZlZlZlZddklZlZdd d d d d dddddddddddddgZeieZ de!fdYZ"de!fdYZ#de!fd YZ$d!e$fd"YZ%e#a&defd#YZ'e'i(Z)dd;d$YZ*dd<d%YZ+d&d=d'YZ,d e'fd(YZ-d e-e*fd)YZ.de.e,fd*YZ/d e-e+fd+YZ0de0e,fd,YZ1d e'fd-YZ2de2e*fd.YZ3de3e,fd/YZ4d e2e+fd0YZ5de5e,fd1YZ6de5fd2YZ7d3e7fd4YZ8d5Z9d6Z:d7e!fd8YZ;e;Z<de0fd9YZ=de.fd:YZ>dS(>iN(t itemgetter(tiziptchaintimap(tresource_filenamet working_sett Requirementtresource_stream(tWidget(tEnumt OrderedSettRequestLocalDescriptortasbool(tRequesttResponsetResourcetLinktJSLinktCSSLinktSourcetJSSourcet CSSSourcet locationstmerge_resourcestretrieve_resourcestJSFunctionCallst IECSSLinkt IECSSSourcetIEJSLinkt IEJSSourcetJSMixintCSSMixintAggregatedJSLinktAggregatedCSSLinkt VariantedUrlcBseZdZdZRS(cCs ||_dS(N(t url_mapping(tselfR#((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyt__init__"scCsAti|ijo|iti}n|iti}t|S(N(tregistrytACTIVE_VARIANTR#tDEFAULT_VARIANTtunicode(R$tlink((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyt __unicode__&s(t__name__t __module__R%R+(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyR" s t ResourcesAppcBseZdZdZeZdddZdZdZhZdZ d Z d Z d Z d Z d ZdZdZdZRS(sc A WSGI-middleware for rendering injected resources and serving server-side callbacks. tnormals /resourcesiicCs7ti|_h|_g|_||_||_dS(N(t threadingtLockt_lockt_dirst_widgetstprefixtbufsize(R$R5R6((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyR%Es    cCs`xY|i|D]H\}}||jo/||jotd||fqXtSqqWtS(Ns%s is already registered for %s(t iter_variantt ValueErrortTruetFalse(R$twebdirtdirnametvarianttold_wdtold_dn((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyt_is_registeredSs    c Cst|to"tiiti|i}nt|toh||i 6}n|i |jpt d|i |fh}|i i z(||i jo|i i|nWd|i iXx!|iD]\}}||}tii|}tii|}d|gtd|id} di| } |i i zb|i| ||pHti|ii|gt| | |fftid|| nWd|i iXdi|i| id|g||s (ttuple(R$((R$s5/usr/lib/python2.6/site-packages/tw/core/resources.pyt get_prefixedscCs|i|iS(N(R7R'(R$((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyt__iter__scCsCttdtit|ii|g|ii|gS(Ni(RRRStnlargestRVR3RU(R$R=((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyR7sc Cst|}|i}|ido|d}||ijo|i|}|i|i}|i||}d|ijo$|ii d||||S|ii d|||Snt dd||S|i |}|p t dd}|||SdS(Ns /__callback__it200itstatuss 404 Not Found( R t path_infot startswithRbtmake_body_seekabletcopyt authorizationRqt body_filetseekRt serve_file( R$tenvirontstart_responsetreqRrRctauth_reqt auth_responsetresp((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyt__call__s$      cCs|i|\}}}|o`td|d|d|}|o||id=t>s<=t%s(RAR(tstrRt enumeratet _trans_tabletreplaceRtboolttemplate(R$tdRR((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyt_extend_templateks  '(s>=Rs<=R(sgte sgt slte slt (R,R-RRRR(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRes  cBseZdZhdd6deid6dd6ZdZdZdZ dZ e dZ d Z d Ze e eZd Zd Zd ZRS(sj A link to an external resource, like a a JS or CSS file stored in the filesystem. **Attention**: Widgets automatically use the framework to register the directory where the resource is located, and the data in there is served by the middleware without further checks. So be careful that those directories contains no private data! sUse this to specify an external link. If provided this will be used as-is as the resources URL. modname and filename will be ignored.R*sThe relative path (from the module's or distribution's path) of the file the Link should link to.This is either a string, or a dictionary. If it's the latter, it **must** contain a key **%s**. The keys are called a `variant`, and they are used to make the resource refer to various incarntations of itself. Most commonly, these are normal, min(ified), packed or debug. If you configure the :class:`tw.core.resources.ResourcesApp` to deliver a specific variant, it will be served instead of the normal one.R]sThe module that contains the Widget declaration. If not given, it defaults to the name of the module where the Link is declared. Must be an existent module name. You can also pass a pkg_resources.Requirement instance to point to the root of an egg distribution.R[cOsztt|i|||ipA|ip|i}ti|||i\|_ |_ |_ n|i d|_ dS(NR*( RRR%t is_externalR[R-R&R`R]R;R<R*R(R$RRR[((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyR%s  (cCst|io|i S(N(RR]R[(R$((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRscCs5t|i}|io|Stii|pdS(NRA(R)t_linkRRRR_(R$R_((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyt _get_links cCs ||_dS(N(R(R$R*((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyt _set_linkscCs t|iS(N(thashR*(R$((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyt__hash__scCst|dd|ijS(NR*(tgetattrRPR*(R$tother((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyt__eq__scCsE|i}t|to|Sti|jo |tiS|tiS(s Return the relative filename. If the filename is a variant mapping, resolve it based on the current registry settings. (R]RCRIR&R'R((R$tfn((s5/usr/lib/python2.6/site-packages/tw/core/resources.pytactive_filenames   N(R,R-RR.R(RRPRR]R[R%tpropertyRRRR*RRR(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRxs"        cBseZdZdZRS(s) A link to an external CSS file. sE(R,R-RR(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRscBseZdZRS(cCs!ti|||i|dS(N(Rt update_paramsR(R$R((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRs(R,R-R(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRscBs;eZdZdZeddZeZeZdZ RS(s. See :class:`~tw.core.resources.Link` sARskUse this turn require_once-protection on or off. Default is to use the configured application wide settingcCshtt|i|d}|i|ij o,d}|io|d7}q[|d7}n||_dS(NRAs?require_once=ttruetfalse(RRRRt USE_CONFIG(R$RR((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRs ( R,R-RRtdictRtobjectRRR(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRs  cBseZdZRS(cCs!ti|||i|dS(N(RRR(R$R((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRs(R,R-R(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRscBs?eZdZhdd6ZdZdZdZdZRS(s An inlined chunk of source code Examples:: >>> class MySource(Source): ... template = "$src" ... src = "foo=$foo" ... source_vars = ["foo"] ... foo = "bar" ... >>> s = MySource() >>> s.render() u'foo=bar' >>> s = MySource(foo='zoo') >>> s.render() u'foo=zoo' >>> s.render(foo='foo') u'foo=foo' The whole source can also be overriden >>> s.render(src='foo') u'foo' sA string with the source to include between the resource's tags. Can also be a template for string.Template. Any attribute listed at ``source_vars`` will be fetched from the instance or from the kw args to ``display`` or ``render`` into a dictionary to provide values to fill in.tsrccOsd}d}t|djo|d}n|id|pt|ddt|djo|d}nti|d|g|S(s Support positional params. (src)iRiN(RPRVRURRt__new__(RRRRtparent((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyR's#c stti||id}|otdg}iD]}||t|dfqC~D}|ifd|i Dt i |i ||d7s c3s1x*|]#}|dijo |VqqWdS(iN(t source_vars(RiRk(R$(s5/usr/lib/python2.6/site-packages/tw/core/resources.pys :s ( RRRRRRRRPtupdateRNtstringtTemplatetsafe_substitute(R$RRt_[1]RjR((R$s5/usr/lib/python2.6/site-packages/tw/core/resources.pyR2sCcCs t|iS(N(RR(R$((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyR?scCs|it|ddjS(NR(RRRP(R$R((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRBs(R,R-RRRRRR(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRs  cBseZdZdZRS(s. An inlined chunk of CSS source code. s2(R,R-RR(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRHscBseZdZRS(cCs'tt|i||i|dS(N(RRRR(R$R((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRPs(R,R-R(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyROscBseZdZdZRS(s- An inlined chunk of JS source code. s,(R,R-RR(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRUscBseZdZRS(cCs!ti|||i|dS(N(RRR(R$R((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyR\s(R,R-R(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyR[scBs)eZdgZgZddgdZRS(tfunction_callscKsEtt|i||||dditt|i|_dS(Ns %s s (RRR%RRtmapRRR(R$RgRtchildrenR((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyR%fsN(R,R-RRRPR%(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRbs tJSDynamicFunctionCallscBs5eZdgZdZdZdZdZRS(t call_gettercCsgS(((RRH((s5/usr/lib/python2.6/site-packages/tw/core/resources.pytnscCsQtt|i|ddittt|i|i|i |_ dS(Ns %s s ( RRRRRRRRRRHRR(R$R((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRps cCs t|S(N(Rg(R$((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRxscCst|t|jS(N(Rg(R$R((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyR{s(R,R-RRRRR(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRls     cCsKxDtD]<}|i|}|o |i|ti|qqW|S(s In-place merge all resources from ``from_`` into ``to``. Resources from ``to_`` will come first in each resulting OrderedSet. (RRRUR tadd_all(ttotfrom_Rjt from_location((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRs $cCsh}t|ddo|i}nbt|ddot|i}n9t|ddo%ttttt|h}n|S(s'Recursively retrieve resources from objRt itervaluesRnN(RRPRRtreduceRRtiter(tobjtret((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRs%t DynamicCallscBs;eZedZdZdZddZdZRS(t_calls_for_requestcCsJh|_x:tD]2}td|d|d|i}||i|s (RtAttributeErrorRWRXRR(R$RH((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRs   (R,R-R RR%RRR(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyRs    cBseZdZRS(s This is just a marker-class that is used to render aggregated links. It makes sure that the archive_tw_resources-command won't pick them up. (R,R-R(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyR scBseZdZRS(s This is just a marker-class that is used to render aggregated links. It makes sure that the archive_tw_resources-command won't pick them up. (R,R-R(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyR!s((((?R0tloggingRDRRRSRtoperatorRt itertoolsRRRt pkg_resourcesRRRRRt tw.core.baseRt tw.core.utilR R R R twebobR Rt__all__t getLoggerR,RWRR"R.RRR&RRRRRRRRRRRRRRRRRRRRRtdynamic_js_callsR R!(((s5/usr/lib/python2.6/site-packages/tw/core/resources.pyts^       " "   2  S F