Skip to content

Commit ecd265a

Browse files
Merge pull request chrismattmann#469 from afuetterer/sys-version
refactor: remove python 2 compat sys.version calls
2 parents fc1c03a + 9224b8b commit ecd265a

1 file changed

Lines changed: 4 additions & 23 deletions

File tree

tika/tika.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -663,12 +663,7 @@ def startServer(tikaServerJar, java_path = TikaJava, java_args = TikaJavaArgs, s
663663
global TikaServerProcess
664664
# Patch for Windows support
665665
if Windows:
666-
if sys.version.startswith("2"):
667-
# Python 2.x
668-
TikaServerProcess = Popen(cmd_string, stdout=logFile, stderr=STDOUT, shell=True)
669-
elif sys.version.startswith("3"):
670-
# Python 3.x
671-
TikaServerProcess = Popen(cmd_string, stdout=logFile, stderr=STDOUT, shell=True, start_new_session=True)
666+
TikaServerProcess = Popen(cmd_string, stdout=logFile, stderr=STDOUT, shell=True, start_new_session=True)
672667
else:
673668
TikaServerProcess = Popen(cmd_string, stdout=logFile, stderr=STDOUT, shell=True, preexec_fn=os.setsid)
674669

@@ -704,17 +699,8 @@ def killServer():
704699
time.sleep(1)
705700
# patch to support subprocess killing for windows
706701
if Windows:
707-
if sys.version.startswith("2"):
708-
# Python 2.x
709-
PROCESS_TERMINATE = 1
710-
handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, TikaServerProcess.pid)
711-
ctypes.windll.kernel32.TerminateProcess(handle, -1)
712-
ctypes.windll.kernel32.CloseHandle(handle)
713-
time.sleep(1)
714-
elif sys.version.startswith("3"):
715-
# Python 3.x
716-
os.kill(TikaServerProcess.pid, signal.SIGTERM)
717-
time.sleep(1)
702+
os.kill(TikaServerProcess.pid, signal.SIGTERM)
703+
time.sleep(1)
718704
else:
719705
try:
720706
os.killpg(os.getpgid(TikaServerProcess.pid), signal.SIGTERM)
@@ -918,12 +904,7 @@ def main(argv=None):
918904
resp = main(sys.argv)
919905

920906
# Set encoding of the terminal to UTF-8
921-
if sys.version.startswith("2"):
922-
# Python 2.x
923-
out = codecs.getwriter("UTF-8")(sys.stdout)
924-
elif sys.version.startswith("3"):
925-
# Python 3.x
926-
out = codecs.getwriter("UTF-8")(sys.stdout.buffer)
907+
out = codecs.getwriter("UTF-8")(sys.stdout.buffer)
927908

928909
if type(resp) == list:
929910
out.write('\n'.join([r[1] for r in resp]))

0 commit comments

Comments
 (0)