def _do(self, op, args):
op, args = op.lower(), copy.copy(args)
if op == 'show_url':
self.show_url(url=args[0])
elif op in ('get_url', 'post_url'):
url = args.pop(0)
base_url = '/'.join(url.split('/')[:3])
uo = urllib.URLopener()
for cookie, value in self.config.get('http_cookies', {}
).get(base_url, []):
uo.addheader('Cookie', '%s=%s' % (cookie, value))
if op == 'post_url':
(fn, hdrs) = uo.retrieve(url, data=args)
else:
(fn, hdrs) = uo.retrieve(url)
hdrs = unicode(hdrs)
with open(fn, 'rb') as fd:
data = fd.read().strip()
if data.startswith('{') and 'application/json' in hdrs:
data = json.loads(data)
if 'message' in data:
self.notify_user(data['message'])
elif op == "shell":
try:
for arg in args:
rv = os.system(arg)
if 0 != rv:
raise OSError(
'Failed with exit code %d: %s' % (rv, arg))
except:
traceback.print_exc()
elif hasattr(self, op):
getattr(self, op)(**(args or {}))
评论列表
文章目录