def show_options(self, url, view):
"""Send options request to `url` and display results in pop-up.
"""
res = options(url, timeout=3)
if not res.ok:
return
names = ['Allow', 'Access-Control-Allow-Methods', 'Access-Control-Max-Age']
headers = [res.headers.get(name, None) for name in names]
items = '\n'.join('<li>{}: {}</li>'.format(n, h) for n, h in zip(names, headers) if h)
content = '<h2>OPTIONS: {}</h2>\n<ul>{}</ul>'.format(url, items)
try:
json_dict = res.json()
except:
pass
else:
content = '{}\n<pre><code>{}</pre></code>'.format(
content, json.dumps(json_dict, sort_keys=True, indent=2, separators=(',', ': '))
)
view.show_popup(content, max_width=700, max_height=500)
评论列表
文章目录