\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|}|jjrd|krJd|krJ|dj|dsN(RtidentityR,tbytestrtjoinR^(RRRRR((RRes9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRs    c@sGtjdkr'dtjn|jfd|DS(s#stringify iterable separated by seps%sc3@s|]}|VqdS(N((Rbte(RRe(s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pys sN(RRfR,RgRh(RRRR((RRes9/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.pyR_s  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(RN(tsR2(tout(s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt,s( R'R4R_t debugflagRR.RRNt_write(R/R0RlR1R2((Rls9/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(Ro(R/RJRKRLR2((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRN1scO@s!|r|j|||ndS(sdo conditional writeN(Ro(R/RORJRKRLR2((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRP3scK@s|j||dS(N(Ro(R/RQR2((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRR7scC@stS(N(tTrue(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRS9sRTcC@s|S(N((R/RVRR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRW;scC@sdS(N((R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR6>sN( R!R"R#R4R<RRNRPRRRSR,RWR6(((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRj!s      tdebugformattercB@s#eZdZdZdZRS(cC@s=tj||||t||_|jjd|jdS(Ns%s = [ (R'R4Rt_outRNR)(R/R0RlR1R2((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR4Bs cC@s0|jjdtj|jdddddS(Ns %s, tindentitleveli(RrRNRtpprintR-(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR;Fs cC@s!tj||jjddS(Ns] (R'R6RrRN(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR6Is (R!R"R4R;R6(((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRqAs  tpickleformattercB@s#eZdZdZdZRS(cC@s/tj||||t||_g|_dS(N(R'R4RRrRY(R/R0RlR1R2((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR4Ns cC@s|jj|jdS(N(RYRZR-(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR;RscC@s-tj||jjtj|jdS(N(R'R6RrRNtpickletdumpsRY(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR6Ts (R!R"R4R;R6(((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRvMs  t jsonformattercB@s#eZdZdZdZRS(cC@s?tj||||t||_|jjdt|_dS(Nt[(R'R4RRrRNRpt_first(R/R0RlR1R2((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$RrRNRpR\R-titemsRtjson(R/tfirstRcRdtu((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR;^s  " cC@s!tj||jjddS(Ns ] (R'R6RrRN(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR6ns (R!R"R4R;R6(((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRyXs  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(R_R((RRRRR(s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pytfsRRRtgen(R tsortdictR^R 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(R_R ((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#RpR%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( NttemplateRTtdefaultst resourcestcachet docheadert docfootert separator(R'R4RRrtlookuptemplatetgettreft_treft loadtemplaterR tkeywordsttemplateresourcest defaulttemplt_tttemplatepartsmapt_partst itertoolstcountt_countert _renderitem(R/R0RlR1R2tspec((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(RRrRNRtrender(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.pyRGscC@s!tj||jdidS(NR(R'R6R(R/((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR6s ( R!R"R4R;RR t propertycacheRRGR6(((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{RTis map-cmdline.t templatesRsavailable styles: %s sspecify a templatet/s\smap-trbN(RR,tostpathRHR t templatepathtisfiletconfigRNRt 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(RRRC(RRt partnamestpartsmapRR((Rs9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRs     c C@sV|jr4tjj}||jd|d|d|St||jd|d|d|S(sPCreate a templater from either a literal template or loading from a map fileRRR(RR t frommapfilet maketemplaterR(R0RRRRR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRs   c C@sp|jd}tjd|d|d|d|}|jjd|jdD|rl||jd sRRT(t configitemsR RRC(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,(RbRc(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(t _hasnodespecR t runsymbolt _hasliteralR(R/REt origmappingt newmappingRtorignode((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt populatemap-s    cC@s/|j|}|dk r|S|jj|S(N(RR,R(R/RRRd((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyR<s cC@s||kot|| S(s<Test if a literal value is set or unset in the given mapping(tcallable(R/RR((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRBscC@s#|j|}t|rdS|S(s1Return value of the given name if it is a literalN(RRR,(R/RRRd((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyt _getliteralFs cC@sd|kpd|kS(s=Test if context revision is set or unset in the given mappingRR?((R/R((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pyRMscC@sh|j|d}|j|d}|dks<|dkr@dSy ||SWntjk rcdSXdS(NR@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( NRRTRRwtdebugR0t formatdebugt formatjson(RRyRvRqRt configboolRj(R0RlR1R2R((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(R0tfilenameR1R2Rltfm((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 thirdpartyRRTRRRR R R R tutilsR RRwtobjectRR'RXRUR^R_RjRqRvRyRRRkRpRRRR,RRRtresourcemapperRRtcontextmanagerRRR(((s9/usr/lib64/python2.7/site-packages/mercurial/formatter.pytjsD   4  K     ' 2   V