comparison mercurial/patch.py @ 30944:48dea083f66d

py3: convert the mode argument of os.fdopen to unicodes (1 of 2) os.fdopen() does not accepts bytes as its second argument which represent the mode in which the file is to be opened. This patch makes sure unicodes are passed in py3 by using pycompat.sysstr().
author Pulkit Goyal <7895pulkit@gmail.com>
date Mon, 13 Feb 2017 20:06:38 +0530
parents 897726622877
children 71a6723c0029
comparison
equal deleted inserted replaced
30943:78de43ab585f 30944:48dea083f66d
32 encoding, 32 encoding,
33 error, 33 error,
34 mail, 34 mail,
35 mdiff, 35 mdiff,
36 pathutil, 36 pathutil,
37 pycompat,
37 scmutil, 38 scmutil,
38 similar, 39 similar,
39 util, 40 util,
40 ) 41 )
41 stringio = util.stringio 42 stringio = util.stringio
207 r'---[ \t].*?^\+\+\+[ \t]|' 208 r'---[ \t].*?^\+\+\+[ \t]|'
208 r'\*\*\*[ \t].*?^---[ \t])', re.MULTILINE|re.DOTALL) 209 r'\*\*\*[ \t].*?^---[ \t])', re.MULTILINE|re.DOTALL)
209 210
210 data = {} 211 data = {}
211 fd, tmpname = tempfile.mkstemp(prefix='hg-patch-') 212 fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
212 tmpfp = os.fdopen(fd, 'w') 213 tmpfp = os.fdopen(fd, pycompat.sysstr('w'))
213 try: 214 try:
214 msg = email.Parser.Parser().parse(fileobj) 215 msg = email.Parser.Parser().parse(fileobj)
215 216
216 subject = msg['Subject'] and mail.headdecode(msg['Subject']) 217 subject = msg['Subject'] and mail.headdecode(msg['Subject'])
217 data['user'] = msg['From'] and mail.headdecode(msg['From']) 218 data['user'] = msg['From'] and mail.headdecode(msg['From'])
1053 (patchfd, patchfn) = tempfile.mkstemp(prefix="hg-editor-", 1054 (patchfd, patchfn) = tempfile.mkstemp(prefix="hg-editor-",
1054 suffix=".diff", text=True) 1055 suffix=".diff", text=True)
1055 ncpatchfp = None 1056 ncpatchfp = None
1056 try: 1057 try:
1057 # Write the initial patch 1058 # Write the initial patch
1058 f = os.fdopen(patchfd, "w") 1059 f = os.fdopen(patchfd, pycompat.sysstr("w"))
1059 chunk.header.write(f) 1060 chunk.header.write(f)
1060 chunk.write(f) 1061 chunk.write(f)
1061 f.write('\n'.join(['# ' + i for i in phelp.splitlines()])) 1062 f.write('\n'.join(['# ' + i for i in phelp.splitlines()]))
1062 f.close() 1063 f.close()
1063 # Start the editor and wait for it to complete 1064 # Start the editor and wait for it to complete