LU~\JddlZddlZddlZddlZddlZddlmZddlmZddlm Z GddZ Gdde Z dS) N) exceptions)util)Templatec,eZdZdZdZddZdZdZdS)TemplateCollectiona;Represent a collection of :class:`.Template` objects, identifiable via URI. A :class:`.TemplateCollection` is linked to the usage of all template tags that address other templates, such as ``<%include>``, ``<%namespace>``, and ``<%inherit>``. The ``file`` attribute of each of those tags refers to a string URI that is passed to that :class:`.Template` object's :class:`.TemplateCollection` for resolution. :class:`.TemplateCollection` is an abstract class, with the usual default implementation being :class:`.TemplateLookup`. c^ ||dS#tj$rYdSwxYw)zReturn ``True`` if this :class:`.TemplateLookup` is capable of returning a :class:`.Template` object for the given ``uri``. :param uri: String URI of the template to be resolved. TF) get_templaterTemplateLookupException)selfuris /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/mako/lookup.py has_templatezTemplateCollection.has_template#sE    c " " "41   55 s ,,Nct)aReturn a :class:`.Template` object corresponding to the given ``uri``. The default implementation raises :class:`.NotImplementedError`. Implementations should raise :class:`.TemplateLookupException` if the given ``uri`` cannot be resolved. :param uri: String URI of the template to be resolved. :param relativeto: if present, the given ``uri`` is assumed to be relative to this URI. )NotImplementedError)r r relativetos r r zTemplateCollection.get_template1s"###c|Sz^Convert the given ``filename`` to a URI relative to this :class:`.TemplateCollection`.r r filenames r filename_to_uriz"TemplateCollection.filename_to_uriAs  rc|S)aAdjust the given ``uri`` based on the calling ``filename``. When this method is called from the runtime, the ``filename`` parameter is taken directly to the ``filename`` attribute of the calling template. Therefore a custom :class:`.TemplateCollection` subclass can place any string identifier desired in the ``filename`` parameter of the :class:`.Template` objects it constructs and have them come back here. rrs r adjust_urizTemplateCollection.adjust_uriGs  r)N)__name__ __module__ __qualname____doc__rr rrrrr rrs_     $$$$      rrc~eZdZdZ dd Zd Zd Zd Zd ZdZ dZ dZ dZ dS)TemplateLookupa Represent a collection of templates that locates template source files from the local filesystem. The primary argument is the ``directories`` argument, the list of directories to search: .. sourcecode:: python lookup = TemplateLookup(["/path/to/templates"]) some_template = lookup.get_template("/index.html") The :class:`.TemplateLookup` can also be given :class:`.Template` objects programatically using :meth:`.put_string` or :meth:`.put_template`: .. sourcecode:: python lookup = TemplateLookup() lookup.put_string("base.html", ''' ${self.next()} ''') lookup.put_string("hello.html", ''' <%include file='base.html'/> Hello, world ! ''') :param directories: A list of directory names which will be searched for a particular template URI. The URI is appended to each directory and the filesystem checked. :param collection_size: Approximate size of the collection used to store templates. If left at its default of ``-1``, the size is unbounded, and a plain Python dictionary is used to relate URI strings to :class:`.Template` instances. Otherwise, a least-recently-used cache object is used which will maintain the size of the collection approximately to the number given. :param filesystem_checks: When at its default value of ``True``, each call to :meth:`.TemplateLookup.get_template()` will compare the filesystem last modified time to the time in which an existing :class:`.Template` object was created. This allows the :class:`.TemplateLookup` to regenerate a new :class:`.Template` whenever the original source has been updated. Set this to ``False`` for a very minor performance increase. :param modulename_callable: A callable which, when present, is passed the path of the source file as well as the requested URI, and then returns the full path of the generated Python module file. This is used to inject alternate schemes for Python module location. If left at its default of ``None``, the built in system of generation based on ``module_directory`` plus ``uri`` is used. All other keyword parameters available for :class:`.Template` are mirrored here. When new :class:`.Template` objects are created, the keywords established with this :class:`.TemplateLookup` are passed on to each new :class:`.Template`. NTFstrictbeakerrcZdtj|dD|_||_||_||_||_| i} | r| d| |r| d|| r| d| id|d|d|d |d | d |d |d |d|d| d| d|d|d|d|d|d|||d|_|dkri|_ i|_ n2tj ||_ tj ||_ tj |_dS)Nc6g|]}tj|Sr) posixpathnormpath).0ds r z+TemplateLookup.__init__..s0   &'I q ! !   rrdirurltypeformat_exceptions error_handlerinclude_error_handleroutput_encoding cache_implencoding_errorsinput_encodingmodule_directory module_writer cache_args cache_enableddefault_filtersbuffer_filtersstrict_undefinedimportsfuture_imports enable_loop) preprocessor lexer_clsr!)rto_list directoriesr5modulename_callablefilesystem_checkscollection_size setdefault template_args _collection _uri_cacheLRUCache threadingLock_mutex)r rBr5rDrEr.r/r1r3r7r2r8 cache_type cache_dir cache_urlrCr6r9r:r;r<r=r>r4r?r@r0s r __init__zTemplateLookup.__init__s<  +/< R+H+H   !1#6 !2.  J  4  ! !% 3 3 3  4  ! !% 3 3 3  6  ! !&* 5 5 5 !2 ]  $%:    *     n   0  ]  *  ]    n   0  w n! " ;# $)"'   , b !D  DOO#}_==D "mO<>>',,   wC((A(  ||BGK??#,Y^D!-D-DEE7>>'**4::gs33333333334!86< s&'7 7 DB+D ,D2D  Dc||f}||jvr |j|S|ddkr |x}|j|<nC|2tjtj||x}|j|<nd|zx}|j|<|S)z9Adjust the given ``uri`` based on the given relative URI.r/)rIr&r]dirname)r r rkeyvs r rzTemplateLookup.adjust_urisJ $/ ! !?3' ' q6S=='* *A$$  #'0~!*--s(( A$$(+Sy 0A$rc |j|S#t$r$||}||j|<|cYSwxYwr)rIrV _relativeize)r rvalues r rzTemplateLookup.filename_to_urisW ?8, ,   %%h//E(-DOH %LLL s +==ctj|}|jD]6}|dt||kr|t|dcS7dS)zhReturn the portion of a filename that is 'relative' to the directories in this lookup. rN)r&r'rBlen)r rrcs r rkzTemplateLookup._relativeizesg %h//$  DCII &$..D ,,,,/4rc|j |j||jS#t$rYnwxYw |j|||}nd}t d|tj|||d|j x|j|<}||jS#|j |dxYw#|jwxYw)N)r rlookupmodule_filenamer) rMacquirerHreleaserVrCrr&r'rGpop)r rr rqtemplates r r_zTemplateLookup._load+s>  " ',. K   ! ! ! !-     +7&*&>&>x&M&MOO&*O3;4&/99$3 44 ( 44 %  K   ! ! ! !  $$S$/// K   ! ! ! !s6 A A C!AC!ACCC!!C<c|j|S tj|j}|jj|tjkr|S|j|d||j|S#t$r8}|j|dtj d|z|d}~wwxYw)NrT) rrZstatmodule_modified_timeST_MTIMErHrtr_OSErrorrr )r r ru template_statras r rUzTemplateLookup._checkJs   $O GH$566M-t}1MMM   d + + +::h/55 5      d + + +42S8  s:A<5A<< B>3B99B>c@t|f||d|j|j|<dS)zPlace a new :class:`.Template` object into this :class:`.TemplateLookup`, based on the given string of ``text``. )rpr N)rrGrH)r r texts r put_stringzTemplateLookup.put_stringZs> !) ! 3! ! *.*<! ! rc||j|<dS)zPlace a new :class:`.Template` object into this :class:`.TemplateLookup`, based on the given :class:`.Template` object. N)rH)r r rus r put_templatezTemplateLookup.put_templateds !)r)NNTr!FNNr"Nr#TNNNNNNrFNNTNNNN) rrrrrQr rrrkr_rUrrrrr r r Vs>>D  "7L'L'L'L'\8"      """>    )))))rr ) rZr&rWrwrKmakorr mako.templaterrr rrr rs  """"""AAAAAAAAHT)T)T)T)T)'T)T)T)T)T)r