[~] Refactor
This commit is contained in:
parent
1865e81973
commit
54e864f79b
46
d1/f2.py
46
d1/f2.py
@ -423,50 +423,40 @@ class Application:
|
|||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stdin=subprocess.PIPE
|
stdin=subprocess.PIPE
|
||||||
) as p:
|
) as p:
|
||||||
stderr_lines = []
|
response_headers = []
|
||||||
response_headers_all = []
|
|
||||||
returncode = None
|
returncode = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
stderr_poll = select.poll()
|
|
||||||
stderr_poll.register(
|
|
||||||
p.stderr,
|
|
||||||
select.POLLIN & select.POLLPRI
|
|
||||||
)
|
|
||||||
stdout_length = 0
|
stdout_length = 0
|
||||||
|
last_header = None
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if last_header == '\r\n' or not p.poll() is None:
|
||||||
|
break
|
||||||
|
|
||||||
|
last_header = p.stdout.readline().decode('utf-8')
|
||||||
|
response_headers.append(
|
||||||
|
last_header.rstrip('\r\n')
|
||||||
|
)
|
||||||
|
|
||||||
|
yield (response_headers, b'', None)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
returncode = p.poll()
|
returncode = p.poll()
|
||||||
|
|
||||||
poll_result = stderr_poll.poll(100)
|
|
||||||
|
|
||||||
self.op1(json_data=[pprint.pformat(poll_result)])
|
|
||||||
if len(poll_result) > 0:
|
|
||||||
stderr = p.stderr.readline(1024).decode('utf-8')
|
|
||||||
stderr_lines.append(stderr)
|
|
||||||
else:
|
|
||||||
stderr = ''
|
|
||||||
|
|
||||||
stdout = p.stdout.read(1024)
|
stdout = p.stdout.read(1024)
|
||||||
stdout_length += len(stdout)
|
stdout_length += len(stdout)
|
||||||
|
|
||||||
response_headers = [
|
yield ([], stdout, returncode)
|
||||||
o[2:]
|
|
||||||
for o in stderr.splitlines()
|
|
||||||
if o.startswith('< ')
|
|
||||||
]
|
|
||||||
response_headers_all.extend(response_headers)
|
|
||||||
|
|
||||||
yield (response_headers, stdout, returncode)
|
if len(stdout) == 0 and not returncode is None:
|
||||||
|
|
||||||
if len(stderr) == 0 and len(stdout) == 0 and not returncode is None:
|
|
||||||
break
|
break
|
||||||
|
|
||||||
assert returncode == 0
|
assert returncode == 0
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
self.op1(json_data=dict(
|
self.op1(json_data=dict(
|
||||||
stderr_lines=stderr_lines,
|
|
||||||
stdout_length=stdout_length,
|
stdout_length=stdout_length,
|
||||||
response_headers_all=response_headers_all,
|
response_headers=response_headers,
|
||||||
returncode=returncode,
|
returncode=returncode,
|
||||||
))
|
))
|
||||||
raise exception
|
raise exception
|
||||||
@ -512,8 +502,8 @@ class Application:
|
|||||||
'http://%s%s' % (proxy_url, uri),
|
'http://%s%s' % (proxy_url, uri),
|
||||||
'-g',
|
'-g',
|
||||||
'-X', method,
|
'-X', method,
|
||||||
'-v',
|
|
||||||
'--no-buffer',
|
'--no-buffer',
|
||||||
|
'-i',
|
||||||
'--silent',
|
'--silent',
|
||||||
'--data-binary', '@%s' % self.input_dat,
|
'--data-binary', '@%s' % self.input_dat,
|
||||||
'--max-filesize', '%d' % Application.MAX_FILE_SIZE,
|
'--max-filesize', '%d' % Application.MAX_FILE_SIZE,
|
||||||
|
Loading…
Reference in New Issue
Block a user