o ]Lb@sdZddlmZddlZddlZddlmZddlmZm Z ddl m Z m Z m Z mZdZiZeeZedd d d d dad dZddZddZddZddZddZddZddZdZdZdZd Zd!d"ZdS)#aallow the use of MBCS paths with problematic encodings Some MBCS encodings are not good for some path operations (i.e. splitting path, case conversion, etc.) with its encoded bytes. We call such a encoding (i.e. shift_jis and big5) as "problematic encoding". This extension can be used to fix the issue with those encodings by wrapping some functions to convert to Unicode string before path operation. This extension is useful for: - Japanese Windows users using shift_jis encoding. - Chinese Windows users using big5 encoding. - All users who use a repository with one of problematic encodings on case-insensitive file system. This extension is not needed for: - Any user who use only ASCII chars in path. - Any user who do not use any of problematic encodings. Note that there are some limitations on using this extension: - You should use single encoding in one repository. - If the repository path ends with 0x5c, .hg/hgrc cannot be read. - win32mbcs is not compatible with fixutf8 extension. By default, win32mbcs uses encoding.encoding decided by Mercurial. You can specify the encoding by config option:: [win32mbcs] encoding = sjis It is useful for the users who want to commit with UTF-8 log message. )absolute_importN)_)getattrsetattr)encodingerrorpycompat registrarsships-with-hg-core win32mbcsencodingcCstjSN)rr r 1/usr/lib/python3/dist-packages/hgext/win32mbcs.pyKsr)defaultcCst|tr|t}||tkr|Stdt|tr#ttt|St|tr-tt|St|t rA| D] \}}t|||<q6|S)NsNot local encoding) isinstancebytesdecode _encodingencode UnicodeErrortuplemaplistdictitems)arguargkvr r rrQs      rcCsnt|tjr |tSt|trttt|St|tr!tt|St|tr5| D] \}}t|||<q*|Sr ) rrunicoderrrrrrr)rrrr r rras      rcCsBzt|}Wn ty|}Ynw|r|ddvr|tj7}|S)Ns:/\)rrrossep)susr r r appendsepns   r%cCsd|D]}t||r||i|Sqz||||i||WSty1ttdtw)Ns8[win32mbcs] filename conversion failed with %s encoding )rrrAbortrr)funcargtypeencdecargskwdsrr r r basewrapperys  r-cCst|tjtt||Sr )r-rr rrr'r+r,r r rwrappersr/cCst|ttt||Sr )r-strrrr.r r rreversewrappersr1cCsB|rt|}t|d|d<d|vrt|d|d<||i|S)Nrspath)rr%r.r r rwrapperforlistdirs r2csJ|dd\}}tj|}t||fdd}j|_t|||dS)N.cs ||Sr r )r+r,r'r/r rfs zwrapname..f)rsplitsysmodulesr__name__r)namer/moduler6r r5rwrapnames   r=s:os.path.join os.path.split os.path.splitext os.path.normpath os.makedirs mercurial.util.endswithsep mercurial.util.splitpath mercurial.util.fscasesensitive mercurial.util.fspath mercurial.util.pconvert mercurial.util.normpath mercurial.util.checkwinfilename mercurial.util.checkosfilename mercurial.util.splitsRmercurial.encoding.upper mercurial.encoding.lower mercurial.util._filenamebytestrsos.path.splituncsbig5 big5-tw csbig5 big5hkscs big5-hkscs hkscs cp932 932 ms932 mskanji ms-kanji shift_jis csshiftjis shiftjis sjis s_jis shift_jis_2004 shiftjis2004 sjis_2004 sjis2004 shift_jisx0213 shiftjisx0213 sjisx0213 s_jisx0213 950 cp950 ms950 cCstjjstjdkr|tddS|ddat t vr_t D]}t |tq$tjr;t D]}t |tq3t dtt dtt D]}t |tqIdtjvra|dtdSdSdS) Nscygwins.[win32mbcs] cannot activate on this platform. r r smercurial.util.listdirsmercurial.windows.listdirs--debugs([win32mbcs] activated with encoding: %s )ospathsupports_unicode_filenamesr sysplatformwarnrconfigrlowerproblematic_encodingssplitfuncsr=r/ iswindowswinfuncsr2rfuncsr1r8argv writenoi18n)uir6r r rextsetups*           rN) __doc__ __future__rr>r8mercurial.i18nrmercurial.pycompatrr mercurialrrrr testedwith configtable configitemrrrr%r-r/r1r2r=rGrJrIrErNr r r rs: #