Replace use of magic constant since it is available as a named constant in py3

This commit is contained in:
Kovid Goyal 2020-07-27 12:54:50 +05:30
parent d8979c20cb
commit 72173970da
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 7 additions and 5 deletions

View File

@ -22,7 +22,7 @@ PDFTOHTML = 'pdftohtml'
def popen(cmd, **kw): def popen(cmd, **kw):
if iswindows: if iswindows:
kw['creationflags'] = 0x08 kw['creationflags'] = subprocess.DETACHED_PROCESS
return subprocess.Popen(cmd, **kw) return subprocess.Popen(cmd, **kw)

View File

@ -58,7 +58,7 @@ def load_jxr_data(data):
with lopen(os.path.join(tdir, 'input.jxr'), 'wb') as f: with lopen(os.path.join(tdir, 'input.jxr'), 'wb') as f:
f.write(data) f.write(data)
cmd = [get_exe_path('JxrDecApp'), '-i', 'input.jxr', '-o', 'output.tif'] cmd = [get_exe_path('JxrDecApp'), '-i', 'input.jxr', '-o', 'output.tif']
creationflags = 0x08 if iswindows else 0 creationflags = subprocess.DETACHED_PROCESS if iswindows else 0
subprocess.Popen(cmd, cwd=tdir, stdout=lopen(os.devnull, 'wb'), stderr=subprocess.STDOUT, creationflags=creationflags).wait() subprocess.Popen(cmd, cwd=tdir, stdout=lopen(os.devnull, 'wb'), stderr=subprocess.STDOUT, creationflags=creationflags).wait()
i = QImage() i = QImage()
if not i.load(os.path.join(tdir, 'output.tif')): if not i.load(os.path.join(tdir, 'output.tif')):
@ -544,7 +544,7 @@ def run_optimizer(file_path, cmd, as_filter=False, input_data=None):
repl(True, iname), repl(False, oname) repl(True, iname), repl(False, oname)
stdin = subprocess.PIPE if as_filter else None stdin = subprocess.PIPE if as_filter else None
stderr = subprocess.PIPE if as_filter else subprocess.STDOUT stderr = subprocess.PIPE if as_filter else subprocess.STDOUT
creationflags = 0x08 if iswindows else 0 creationflags = subprocess.DETACHED_PROCESS if iswindows else 0
p = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=stderr, stdin=stdin, creationflags=creationflags) p = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=stderr, stdin=stdin, creationflags=creationflags)
stderr = p.stderr if as_filter else p.stdout stderr = p.stderr if as_filter else p.stdout
if as_filter: if as_filter:
@ -644,7 +644,9 @@ def test(): # {{{
despeckle_image(img) despeckle_image(img)
remove_borders_from_image(img) remove_borders_from_image(img)
image_to_data(img, fmt='GIF') image_to_data(img, fmt='GIF')
raw = subprocess.Popen([get_exe_path('JxrDecApp'), '-h'], creationflags=0x08 if iswindows else 0, stdout=subprocess.PIPE).stdout.read() raw = subprocess.Popen([get_exe_path('JxrDecApp'), '-h'],
creationflags=subprocess.DETACHED_PROCESS if iswindows else 0,
stdout=subprocess.PIPE).stdout.read()
if b'JPEG XR Decoder Utility' not in raw: if b'JPEG XR Decoder Utility' not in raw:
raise SystemExit('Failed to run JxrDecApp') raise SystemExit('Failed to run JxrDecApp')
# }}} # }}}

View File

@ -30,7 +30,7 @@ if iswindows:
def get_default_route_src_address_external(): def get_default_route_src_address_external():
# Use -6 for IPv6 addresses # Use -6 for IPv6 addresses
raw = subprocess.check_output('route -4 print 0.0.0.0'.split(), creationflags=0x08).decode('utf-8', 'replace') raw = subprocess.check_output('route -4 print 0.0.0.0'.split(), creationflags=subprocess.DETACHED_PROCESS).decode('utf-8', 'replace')
in_table = False in_table = False
default_gateway = get_address_of_default_gateway() default_gateway = get_address_of_default_gateway()
for line in raw.splitlines(): for line in raw.splitlines():