コード例 #1
0
ファイル: curl_util.py プロジェクト: muttu2244/MyPython
def exec_curl2(version, req, args):
	s = cStringIO.StringIO()
	c = Util.fun_wrapper(req, args)
	c.setopt(pycurl.WRITEFUNCTION, s.write)
	try:
		c.perform()
	except Exception, e:
		err = c.errstr()
		ConnPool.put(c)
		return [ False, None, Util.gen_error(version, ApiError.connectionError(err)), None ]
コード例 #2
0
ファイル: curl_util.py プロジェクト: muttu2244/MyPython
	def process_response(self, success, callback, data, args):
		if success:
			retval = Util.decode_post(data)
			if not retval:
				Util.err_log("Unable to decode response: args=%s data=%s" % (str(args), data))
				self.api_error[ args[0] ] = ApiError.badData("Unable to parse data")
				return

			if not Util.status_success(retval):
				self.api_error[ args[0] ] = ApiError.internalApiError(retval[ Constants.STATUS ])
			else:
				self.api_data[ args[0] ] = retval[ Constants.RESULT ]
				if callback:
					callback(args, retval[ Constants.RESULT ])
		else:
			self.api_error[ args[0] ] = ApiError.connectionError(data)
コード例 #3
0
ファイル: curl_util.py プロジェクト: muttu2244/MyPython
def exec_curl(version, req, args):
	s = cStringIO.StringIO()
	c = Util.fun_wrapper(req, args)
	c.setopt(pycurl.WRITEFUNCTION, s.write)
	try:
		c.perform()
	except Exception, e:
		err = c.errstr()
		ConnPool.put(c)
		return [ False, None, Util.gen_error(version, ApiError.connectionError(err)) ]
		
	if c.getinfo(pycurl.HTTP_CODE) != 200:
		err = c.errstr()
		ConnPool.put(c)
		return [ False, None, Util.gen_error(version, ApiError.connectionError(err)) ]
	ConnPool.put(c)

	ret = Util.decode_post(s.getvalue())
	if not ret:
		return [ False, None, Util.gen_error(version, ApiError.badData("Unable to parse response body")) ]
		
	if not Util.status_success(ret):
		return [ False, None, Util.gen_error(version, ApiError.internalApiError(ret[ Constants.STATUS ])) ]
	return [ True, ret[ Constants.RESULT ], None ]

def exec_curl2(version, req, args):
	s = cStringIO.StringIO()
	c = Util.fun_wrapper(req, args)
	c.setopt(pycurl.WRITEFUNCTION, s.write)
	try: