comparison mercurial/pycompat.py @ 43021:2cc453284d5c

patchbomb: protect email addresses from shell When patchbomb sends email via a sendmail-like program it invokes this using procutil.popen which passes the string to a shell to be parsed. To protect any special characters in the email addresses on the command line from being interpretered by the shell they must be quoted.
author Floris Bruynooghe <flub@google.com>
date Mon, 30 Sep 2019 00:01:58 +0200
parents 1b49b84d5ed5
children 2372284d9457
comparison
equal deleted inserted replaced
43020:d1d919f679f7 43021:2cc453284d5c
326 Python 3 compatibility as shelx.split() don't accept bytes on Python 3. 326 Python 3 compatibility as shelx.split() don't accept bytes on Python 3.
327 """ 327 """
328 ret = shlex.split(s.decode('latin-1'), comments, posix) 328 ret = shlex.split(s.decode('latin-1'), comments, posix)
329 return [a.encode('latin-1') for a in ret] 329 return [a.encode('latin-1') for a in ret]
330 330
331 shlexquote = shlex.quote
332
331 else: 333 else:
332 import cStringIO 334 import cStringIO
335 import pipes
333 336
334 xrange = xrange 337 xrange = xrange
335 unicode = unicode 338 unicode = unicode
336 bytechr = chr 339 bytechr = chr
337 byterepr = repr 340 byterepr = repr
391 if getattr(sys, 'argv', None) is not None: 394 if getattr(sys, 'argv', None) is not None:
392 sysargv = sys.argv 395 sysargv = sys.argv
393 sysplatform = sys.platform 396 sysplatform = sys.platform
394 sysexecutable = sys.executable 397 sysexecutable = sys.executable
395 shlexsplit = shlex.split 398 shlexsplit = shlex.split
399 shlexquote = pipes.quote
396 bytesio = cStringIO.StringIO 400 bytesio = cStringIO.StringIO
397 stringio = bytesio 401 stringio = bytesio
398 maplist = map 402 maplist = map
399 rangelist = range 403 rangelist = range
400 ziplist = zip 404 ziplist = zip