\x89\x50\x4E\x47\x0D\x0A\x1A\x0A PNG  \x89\x50\x4E\x47\x0D\x0A\x1A\x0A  13\c@@sqdZddlmZmZddlZddlZddlZddlmZddl m Z m Z ddl m Z ddlmZmZmZmZmZmZmZdd lmZmZejZd efd YZd efd YZdZdefdYZdZdefdYZ defdYZ!defdYZ"defdYZ#defdYZ$defdYZ%defdYZ&e j'd e(d!efd"YZ)d#Z*d$Z+dddd%Z-dddd&Z.eZ/d'ej0fd(YZ1d)Z2ej3d*Z4ej3d+Z5d,Z6dS(-s~ Generic output formatting for Mercurial The formatter provides API to show data in various ways. The following functions should be used in place of ui.write(): - fm.write() for unconditional output - fm.condwrite() to show some extra data conditionally in plain output - fm.context() to provide changectx to template output - fm.data() to provide extra data to JSON or template output - fm.plain() to show raw text that isn't provided to JSON or template output To show structured data (e.g. date tuples, dicts, lists), apply fm.format*() beforehand so the data is converted to the appropriate data type. Use fm.isplain() if you need to convert or format data conditionally which isn't supported by the formatter API. To build nested structure (i.e. a list of dicts), use fm.nested(). See also https://www.mercurial-scm.org/wiki/GenericTemplatingPlan fm.condwrite() vs 'if cond:': In most cases, use fm.condwrite() so users can selectively show the data in template output. If it's costly to build data, use plain 'if cond:' with fm.write(). fm.nested() vs fm.formatdict() (or fm.formatlist()): fm.nested() should be used to form a tree structure (a list of dicts of lists of dicts...) which can be accessed through template keywords, e.g. "{foo % "{bar % {...}} {baz % {...}}"}". On the other hand, fm.formatdict() exports a dict-type object to template, which can be accessed by e.g. "{get(foo, key)}" function. Doctest helper: >>> def show(fn, verbose=False, **opts): ... import sys ... from . import ui as uimod ... ui = uimod.ui() ... ui.verbose = verbose ... ui.pushbuffer() ... try: ... return fn(ui, ui.formatter(pycompat.sysbytes(fn.__name__), ... pycompat.byteskwargs(opts))) ... finally: ... print(pycompat.sysstr(ui.popbuffer()), end='') Basic example: >>> def files(ui, fm): ... files = [(b'foo', 123, (0, 0)), (b'bar', 456, (1, 0))] ... for f in files: ... fm.startitem() ... fm.write(b'path', b'%s', f[0]) ... fm.condwrite(ui.verbose, b'date', b' %s', ... fm.formatdate(f[2], b'%Y-%m-%d %H:%M:%S')) ... fm.data(size=f[1]) ... fm.plain(b'\n') ... fm.end() >>> show(files) foo bar >>> show(files, verbose=True) foo 1970-01-01 00:00:00 bar 1970-01-01 00:00:01 >>> show(files, template=b'json') [ { "date": [0, 0], "path": "foo", "size": 123 }, { "date": [1, 0], "path": "bar", "size": 456 } ] >>> show(files, template=b'path: {path}\ndate: {date|rfc3339date}\n') path: foo date: 1970-01-01T00:00:00+00:00 path: bar date: 1970-01-01T00:00:01+00:00 Nested example: >>> def subrepos(ui, fm): ... fm.startitem() ... fm.write(b'reponame', b'[%s]\n', b'baz') ... files(ui, fm.nested(b'files', tmpl=b'{reponame}')) ... fm.end() >>> show(subrepos) [baz] foo bar >>> show(subrepos, template=b'{reponame}: {join(files % "{path}", ", ")}\n') baz: foo, bar i(tabsolute_importtprint_functionNi(t_(thextshort(tattr(terrortpycompatttemplatefilterst templatekwt templatert templateutiltutil(tdateutilt stringutilt_nullconvertercB@sPeZdZeZedZedZedZedZ RS(s=convert non-primitive data types to be processed by formattercC@s|S(s$wrap nested data by appropriate type((tdatattmpltsep((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt wrapnestedscC@s|\}}t||fS(s(convert date tuple to appropriate format(tint(tdatetfmtttsttz((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt formatdates cC@s t|S(s:convert dict or key-value pairs to appropriate dict format(tdict(RtkeytvalueRR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt formatdictscC@s t|S(s+convert iterable to appropriate list format(tlist(RtnameRR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt formatlists( t__name__t __module__t__doc__tFalset storecontextt staticmethodRRRR (((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRs t baseformattercB@seZdZdZdZdZdZddZdddd d Z dd d Z d Z d Z dZ dZdZdZdZdddZdZRS(cC@s:||_||_||_||_d|_t|_dS(N(t_uit_topict_optst _convertertNonet_itemRthexfunc(tselftuittopictoptst converter((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt__init__s      cC@s|S(N((R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt __enter__scC@s|dkr|jndS(N(R,tend(R/texctypetexcvaluet traceback((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt__exit__s cC@sdS(s0show a formatted item once all data is collectedN((R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt _showitemscC@s)|jdk r|jni|_dS(s begin an item in the format listN(R-R,R;(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt startitems s%a %b %d %H:%M:%S %Y %1%2cC@s|jj||S(s(convert date tuple to appropriate format(R+R(R/RR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRsRRt cC@s|jj|||||S(s:convert dict or key-value pairs to appropriate dict format(R+R(R/RRRRR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRscC@s|jj||||S(s+convert iterable to appropriate list format(R+R (R/RRRR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR scK@stj|}td|Ds+t|jjrd|krfd|krf|dj|dsR@R?R>N( Rt byteskwargstalltAssertionErrorR+R%t changectxR>R-tupdate(R/tctxs((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pytcontexts cC@stS(s#set of field names to be referenced(tset(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pytdatahintscK@s#tj|}|jj|dS(s8insert data into item that's not shown in default outputN(RRCR-RG(R/R((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRscO@sS|j}t|t|ks6t||f|jjt||dS(s3do default text output while assigning data to itemN(tsplittlenRER-RGtzip(R/tfieldstdeftextt fielddataR2t fieldkeys((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pytwrites *cO@sG|j}t|t|ks*t|jjt||dS(s4do conditional write (primarily for plain formatter)N(RLRMRER-RGRN(R/tcondRORPRQR2RR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt condwrites cK@sdS(s$show raw text for non-templated modeN((R/ttextR2((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pytplainscC@stS(scheck for plain formatter usage(R$(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pytisplainstcC@s;g}|jj||||j|sN(RtidentityR,tbytestrtjoinRc(RRRRR((RRhs9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRs    c@sGtjdkr'dtjn|jfd|DS(s#stringify iterable separated by seps%sc3@s|]}|VqdS(N((RAte(RRh(s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pys sN(RRiR,RjRk(RRRR((RRhs9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR s    ( R!R"R#R$R%R&RRRR (((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRds  tplainformattercB@seeZdZdZdZdZdZdZdZdZ d dd Z d Z RS( sthe default text output schemec@shtj||||t|jr.t|_n t|_|krR|j|_nfd|_dS(Nc@s j|S(N(RS(tsR2(tout(s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt,s( R'R4Rdt debugflagRR.RRSt_write(R/R0RoR1R2((Ros9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR4#s    cC@sdS(N((R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR<-scK@sdS(N((R/R((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR/scO@s|j|||dS(N(Rr(R/RORPRQR2((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRS1scO@s!|r|j|||ndS(sdo conditional writeN(Rr(R/RTRORPRQR2((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRU3scK@s|j||dS(N(Rr(R/RVR2((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRW7scC@stS(N(tTrue(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRX9sRYcC@s|S(N((R/R[RR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR\;scC@sdS(N((R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR6>sN( R!R"R#R4R<RRSRURWRXR,R\R6(((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRm!s      tdebugformattercB@s#eZdZdZdZRS(cC@s=tj||||t||_|jjd|jdS(Ns%s = [ (R'R4Rt_outRSR)(R/R0RoR1R2((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR4Bs cC@s0|jjdtj|jdddddS(Ns %s, tindentitleveli(RuRSRtpprintR-(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR;Fs cC@s!tj||jjddS(Ns] (R'R6RuRS(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR6Is (R!R"R4R;R6(((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRtAs  tpickleformattercB@s#eZdZdZdZRS(cC@s/tj||||t||_g|_dS(N(R'R4RRuR^(R/R0RoR1R2((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR4Ns cC@s|jj|jdS(N(R^R_R-(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR;RscC@s-tj||jjtj|jdS(N(R'R6RuRStpickletdumpsR^(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR6Ts (R!R"R4R;R6(((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRyMs  t jsonformattercB@s#eZdZdZdZRS(cC@s?tj||||t||_|jjdt|_dS(Nt[(R'R4RRuRSRst_first(R/R0RoR1R2((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR4Ys cC@s|jrt|_n|jjd|jjdt}xqt|jjD]Z\}}|rlt}n|jjdtj |dt}|jjd||fqQW|jjddS(Nt,s { s, tparanoids "%s": %ss }( R~R$RuRSRsRaR-titemsRtjson(R/tfirstRBRgtu((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR;^s  " cC@s!tj||jjddS(Ns ] (R'R6RuRS(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR6ns (R!R"R4R;R6(((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR|Xs  t_templateconvertercB@sPeZdZeZedZedZedZedZ RS(s=convert non-primitive data types to be processed by templatercC@stj|d|d|S(s$wrap nested data by templatable typeRR(R t mappinglist(RRR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRwscC@s tj|S(sreturn date tuple(R R(RR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR{sc @sUtjtfd}tjdddd|S(sAbuild object that can be evaluated as either plain string or dictc3@stjVdS(N(RdR((RRRRR(s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pytfsRRRtgen(R tsortdictRcR t hybriddict(RRRRRR((RRRRRs9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRsc@sCtfd}tjddd|S(sAbuild object that can be evaluated as either plain string or listc3@stjVdS(N(RdR ((RRRR(s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRsRRR(RR t hybridlist(RRRRR((RRRRs9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR s ( R!R"R#RsR%R&RRRR (((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRrs ttemplateformattercB@sGeZdZdZdZejdZdZdZ RS(c C@stj||||t||_t|||jdd}|j|_t||dt j dt |dt j |_ t||j dddg|_tj|_|jdidS( NttemplateRYtdefaultst resourcestcachet docheadert docfootert separator(R'R4RRutlookuptemplatetgettreft_treft loadtemplaterR tkeywordsttemplateresourcest defaulttemplt_tttemplatepartsmapt_partst itertoolstcountt_countert _renderitem(R/R0RoR1R2tspec((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR4s    cC@s\|jj}t|j|d<}|dkrE|jdin|j|j|dS(NtindexiR(R-tcopytnextRRR(R/titemR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR;s  cC@sC||jkrdS|j|}|jj|jj||dS(N(RRuRSRtrender(R/tpartRR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRs cC@s|jj|jS(N(Rt symbolsusedR(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt _symbolsusedscC@s |jdS(s5set of field names to be referenced from the templatei(R(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRKscC@s!tj||jdidS(NR(R'R6R(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR6s ( R!R"R4R;RR t propertycacheRRKR6(((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRs    tfrozent templatespeccB@s,eZejZejZejZRS((R!R"RtibRRtmapfile(((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRs  cC@sd|krtd|d Stjj|dstjd|pQtj|}|rtjj|rt|d |Sn|jd|rt|d d S|dkr|j t dtj t j t dnd |ksd |krztjj|rztjj|jd rCt|d tjj|Stj|d }|j}Wd QXtd|d Std|d S(sFind the template matching the given -T/--template spec 'tmpl' 'tmpl' can be any of the following: - a literal template (e.g. '{rev}') - a map-file name or path (e.g. 'changelog') - a reference to [templates] in config file - a path to raw template file A map file defines a stand-alone template environment. If a map file selected, all templates defined in the file will be loaded, and the template matching the given topic will be rendered. Aliases won't be loaded from user config, but from the map file. If no map file selected, all templates in [templates] section will be available as well as aliases in [templatealias]. t{RYis map-cmdline.t templatesRsavailable styles: %s sspecify a templatet/s\smap-trbN(RR,tostpathRLR t templatepathtisfiletconfigRSRt stylelistRtAborttbasenamet startswithtrealpathR t posixfiletread(R0R1RtmapnameR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRs&  *c@si|j|j6}|jr<|jfd|DnI|jrx=|D]2}d|j|f}|krL|||ss%s:%s(RRRG(RRt partnamestpartsmapRR((Rs9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRs     c C@so|jo|j st|jrMtjj}||jd|d|d|St||jd|d|d|S(sPCreate a templater from either a literal template or loading from a map fileRRR(RRRER t frommapfilet maketemplater(R0RRRRR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRs  c C@sp|jd}tjd|d|d|d|}|jjd|jdD|rl||jd sRRY(t configitemsR RRG(R0RRRRRR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRsRcB@seZdZddZdZdZdZdZdZ dZ dZ d Z d Z d Zie d 6ed 6ZRS(s@Resource mapper designed for the default templatekw and functioncC@s"iid6|d6|d6|_dS(NRR>R0(t_resmap(R/R0R>((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR4sc@sfdjDS(Nc@s.h|]$}j|dk r|qS(N(t_getsomeR,(RARB(tmappingR/(s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pys s (t knownkeys(R/R((RR/s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt availablekeysscC@sddddddhS(NRR?R@R>trevcacheR0((R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR"scC@sY||jkrdS|j||}|tkrU|j|||}||R(RRR,RtRepoLookupError(R/RR>R((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt_loadctxQs cC@sh|j|d}|j|d}|dks<|dkr@dSy ||SWntjk rcdSXdS(NR?R(RRR,Rt LookupError(R/RR?R((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt _loadfctx[s R?R@N(R!R"R#R,R4RRRRRRRRRRR(((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRs          cC@s|jdd}|dkr1t||||S|dkrPt||||S|dkrot||||S|dkrt||||S|jddrt||||S|jddrt||||St||||S( NRRYRRztdebugR0t formatdebugt formatjson(RR|RyRtRt configboolRm(R0RoR1R2R((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt formatterjs    c c@sBtj|d*}t|||| }|VWdQXWdQXdS(srCreate a formatter that writes outputs to the specified file Must be invoked using the 'with' statement. twbN(R RR(R0tfilenameR1R2Rotfm((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt openformatter|scc@s |VdS(N((R((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt _neverendingscC@s0|r"t|j||j|jSt|SdS(sCreate a formatter backed by file if filename specified, else return the given formatter Must be invoked using the 'with' statement. This will never call fm.end() of the given formatter. N(RR(R)R*R(RR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt maybereopens(7R#t __future__RRt contextlibRRti18nRRRRt thirdpartyRRYRRRR R R R tutilsR RRztobjectRR'R]RZRcRdRmRtRyR|RRRnRsRRRR,RRRtresourcemapperRRtcontextmanagerRRR(((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pytjsD   4  K     ' 2   V