我有一个老式的Python CGI脚本,旨在允许任意数量的已保存问题,并允许每个问题任意数量的已保存答案。我一直在尝试通过使它在列表上的索引为1来保存测试题的第二个答案,但是(预期的)作业似乎没有任何作用。
用于解析CGI值(未保存的值为saved_0_2
)的函数是
def save_values():
sys.stderr.write('save_values()\n')
if get_cgi('submitted'):
sys.stderr.write('submitted')
sys.stderr.write(repr(cgi_form.keys()) + '\n')
for key in cgi_form.keys():
try:
parts = key.split('_')
entry = int(parts[1])
slot = int(parts[2])
if slot == 0:
saved['entries'][entry][1] = get_cgi(key)
else:
sys.stderr.write('Entry: ' + str(entry))
sys.stderr.write('Slot: ' + str(slot))
sys.stderr.write(get_cgi(key))
sys.stderr.write(repr(saved['entries'][entry][2]))
saved['entries'][entry][2][slot - 1] = get_cgi(key)
sys.stderr.write(repr(saved['entries'][entry][2]))
except IndexError:
pass
saved['index'] += 1
sys.stderr.write(repr(saved) + '\n')
cPickle.dump(saved, open(STORAGE + '.' + str(os.getpid()), 'w'))
os.rename(STORAGE + '.' + str(os.getpid()), STORAGE)
if get_cgi('entry'):
open(ACCESS, 'a').write('Statement: ' +
saved['entries'][int(get_cgi('entry'))][1] + '\n' + 'Response: ' +
get_cgi('response') + '\n\n')
Apache日志中以saved_0_2
填充“ It is。”的输出为:
[Sat Jun 23 13:07:57.215372 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: Starting...: /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
[Sat Jun 23 13:07:57.219428 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: load_saved(): /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
[Sat Jun 23 13:07:57.219710 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: save_values(): /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
[Sat Jun 23 13:07:57.219842 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: submitted: /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
[Sat Jun 23 13:07:57.220047 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: ['saved_0_0', 'saved_0_1', 'saved_0_2', 'submitted']: /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
[Sat Jun 23 13:07:57.220188 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: Entry: 0: /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
[Sat Jun 23 13:07:57.220274 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: Slot: 1: /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
[Sat Jun 23 13:07:57.220370 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: Times are HARD.: /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
[Sat Jun 23 13:07:57.220463 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: ['Times are HARD.']: /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
[Sat Jun 23 13:07:57.220563 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: ['Times are HARD.']: /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
[Sat Jun 23 13:07:57.220643 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: Entry: 0: /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
[Sat Jun 23 13:07:57.220733 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: Slot: 2: /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
[Sat Jun 23 13:07:57.220811 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: It is.: /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
[Sat Jun 23 13:07:57.220901 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: ['Times are HARD.']: /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
[Sat Jun 23 13:07:57.221079 2018] [cgi:error] [pid 2443:tid 2995739456] [client 127.0.0.1:41156] AH01215: {'index': 41, 'entries': [[0, "It's tough.", ['Times are HARD.']]]}: /home/paul/paulshukin.com/empathy_edit.cgi, referer: http://localhost/empathy_edit.cgi
但是下一次页面加载时没有带有现有答案的数组的索引1元素。此外,在保存程序中,我受到政府经济学家计算机病毒的打击。一切都说出我想要的值,以便将第二个(索引1)元素添加到列表中,但是赋值似乎并没有改变列表,这是在酸洗和保存之前。
感谢您的帮助...