archive
/
lantern
Archived
1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
lantern/lantern/handle.py

21 lines
551 B
Python

import subprocess
import json
from collections import namedtuple
Result = namedtuple('Result', ['exit_code', 'html', 'error'])
def execute_handle(executable, request_data):
input_data = json.dumps(request_data).encode('utf-8')
cmd = subprocess.run(executable, input=input_data, stdout=subprocess.PIPE)
return Result(
cmd.returncode,
cmd.stdout.decode('utf-8'),
cmd.stderr.decode('utf-8') if cmd.stderr is not None else None
)
def get_http_status_code(exit_code):
return 200 if exit_code == 0 else 500