3

T'íc†ã@sîdZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddlm
Z
ddlmZm
Z
mZmZmZmZddlmZyddlm
ZWnek
r¨dZYnXdZeedœd	d
„Zeedœdd
„Zeeedœdd„Zeddœdd„Zeeeeedœdd„Zeeddœdd„Zeeddœdd„Z eeddœdd„Z!ej"dƒZ#ej"dƒZ$eed œd!d"„Z%eed#œd$d%„Z&ej'feeed&œd'd(„Z(e(Z)ej*ƒp ej+ƒZ,eed)œd*d+„Z-ej.ee
d3d,œd-d.„ƒZ/Gd/d0„d0ƒZ0eddœd1d2„Z1dS)4z6Operating system-related utility functions for Sphinx.éN)ÚStringIO)Úpath)ÚAnyÚ	GeneratorÚIteratorÚListÚOptionalÚType)ÚRemovedInSphinx50Warningú/)Ú
canonicalpathÚreturncCs|jttjƒS)N)ÚreplaceÚSEPrÚsep)r©rú4/tmp/pip-build-gk9425m9/sphinx/sphinx/util/osutil.pyÚos_pathsr)Ú
nativepathr
cCs|jtjtƒS)z"Return path in OS-independent form)rrrr)rrrrÚ
canon_path#sr)ÚbaseÚtor
cCsÄ|jtƒr|S|jdƒdjtƒ}|jdƒdjtƒ}xDt|dd…|dd	…ƒD]&\}}||krdP|jdƒ|jdƒqRW||krˆdSt|ƒdkr¦|dgkr¦dtSdtt|ƒdtj|ƒS)
z.Return a relative URL from ``base`` to ``to``.ú#rNéÚÚ.z..éÿÿÿÿr)Ú
startswithrÚsplitÚzipÚpopÚlenÚjoin)rrZb2Út2ÚxÚyrrrÚrelative_uri(s
$
r&)rr
cCstj|dddS)zEnsure that a path exists.T)Úexist_okN)ÚosÚmakedirs)rrrrÚ	ensuredir?sr*)ÚdirnamesÚsuffixr
ccsrxl|D]d}x^tj|ƒD]P\}}}xD|D]<}|j|ƒr&ytjtj||ƒƒVWq&tk
r`Yq&Xq&WqWqWdS)N)r(ÚwalkÚendswithrÚgetmtimer"ÚOSError)r+r,ÚdirnameÚrootZ_dirsÚfilesÚsfilerrrÚmtimes_of_filesDs


r5)ÚsourceÚdestr
cCsPtjdtddtjj|ƒr@ytj|ƒWntk
r>YnXtj||ƒdS)z3Move a file, removing the destination if it exists.zYsphinx.util.osutil.movefile() is deprecated for removal. Please use os.replace() instead.é)Ú
stacklevelN)	ÚwarningsÚwarnr
r(rÚexistsÚunlinkr0Úrename)r6r7rrrÚmovefileOs
r?cCs,tj|ƒ}ttdƒr(tj||j|jfƒdS)z!Copy a file's modification times.ÚutimeN)r(ÚstatÚhasattrr@Úst_atimeÚst_mtime)r6r7ÚstrrrÚ	copytimes\s

rFcCsNtj|ƒstj||ƒrJtj||ƒyt||ƒWntk
rHYnXdS)z{Copy a file and its modification times, if possible.

    Note: ``copyfile`` skips copying if the file has not been changedN)rr<ÚfilecmpÚcmpÚshutilÚcopyfilerFr0)r6r7rrrrJcsrJz[^a-zA-Z0-9_-]z Documentation$)Ústringr
cCstjd|ƒpdS)NrZsphinx)Úno_fn_reÚsub)rKrrrÚ
make_filenametsrN)Úprojectr
cCsttjd|ƒƒjƒS)Nr)rNÚproject_suffix_rerMÚlower)rOrrrÚmake_filename_from_projectxsrR)rÚstartr
cCs(ytjj||ƒStk
r"|SXdS)aReturn a relative filepath to *path* either from the current directory or
    from an optional *start* directory.

    This is an alternative of ``os.path.relpath()``.  This returns original path
    if *path* and *start* are on different drives (for Windows platform).
    N)r(rÚrelpathÚ
ValueError)rrSrrrrT|srT)Úpathdirr
cCsvtdk	rt|tƒr|jƒStj|ƒ}t|tƒrny|jtƒ}Wn0tk
rl}ztdtƒ|‚WYdd}~XnX|SdS)NzAmultibyte filename not supported on this filesystem encoding (%r))ÚPathÚ
isinstanceÚabspathrÚbytesÚdecodeÚfs_encodingÚUnicodeDecodeError)rVÚexcrrrrYs

rY)Ú
target_dirr
ccs.tjƒ}ztj|ƒdVWdtj|ƒXdS)N)r(ÚgetcwdÚchdir)r_ÚcwdrrrÚcdœs


rcc@steZdZdZeddœdd„Zeddœdd„Zdd	œd
d„Zdd	œdd
„Ze	e
e
eedœdd„Z
eedœdd„ZdS)ÚFileAvoidWritea¸File-like object that buffers output and only writes if content changed.

    Use this class like when writing to a file to avoid touching the original
    file if the content hasn't changed. This is useful in scenarios where file
    mtime is used to invalidate caches or trigger new behavior.

    When writing to this file handle, all writes are buffered until the object
    is closed.

    Objects can be used as context managers.
    N)rr
cCs||_d|_dS)N)Ú_pathÚ_io)ÚselfrrrrÚ__init__²szFileAvoidWrite.__init__)Údatar
cCs|jstƒ|_|jj|ƒdS)N)rfrÚwrite)rgrirrrrj¶szFileAvoidWrite.write)r
cCs’|jstdƒ‚|jƒ}|jjƒy2t|jdd}|jƒ}||krFdSWdQRXWntk
rfYnXt|jddd}|j|ƒWdQRXdS)z0Stop accepting writes and write file, if needed.z,FileAvoidWrite does not support empty files.zutf-8)ÚencodingNÚw)	rfÚ	ExceptionÚgetvalueÚcloseÚopenreÚreadr0rj)rgÚbufZold_fZold_contentÚfrrrro»s
zFileAvoidWrite.closecCs|S)Nr)rgrrrÚ	__enter__ÎszFileAvoidWrite.__enter__)Úexc_typeÚ	exc_valueÚ	tracebackr
cCs|jƒdS)NT)ro)rgrurvrwrrrÚ__exit__ÑszFileAvoidWrite.__exit__)Únamer
cCs|jstdƒ‚t|j|ƒS)Nz=Must write to FileAvoidWrite before other methods can be used)rfrmÚgetattr)rgryrrrÚ__getattr__ÕszFileAvoidWrite.__getattr__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrrhrjrortr	rmrÚboolrxr{rrrrrd¦srdcCs&tjj|ƒrtj|ƒn
tj|ƒdS)N)r(rÚisdirrIÚrmtreeÚremove)rrrrrƒÞsrƒ)NNN)2rÚ
contextlibrGr(ÚrerIÚsysr:ÚiorrÚtypingrrrrrr	Zsphinx.deprecationr
Zsphinx.testing.pathrWÚImportErrorrr€rrr&r*Úfloatr5r?rFrJÚcompilerLrPrNrRÚcurdirrTZsafe_relpathÚgetfilesystemencodingÚgetdefaultencodingr\rYÚcontextmanagerrcrdrƒrrrrÚ<module>sH 




	8