Plan 9 from Bell Labs’s /usr/web/sources/contrib/bichued/root/sys/src/cmd/hg/mercurial/util.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�
�c*@s[dZddklZddkZddkZddkZddkZddkZddkZddk	Z	ddk
Z
ddkZddkZddk
Z
ddkZddkZddkZddkZddkZd�ad�addkZeidjZd�Zd�Zd	�ZdqZedrZd&�Zd'�Zd(efd)��YZ d*�Z!d+�Z"he"d,<e!d-<Z#d.�Z$d/�Z%d0d1d2�Z&ei'Z'd3�Z(d4�Z)d5�Z*d6�Z+da-d7�Z.d8�Z/d9�Z0hdddd:�Z1d;�Z2d<�Z3d=�Z4d>�Z5d?�Z6dd@�Z7dAefdB��YZ8dC�Z9e:edD�o
ei;Z<n
dE�Z<dddF�Z=eidGjoddHk>TnddHk?TdI�Z@dJ�ZAdK�ZBdL�ZChZDdM�ZEdN�ZFdO�ZGdP�ZHdQ�ZIdR�ZJdS�ZKeLddT�ZMdUefdV��YZNddW�ZOdXefdY��YZPdZefd[��YZQd1dd\�ZRd]�ZSdd^d_�ZTdd`�ZUgda�ZVdddb�ZWdc�ZXdd�ZYde�ZZdfdg�Z[eLdeLdh�Z\da]di�Z^dj�Z_dk�Z`dl�Zadm�Zbdn�Zcddo�Zddp�ZedS(ss�Mercurial utility functions and platform specfic implementations.

This contains helper routines that are independent of the SCM core and
hide platform-specific details from the core.
i�(t_NcCs
t|�S(N(t	_fastsha1(ts((s./mercurial/util.pytsha1scCsNyddkl}Wn#tj
oddkl}nX|aa||�S(Ni�(R(tsha(thashlibRtImportErrorRR(Rt_sha1((s./mercurial/util.pyRs
tposixcCsCti|dtdddtdtidti�}|i|ifS(Ntshelltbufsizei�t	close_fdststdintstdout(t
subprocesstPopentTruetclosefdstPIPERR
(tcmdtp((s./mercurial/util.pytpopen2)scCsRti|dtdddtdtidtidti�}|i|i|ifS(NR	R
i�RRR
tstderr(RRRRRRR
R(RR((s./mercurial/util.pytpopen31s
cCs5yddk}|iSWntj
odSnXdS(s(Return version information if available.i�Ntunknown(t__version__tversionR(R((s./mercurial/util.pyR8s
s%Y-%m-%d %H:%M:%Ss%Y-%m-%d %I:%M:%S%ps%Y-%m-%d %H:%Ms%Y-%m-%d %I:%M%ps%Y-%m-%ds%m-%ds%m/%ds%m/%d/%ys%m/%d/%Ys%a %b %d %H:%M:%S %Ys%a %b %d %I:%M:%S%p %Ys%a, %d %b %Y %H:%M:%Ss%b %d %H:%M:%S %Ys%b %d %I:%M:%S%p %Ys%b %d %H:%M:%Ss%b %d %I:%M:%S%ps%b %d %H:%Ms
%b %d %I:%M%ps%b %d %Ys%b %ds%H:%M:%Ss	%I:%M:%SPs%H:%Ms%I:%M%ps%Ys%Y-%ms%bs%b %YcsEh��iidjo��fd�}n��fd�}|S(s"cache the result of function callsics)|�jo�|��|<n�|S(N((targ(tcachetfunc(s./mercurial/util.pytfjs
cs)|�jo�|��|<n�|S(N((targs(RR(s./mercurial/util.pyRos
(t	func_codetco_argcount(RR((RRs./mercurial/util.pyt	cachefunccs
csQh�g��iidjo���fd�}n���fd�}|S(s+cache most recent results of function callsicsj|�jo;t��djo��id�=n�|��|<n�i|��i|��|S(Nii(tlentpoptremovetappend(R(RRtorder(s./mercurial/util.pyR{s


csj|�jo;t��djo��id�=n�|��|<n�i|��i|��|S(Nii(R#R$R%R&(R(RRR'(s./mercurial/util.pyR�s


(R R!(RR((RR'Rs./mercurial/util.pytlrucachefuncvs

t
propertycachecBseZd�Zdd�ZRS(cCs||_|i|_dS(N(Rt__name__tname(tselfR((s./mercurial/util.pyt__init__�s	cCs&|i|�}t||i|�|S(N(RtsetattrR+(R,tobjttypetresult((s./mercurial/util.pyt__get__�sN(R*t
__module__R-tNoneR2(((s./mercurial/util.pyR)�s	c
CsFti|dtdtdtidti�}|i|�\}}|S(s9filter string S through command CMD, returning its outputR	RRR
(RRRRRtcommunicate(RRRtpouttperr((s./mercurial/util.pyt
pipefilter�scCsbd
\}}ztidd�\}}ti|d�}|i|�|i�tidd�\}}ti|�|id|�}|id|�}ti|�}t	i
djo|d@o
d	}n|o&ttd
�|t
|�f��nt|d�i�SWdy|oti|�nWnnXy|oti|�nWnnXXdS(s�filter string S through a pair of temporary files with CMD.
    CMD is used as a template to create the real command to be run,
    with the strings INFILE and OUTFILE replaced by the real names of
    the temporary files generated.tprefixs
hg-filter-in-twbshg-filter-out-tINFILEtOUTFILEtOpenVMSiiscommand '%s' failed: %strbN(NN(R4ttempfiletmkstemptostfdopentwritetclosetreplacetsystemtsystplatformtAbortRtexplain_exittopentreadtunlink(RRtinnametoutnametinfdtfptoutfdtcode((s./mercurial/util.pyt
tempfilter�s,



s	tempfile:spipe:cCs[xKti�D]=\}}|i|�o!|||t|�i��Sq
q
Wt||�S(sIfilter a string through a command that transforms its input to its output(tfiltertablet	iteritemst
startswithR#tlstripR8(RRR+tfn((s./mercurial/util.pytfilter�s

%cCst|o
d|j�S(s&return true if a string is binary datat(tbool(R((s./mercurial/util.pytbinary�siiccs�d�}g}d}x�|D]�}|i|�|t|�7}||jow||joL|d>}d||�>}||jo
|}n||jo
|}q�ndi|�Vd}g}qqW|odi|�VndS(srreturn no less than min bytes per chunk while data remains,
    doubling min after each chunk until it reaches maxcSs@|pdSnd}x |o|dL}|d7}qW|dS(Nii((txti((s./mercurial/util.pytlog2�s

iitN(R&R#tjoin(tsourcetmintmaxR`tbuftblentchunktnmin((s./mercurial/util.pytincreasingchunks�s(		






cCstS(N(R(RY((s./mercurial/util.pytalways�scCstS(N(tFalse(RY((s./mercurial/util.pytnever�scCs2|pt|�Sntii|�oitii|�dtii|�djotii|t|��Sndit|�|f�}nt|�|id�}}|i	�|i	�x<|o4|o-|d|djo|i
�|i
�q�W|i	�tiidgt|�|�pdS(sareturn the relative path from one place to another.
    root should use os.sep to separate directories
    n1 should use os.sep to separate directories
    n2 should use "/" to separate directories
    returns an os.sep-separated path.

    If n1 is a relative path, it's assumed it's
    relative to root.
    n2 should always be relative to root.
    it/i�s..t.(
t	localpathRAtpathtisabst
splitdriveRbtpconvertt	splitpathtsplittreverseR$tsepR#(troottn1tn2tatb((s./mercurial/util.pytpathto�s-

&

cCs�|tijo
ti}n%t|�o
|}n|ti}|}tii|�ptii|||�}ntii|�}t|�}||jo8|i|�o(|t	|�}||�t
|�Sn||jodSn�ti|�}g}x�to�yti|�}Wnt
j
oPnXt||�oC|pdSn|i�tii|�}||�t
|�Sntii|�\}	}
|i|
�|	|joPn|	}qWtd|��dS(s7return the canonical path of myname, given cwd and rootRas%s not under rootN(RARxtendswithsepRqRrRbtnormpathtpath_auditorRWR#RttstatRtOSErrortsamestatRwRvR&RI(RytcwdtmynametrootsepR+t
audit_pathtroot_sttreltname_sttdirnametbasename((s./mercurial/util.pyt	canonpathsH










cCs-ttd�pttd�p
tid�S(s�return True if we are a frozen executable.

    The code supports py2exe (most common, Windows only) and tools/freeze
    (portable, not much used).
    tfrozent	importerst__main__(thasattrRGtimpt	is_frozen(((s./mercurial/util.pytmain_is_frozen>scCsntdjo]tiid�}|ot|�qjt�otti�qjtt	d�pd�ntS(s]return location of the 'hg' executable.

    Defaults to $HG or 'hg' in the search path.
    tHGthgN(
t
_hgexecutableR4RAtenvirontgettset_hgexecutableR�RGt
executabletfind_exe(R�((s./mercurial/util.pythgexecutableHs

cCs
|adS(s#set location of the 'hg' executableN(R�(Rq((s./mercurial/util.pyR�Wsc
Cs0d�}h}x$|D]}tii|�||<qW|dj	oti�}n|}	tidjod|}nzAx-|i�D]\}}
||
�ti|<q�Wt�tid<|dj	o||joti|�nti	|�}t
idjo|d@o
d}n|o�|o�dtii
|	idd�d�t|�df}|od	||f}ny|i|d
�Wq�tj
o||��q�Xn|SWdxB|i�D]4\}}
|
djoti|=q�|
ti|<q�W|dj	o||joti|�nXdS(s�enhanced shell command execution.
    run with environment maybe modified, maybe in different dir.

    if command fails and onerr is None, return status.  if ui object,
    print error message and return status, else raise onerr object as
    exception.cSsA|djp
|tjodSn|tjodSnt|�S(s9convert python object into string that is useful to shellt0t1N(R4RlRtstr(tval((s./mercurial/util.pytpy2shellcs

tnts"%s"R�R=iis%s %ss%s: %ss
N(RAR�R�R4tgetcwdR+RVR�tchdirRFRGRHRqR�RvRJtwarntAttributeError(
RR�R�tonerrt	errprefixR�toldenvtktoldcwdtorigcmdtvtrcterrmsg((s./mercurial/util.pyRF\sJ	


"

cs�fd�}|S(s5wrap a function with code to check for calling errorscsay�||�SWnItj
o=ttiti�d��djo
ti�n�nXdS(Nii(t	TypeErrorR#t	tracebackt
extract_tbRGtexc_infoterrortSignatureError(Rtkwargs(R(s./mercurial/util.pytcheck�s&
((RR�((Rs./mercurial/util.pytchecksignature�scCs#yti|�WntSnXtS(sCtest whether a file with this name exists. does not follow symlinks(RAtlstatRlR(tfilename((s./mercurial/util.pytlexists�s
cCsryti||�WnWtj
oK}d�}||�}ti||�ti|�ti||�nXdS(sforcibly rename a filecSsdxKtd�D]=}d|tidd�f}tii|�p|Sq
q
Wttidf�dS(Ni
s%s-%08xil�s"No usable temporary filename found(	txrangetrandomtrandintRARqtexiststIOErrorterrnotEEXIST(R9ttriesttemp((s./mercurial/util.pyttempname�s
N(RAtrenameR�RM(tsrctdstterrR�R�((s./mercurial/util.pyR��s	
cCsDti|�ytitii|��Wntj
onXdS(s.unlink and remove the directory if it is emptyN(RARMt
removedirsRqR�R�(R((s./mercurial/util.pyRM�s

cCs�tii|�o8yti|�WnnXtiti|�|�nRy$ti||�ti||�Wn*ti	j
o}t
t|���nXdS(s,copy a file, preserving mode and atime/mtimeN(RARqtislinkRMtsymlinktreadlinktshutiltcopyfiletcopystattErrorRIR�(R�tdesttinst((s./mercurial/util.pyR��scCs!|djo4ti|�ititii|��ij}ntii|�okti|�x�ti	|�D]F\}}tii
||�}tii
||�}t|||�qqWn_|oGyt||�Wqt
tfj
ot}ti||�qXnti||�dS(s1Copy a directory tree using hardlinks if possibleN(R4RAR�tst_devRqR�tisdirtmkdirtosutiltlistdirRbt	copyfilestos_linkR�R�RlR�tcopy(R�R�thardlinkR+tkindtsrcnametdstname((s./mercurial/util.pyR��s"
%
R�cBs eZdZd�Zd�ZRS(sensure that a filesystem path contains no banned components.
    the following properties of a path are checked:

    - under top-level .hg
    - starts at the root of a windows drive
    - contains ".."
    - traverses a symlink (e.g. a/symlink_here/b)
    - inside a nested repositorycCs%t�|_t�|_||_dS(N(tsettauditedt
auditeddirRy(R,Ry((s./mercurial/util.pyR-�sc	s���ijodSntii��}t|�}tii��dp'|di�d	jpti|jott	d����nd�i�jo�g}|D]}||i�q�~}xhd
D]\}||djoE|i
|�}tii|| �}tt	d��|f��q�q�Wn��fd�}	|i�g}
xT|oLti
i|�}|�ijoPn|	|�|
i|�|i�qXW�ii���ii|
�dS(Nis.hgs.hg.Ras#path contains illegal component: %sispath %r is inside repo %rcs�tii�i|�}yti|�}Wn>tj
o2}|itititi	fjo�q��Xt
i|i�o t
td��|f��nVt
i|i�oBtiitii|d��o t
td��|f��ndS(Ns"path %r traverses symbolic link %rs.hgspath %r is inside repo %r(RARqRbRyR�R�R�tENOENTtENOTDIRtEINVALR�tS_ISLNKtst_modeRIRtS_ISDIRR�(R9tcurpathtstR�(R,Rq(s./mercurial/util.pyR�s""(s.hgs.hg.Ra(s.hgs.hg.(R�RARqtnormcaseRuRstlowertpardirRIRtindexRbR$RxR�R&taddtupdate(R,RqR�tpartst_[1]RtlpartstpostbaseR�tprefixesR9((R,Rqs./mercurial/util.pyt__call__s8'(



(R*R3t__doc__R-R�(((s./mercurial/util.pyR��s	cCsti|�iS(s.Return number of hardlinks for the given file.(RAR�tst_nlink(tpathname((s./mercurial/util.pytnlinks0stlinkcCstdtd���dS(NisHardlinks not supported(R�R(R�R�((s./mercurial/util.pyR�7scCsdS(N(R4(tkeyR+tscope((s./mercurial/util.pyt
lookup_reg:sR�(t*cCs�yti||�SWnAtj
o#}|itijo�qXntj
onXti|titiBti	B�}ti
||�ti|�dS(N(RAR�R�R�R�R�RKtO_CREATtO_WRONLYtO_EXCLRCRD(tinfoR�twhytld((s./mercurial/util.pytmakelockBs#cCsnyti|�SWnJtj
o,}|ititifjo�q^ntj
onXt|�i�S(N(	RAR�R�R�R�tENOSYSR�t	posixfileRL(R�R((s./mercurial/util.pytreadlockOscCsAyti|i��SWn#tj
oti|i�SnXdS(s1stat file object that may not have fileno method.N(RAtfstattfilenoR�R�R+(RQ((s./mercurial/util.pyR
YscCs�ti|�}tii|�\}}tii||i��}||jotii||i��}ny,ti|�}||jotSntSWntSnXdS(s�
    Check whether the given path is on a case-sensitive filesystem

    Requires a path (like /foo/.hg) ending with a foldable final
    directory component.
    N(	RAR�RqRvRbtupperR�RlR(Rqts1tdR}tp2ts2((s./mercurial/util.pyt	checkcasebs

cCs�|i�i|i��oPt|�}||tijp||tijo|d}n||}ntiitii||��pdSnti}tio|ti}n|i
dd�tid||f�}tii
tii|��}g}x�|i|�D]�\}}|o|i|�qn|tjoti|�t|<nt|}	|i�}
x@|	D]+}|i�|
jo|i|�PqqW|i|�tii||
�}qWdi|�S(sGet name in the case stored in the filesystem

    The name is either relative to root, or it is an absolute path starting
    with root. Note that this function is unnecessary, and should not be
    called, for case-sensitive filesystems (simply because it's expensive).
    is\s\\s([^%s]+)|([%s]+)RaN(R�RWR#RARxtaltsepRqR�RbR4REtretcompileR�R�tfindallR&t_fspathcacheR�(R+RytltsepstpatterntdirR1tpartRxtcontentstlparttn((s./mercurial/util.pytfspathws>("	




	
c
Cs�y�titiBtiB}tidd|�\}}zati|�ti|�id@}||@}ti	|||A�ti|�id@|j}Wdti
|�XWnttfj
ot
SnX|p|S(s}
    Check whether the given path is on a filesystem with UNIX-like exec flags

    Requires a directory (like /foo/.hg)
    Rai�N(R�tS_IXUSRtS_IXGRPtS_IXOTHR?R@RARDR�tchmodRMR�R�Rl(Rqt	EXECFLAGStfhRYtmtnew_file_has_exectexec_flags_cannot_flip((s./mercurial/util.pyt	checkexec�s

 	cCs[tid|�}y%tid|�ti|�tSWnttfj
otSnXdS(s?check whether the given path is on a symlink-capable filesystemRRoN(	R?tmktempRAR�RMRR�R�Rl(RqR+((s./mercurial/util.pyt	checklink�s
cCs
tidjS(sCreturn True if patches should be applied in binary mode by default.R�(RAR+(((s./mercurial/util.pytneedbinarypatch�scCs-|iti�ptio|iti�S(s)Check path ends with os.sep or os.altsep.(tendswithRARxR(Rq((s./mercurial/util.pyR�scCs|iti�S(s�Split path by os.sep.
    Note that this function does not use os.altsep because this is
    an alternative of simple "xxx.split(os.sep)".
    It is recommended to use os.path.normpath() before using this
    function if need.(RvRARx(Rq((s./mercurial/util.pyRu�scCs0tidjp tidjptiid�S(sAre we running in a GUI?R�tmactDISPLAY(RAR+R�R�(((s./mercurial/util.pytgui�scCs�tii|�\}}tidd|d|�\}}ti|�yti|�id@}WnWtj
oK}|i	t	i
jo�n|}|d	jot}n|dM}nXti
||�|o|Sny�yt|d�}	WnStj
oG}|i	t	i
jo|Snt|dd	�p
||_n�nXt|d�}
x!t|	�D]}|
i|�qbW|	i�|
i�Wn%yti|�WnnX�nX|S(
sCreate a temporary file with the same contents from name

    The permission bits are copied from the original file.

    If the temporary file is going to be truncated immediately, you
    can use emptyok=True as an optimization.

    Returns the name of the temporary file.
    R9s.%s-Ri�i�R>R�R:N(RARqRvR?R@RDR�R�R�R�R�R4tumaskR&RR�tgetattrR�t
filechunkiterRCRM(R+temptyokt
createmodeRRYtfdR�R�R�tifptofpRh((s./mercurial/util.pyt
mktempcopy�sF
"




tatomictempfilecBs2eZdZd�Zd�Zd�Zd�ZRS(s�file-like object that atomically updates a file

    All writes will be redirected to a temporary copy of the original
    file.  When rename is called, the copy is renamed to the original
    name, making the changes visible.
    cCsL||_d|_t|dd|jd|�|_t|i|�|_dS(NR7twR8(t_atomictempfile__nameR4t_fpR<R�R(R,R+tmodeR8((s./mercurial/util.pyR-s
		cCst|i|�S(N(R5R@(R,R+((s./mercurial/util.pyt__getattr__scCs;|iip*|ii�t|it|i��ndS(N(R@tclosedRDR�R�RpR?(R,((s./mercurial/util.pyR�!s

cCsR|ipdSn|iip/yti|i�WnnX|ii�ndS(N(R@RCRARMR�RD(R,((s./mercurial/util.pyt__del__&s

(R*R3R�R-RBR�RD(((s./mercurial/util.pyR=s
			cCs�y6ti|�|dj	oti||�ndSWnJtj
o>}|itijodSn|itijo�q�nXtii	tii
|��}t||�t||�dS(s9recursive directory creation with parent mode inheritanceN(RAR�R4R&R�R�R�R�RqtabspathR�tmakedirs(R+RAR�tparent((s./mercurial/util.pyRF/s


topenercBsMeZdZed�Zed��Zd�Zdeed�Z	d�Z
RS(s�Open files relative to a base directory

    This class is used to hide the details of COW semantics and
    remote file access from higher level code.
    cCs9||_|ot|�|_n
t|_d|_dS(N(R�R�R�RkR4R8(R,R�taudit((s./mercurial/util.pyR-Es
		cCs
t|i�S(N(R.R�(R,((s./mercurial/util.pyt_can_symlinkMscCs3|idjodSnti||id@�dS(Ni�(R8R4RAR&(R,R+((s./mercurial/util.pyt_fixfilemodeQstrc	Cs7|i|�tii|i|�}|od|jo|d7}nd}|djo�yt|�}WnRtj
oFd}tii|�}tii|�pt	||i
�q�nX|ot|||i
�Sn|djott
|�|�qnt||�}|djo|i|�n|S(NR}i�RLR>ii(RLsrb(R�RARqRbR�R�R�R�R�RFR8R=R�R<RRK(	R,RqRAttextt
atomictempRtnlinkRRQ((s./mercurial/util.pyR�Vs*



c	Cs|i|�tii|i|�}yti|�Wntj
onXtii|�}tii|�pt	||i
�n|ioXyti||�Wqtj
o1}t|i
td�||if|��qXn4||d�}|i|�|i�|i|�dS(Nscould not symlink to %r: %sR>(R�RARqRbR�RMR�R�R�RFR8RJR�R�RtstrerrorRCRDRK(R,R�R�tlinknameR�R�R((s./mercurial/util.pyR�os&



(R*R3R�RR-R)RJRKRlR�R�(((s./mercurial/util.pyRH?s	tchunkbuffercBs eZdZd�Zd�ZRS(soAllow arbitrary sized chunks of data to be efficiently read from an
    iterator over chunks of arbitrary size.cCs%t|�|_d|_d|_dS(szin_iter is the iterator that's iterating over the input chunks.
        targetsize is how big a buffer to try to maintain.RaiiNi(titerRft
targetsize(R,tin_iter((s./mercurial/util.pyR-�s	cCs'|t|i�jo�|io�t||i�}ti�}|i|i�t|i�}x@|iD]5}|i|�|t|�7}||joPqgqgW||jo
t|_n|i	�|_nt|i�|jot
|i�d}|_n$|i| t|i|�}|_|S(suRead L bytes of data from the iterator of chunks of data.
        Returns less than L bytes if the iterator runs dry.Ra(R#RfRSReRTt	cStringIOtStringIORCRltgetvalueR�tbuffer(R,RRTt	collectort	collectedRhR((s./mercurial/util.pyRL�s$ 


	

#(R*R3R�R-RL(((s./mercurial/util.pyRR�s	ccs�|djpt�|djp|djpt�xttol|djo
|}nt||�}|o
|i|�}|pPn|o|t|�8}n|Vq8WdS(sXCreate a generator that produces the data in the file size
    (default 65536) bytes at a time, up to optional limit (default is
    to read all data).  Chunks may be less than size bytes if the
    chunk is the last chunk in the file, or the file is a socket or
    some other type of file that sometimes reads less data than is
    requested.iN(tAssertionErrorR4RRdRLR#(RtsizetlimittnbytesR((s./mercurial/util.pyR6�s!
cCsPti�}|ddjotio
ti}n
ti}ti|�|fS(Nii(ttimet	localtimetdaylighttaltzonettimezonetmktime(tltttz((s./mercurial/util.pytmakedate�s

	s%a %b %d %H:%M:%S %Y %1%2cCs�|pt�\}}d|jp
d|joh|djodpd}t|�d}|idd||df�}|idd|d�}nti|tit|�|��}|S(	s�represent a (unixtime, offset) tuple as a localized time.
    unixtime is seconds since the epoch, and offset is the time zone's
    number of seconds away from UTC. if timezone is false, do not
    append time zone to string.s%1s%2it-t+i<s%c%02ds%02d(RhtabsRER`tstrftimetgmtimetfloat(tdatetformatttRgtsigntminutesR((s./mercurial/util.pytdatestr�s %cCst|dd�S(s1turn (timestamp, tzoff) tuple into iso 8631 date.Rps%Y-%m-%d(Rt(Ro((s./mercurial/util.pyt	shortdate�sc
Cs'd�}||�|}}|djodi|i�d �}nxs|D]k}g}|D]"}d||jo|tq^q^~}	|	p(|d||7}|d|d7}qMqMWti||�}
tti|
��}|djo#tti	|
��}||}n||}||fS(	s~parse a localized time string and return a (unixtime, offset) tuple.
    if the string cannot be parsed, ValueError is raised.cSs�|i�d}|ddjo�t|�djon|di�o]|ddjodpd}t|dd!�}t|dd!�}||d|dSn|d	jp
|d
jodSndS(Ni�is+-iiRjii<tGMTtUTC(RvR#tisdigittintR4(tstringRgRrthoursRs((s./mercurial/util.pyRd�s5t i�t%t@s@%iN(
R4RbRvRR`tstrptimeRytcalendarttimegmRe(
RzRptdefaultsRdtoffsetRoRR�Rtfoundt	timetuplet
localunixtimetunixtime((s./mercurial/util.pytstrdate�s"	
6

c
Cs�|pdSnt|t�ot|�djo|Sn|p
t}n|i�}y"tt|id��\}}Wn�tj
o�|p
h}nt	�}x_di�D]Q}||jo>|ddjod||<qt
|d|d�||<q�q�Wxb|D]?}yt|||�\}}Wnttfj
oq
XPq
Wt
td�|��nXt|�d	jot
td
�|��n|djp
|djot
td
�|��n||fS(s�parse a localized date/time string and return a (unixtime, offset) tuple.

    The date may be a "unixtime offset" string or in one of the specified
    formats. If the date already is a (unixtime, offset) tuple, it is returned.
    iiR|sd mb yY HI M StHMSt00R}sinvalid date: %r i�sdate exceeds 32 bits: %di ;��simpossible time zone offset: %d(ii(t
isinstancettupleR#tdefaultdateformatststriptmapRyRvt
ValueErrorRhRtR�t
OverflowErrorRIRRk(RotformatsR�twhenR�tnowRRp((s./mercurial/util.pyt	parsedate�s@#
"
	

#cs}d�}d�}|i�}|ddjo!||d���fd�Sn*|ddjo!||d���fd�Sn�dd	jonyt|d�}Wn-tj
o!ttd
�|d��nXt�d|dd��fd
�Snyd|joB|id�\}}||�||�����fd�Sn*||�||�����fd�SdS(s�Return a function that matches a given date match specifier

    Formats include:

    '{date}' match a given date to the accuracy provided

    '<{date}' on or before a given date

    '>{date}' on or after a given date

    cSs)tdddd�}t|t|�dS(NtmbR�Ri(tdictR�textendeddateformats(RoR((s./mercurial/util.pyR�3sc	Ss�tdddddddd�}x@di�D]2}y"||d	<t|t|�d
SWq.q.Xq.Wd|d	<t|t|�d
S(NR�t12tHIt23tMt59tSs31 30 29Rit28(R�RvR�R�(RoRtdays((s./mercurial/util.pyR7s!


it<ics
|�jS(((R^(R�(s./mercurial/util.pyt<lambda>Est>cs
|�jS(((R^(R�(s./mercurial/util.pyR�HsRisinvalid day spec: %siics
|�jS(((R^(R�(s./mercurial/util.pyR�Oss to cs|�jo
|�jS(((R^(tstoptstart(s./mercurial/util.pyR�Sscs|�jo
|�jS(((R^(R�R�(s./mercurial/util.pyR�VsN(R�RyR�RIRRhRv(RoR�RR�R|R}((R�R�R�s./mercurial/util.pyt	matchdate&s,
		
cCs�|id�}|djo|| }n|id�}|djo||d}n|id�}|djo|| }n|id�}|djo|| }n|S(s>Return a short representation of a user name or email address.R~iR�iR|Ro(tfind(tuserR((s./mercurial/util.pyt	shortuserXs



cCs>|id�}|djo
d}n||id�d|!S(sget email of author.R�i�R�iN(R�R4(tauthorRL((s./mercurial/util.pytemailhsi�cCs/t|�|jo|Snd||d SdS(s;Trim string to at most maxlength (default: 400) characters.s%s...iN(R#(RMt	maxlength((s./mercurial/util.pytellipsisnsc#s��fd�}|o ttid�o
d�}nt}|djo|og}||��nx<ti�dtd|�D]\}}}d|jok|Vtii|dd�}	tiitii|	d��o	|	Vn|o|i	d�q�g|(q�|o�g}
x}|D]u}tii||�}|||�oJtii
|�o&x0t|t|�D]}
|
VqoWq�|
i|�qqW|
|(q�q�WdS(	s2yield every hg repository under path, recursively.cs|i�jo
|�ndS(N(R�(R�(Rq(s./mercurial/util.pyt
errhandlerwsR�cSsjt}tii}ti|�}x)|D]!}|||�ot}Pq(q(W|p|i|�n|S(N(RlRARqR�R�RR&(tdirlstR�tmatchR�tdirstatt
lstdirstat((s./mercurial/util.pyt_add_dir_if_not_there{s	ttopdowntonerrors.hgtpatchesN(
R�RARqRlR4twalkRRbR�R%R�t	walkreposR&(Rqt	followsymt	seen_dirstrecurseR�R�RytdirstfilestqroottnewdirsRtfnamethgname((Rqs./mercurial/util.pyR�us:

"	
cCsJt�}|it��g}|D]}|tii|�q$~}|S(s+return default os-specific hgrc search path(t
system_rcpathtextendtuser_rcpathRARqR�(RqR�R((s./mercurial/util.pyt	os_rcpath�s	-cCs�tdjo�dtijo�gax�tiditi�D]�}|pq=ntii|�oTx^ti	|�D]<\}}|i
d�o titii||��qtqtWq=ti|�q=Wq�t
�antS(sreturn hgrc search path. if env var HGRCPATH is set, use it.
    for each item in path, if directory, use files ending in .rc,
    else use item.
    make HGRCPATH empty to only look in .hg/hgrc of current repo.
    if no HGRCPATH, use default os-specific path.tHGRCPATHs.rcN(t_rcpathR4RAR�RvtpathsepRqR�R�R�R0R&RbR�(RRR�((s./mercurial/util.pytrcpath�s
(
c
Csddtd�fddtd�fddtd�fddtd	�fddtd
�fddtd�fddtd�fddtd
�fddtd�fddtd�ff
}x>|D]6\}}}|||jo||t|�Sq�q�W|dd|S(s:return byte count formatted as readable string, with unitsidiis%.0f GBi
s%.1f GBs%.2f GBis%.0f MBs%.1f MBs%.2f MBs%.0f KBs%.1f KBs%.2f KBs
%.0f bytesi�ii@i@i@iiiiii(RRn(R_tunitst
multipliertdivisorRp((s./mercurial/util.pyt	bytecount�scCsP|d}|i|�o2|t|�}|id�o|d}qLn|S(Nt:s//i(RWR#(tschemeRqtsc((s./mercurial/util.pytdrop_scheme�s
cCst|�idd�S(Ns\\s\(treprRE(R((s./mercurial/util.pytuirepr�scCs$dtijo/yttid�SWq?tj
oq?Xny�ddk}ddk}ddk}x�titi	fD]�}ypy|i
�}Wntj
o
wynXti|�pwyn|i
||id�}|id|�dSWqytj
oqyXqyWWntj
onXdS(	NtCOLUMNSi�R[ithiiPt(RAR�RyR�ttermiostarraytfcntlRGR
RRR�tisattytioctlt
TIOCGWINSZR(R�R�R�tdevR9tarri((s./mercurial/util.pyt	termwidth�s.	$
cCsL|djot�d}ndd|}|iti|d||��S(Nis
R|twidth(R4R�Rbttextwraptwrap(tlinet
hangindentR�tpadding((s./mercurial/util.pyR��s
ccs1x*|D]"}x|i�D]}|VqWqWdS(N(t
splitlines(titeratorRhR�((s./mercurial/util.pyt	iterliness

(s%Y-%m-%d %H:%M:%Ss%Y-%m-%d %I:%M:%S%ps%Y-%m-%d %H:%Ms%Y-%m-%d %I:%M%ps%Y-%m-%ds%m-%ds%m/%ds%m/%d/%ys%m/%d/%Ys%a %b %d %H:%M:%S %Ys%a %b %d %I:%M:%S%p %Ys%a, %d %b %Y %H:%M:%Ss%b %d %H:%M:%S %Ys%b %d %I:%M:%S%p %Ys%b %d %H:%M:%Ss%b %d %I:%M:%S%ps%b %d %H:%Ms
%b %d %I:%M%ps%b %d %Ys%b %ds%H:%M:%Ss	%I:%M:%SPs%H:%Ms%I:%M%p(s%Ys%Y-%ms%bs%b %Y(fR�ti18nRR�R�RVR�RR�RGR?R�RAR�R`R�R�R�R�RRRR+RRRRR�R�R"R(tobjectR)R8RTRURZR]RjRIRkRmR~R�R4R�R�R�R�RFR�R�R�RMR�R�R�R�R�R�R�RtwindowsRR	RR
RRR"R,R.R/RRuR3RlR<R=RFRHRRR6RhRtRuR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�(((s./mercurial/util.pys<module>s�TH					
													1	
		2	
					?	
	
	
	
				.						0H"	$.	2		.						

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.