本文整理汇总了Python中xmlrpclib.ServerProxy方法的典型用法代码示例。如果您正苦于以下问题:Python xmlrpclib.ServerProxy方法的具体用法?Python xmlrpclib.ServerProxy怎么用?Python xmlrpclib.ServerProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmlrpclib
的用法示例。
在下文中一共展示了xmlrpclib.ServerProxy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_distribute
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def test_distribute(self):
real_urlopen = urllib.urlopen
real_server_proxy = xmlrpclib.ServerProxy
try:
xmlrpclib.ServerProxy = ProxyStub(
"distributedata.py", xmlrpclib.ServerProxy, False
)
urllib.urlopen = urlopenstub
data = pypidata.get_data("distribute")
rating = rate(data)
self.assertEqual(
rating,
(
9,
[
"The classifiers should specify what minor versions of Python "
"you support as well as what major version.",
"You should have three or more owners of the project on PyPI.",
],
),
)
finally:
xmlrpclib.ServerProxy = real_server_proxy
urllib.urlopen = real_urlopen
示例2: setUpClass
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def setUpClass(self):
import tests.data_test_webpage
import httpbin
self.httpbin_thread = utils.run_in_subprocess(httpbin.app.run, host='0.0.0.0', port=14887, passthrough_errors=False)
self.httpbin = 'http://' + socket.gethostbyname(socket.gethostname()) + ':14887'
self.inqueue = Queue(10)
self.outqueue = Queue(10)
self.fetcher = Fetcher(self.inqueue, self.outqueue)
self.fetcher.splash_endpoint = 'http://127.0.0.1:8050/execute'
self.rpc = xmlrpc_client.ServerProxy('http://localhost:%d' % 24444)
self.xmlrpc_thread = utils.run_in_thread(self.fetcher.xmlrpc_run, port=24444)
self.thread = utils.run_in_thread(self.fetcher.run)
self.proxy_thread = subprocess.Popen(['pyproxy', '--username=binux', '--bind=0.0.0.0',
'--password=123456', '--port=14830',
'--debug'], close_fds=True)
self.proxy = socket.gethostbyname(socket.gethostname()) + ':14830'
示例3: attach_volume
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def attach_volume(self, vm, disk_size, disk_device, disk_fstype, session_id):
server = ServerProxy(self.server_url, allow_none=True)
disk_temp = '''
DISK = [
TYPE = fs ,
FORMAT = %s,
SIZE = %d,
TARGET = %s,
SAVE = no
]
''' % (disk_fstype, disk_size, disk_device)
success, res_info = server.one.vm.attach(session_id, int(vm.id), disk_temp, False)[0:2]
if success:
return (True, "")
else:
return (False, res_info)
示例4: delete_image
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def delete_image(self, image_url, auth_data):
server = ServerProxy(self.server_url, allow_none=True)
session_id = self.getSessionID(auth_data)
if session_id is None:
return (False, "Incorrect auth data, username and password must be specified for OpenNebula provider.")
image_id = self.get_image_id(image_url, session_id)
if image_id is None:
return (False, "Incorrect image name or id specified.")
# Wait the image to be READY (not USED)
success, msg = self.wait_image(image_id, auth_data)
if not success:
self.logger.warn("Error waiting image to be READY: " + msg)
success, res_info = server.one.image.delete(session_id, image_id)[0:2]
if success:
return (True, "")
else:
return (False, res_info)
示例5: get_image_id
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def get_image_id(self, image_url, session_id):
url = urlparse(image_url)
image_id = url[2][1:]
if image_id.isdigit():
return int(image_id)
else:
# We have to find the ID of the image name
server = ServerProxy(self.server_url, allow_none=True)
success, res_info = server.one.imagepool.info(session_id, -2, -1, -1)[0:2]
if success:
pool_info = IMAGE_POOL(res_info)
else:
self.logger.error("Error in the function one.imagepool.info: " + res_info)
return None
for image in pool_info.IMAGE:
if image.NAME == image_id:
return image.ID
return None
示例6: alter_xmlrpc
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def alter_xmlrpc(request):
"""Replaces the ServerProxy class in the xmlrpclib library with a fake class.
Class is restored after testing.
"""
old_method = xmlrpclib.ServerProxy
xmlrpclib.ServerProxy = FakeServerProxy
def func(value):
FakeServerProxy.VALUE = value
def fin():
xmlrpclib.ServerProxy = old_method
request.addfinalizer(fin)
return func
# Initialize the application and sets the app context to avoid needing 'with app.app_context():'.
# This must happen before any Celery tasks are imported automatically by py.test during test discovery.
示例7: test_multicall
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def test_multicall(self):
try:
p = xmlrpclib.ServerProxy(URL)
multicall = xmlrpclib.MultiCall(p)
multicall.add(2,3)
multicall.pow(6,8)
multicall.div(127,42)
add_result, pow_result, div_result = multicall()
self.assertEqual(add_result, 2+3)
self.assertEqual(pow_result, 6**8)
self.assertEqual(div_result, 127//42)
except (xmlrpclib.ProtocolError, socket.error), e:
# ignore failures due to non-blocking socket 'unavailable' errors
if not is_unavailable_exception(e):
# protocol error; provide additional information in test output
self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
示例8: test_non_existing_multicall
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def test_non_existing_multicall(self):
try:
p = xmlrpclib.ServerProxy(URL)
multicall = xmlrpclib.MultiCall(p)
multicall.this_is_not_exists()
result = multicall()
# result.results contains;
# [{'faultCode': 1, 'faultString': '<type \'exceptions.Exception\'>:'
# 'method "this_is_not_exists" is not supported'>}]
self.assertEqual(result.results[0]['faultCode'], 1)
self.assertEqual(result.results[0]['faultString'],
'<type \'exceptions.Exception\'>:method "this_is_not_exists" '
'is not supported')
except (xmlrpclib.ProtocolError, socket.error), e:
# ignore failures due to non-blocking socket 'unavailable' errors
if not is_unavailable_exception(e):
# protocol error; provide additional information in test output
self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
示例9: test_two
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def test_two(self):
p = xmlrpclib.ServerProxy(URL)
#do three requests.
self.assertEqual(p.pow(6,8), 6**8)
self.assertEqual(p.pow(6,8), 6**8)
self.assertEqual(p.pow(6,8), 6**8)
#they should have all been handled by a single request handler
self.assertEqual(len(self.RequestHandler.myRequests), 1)
#check that we did at least two (the third may be pending append
#due to thread scheduling)
self.assertGreaterEqual(len(self.RequestHandler.myRequests[-1]), 2)
#test special attribute access on the serverproxy, through the __call__
#function.
示例10: test_close
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def test_close(self):
p = xmlrpclib.ServerProxy(URL)
#do some requests with close.
self.assertEqual(p.pow(6,8), 6**8)
self.assertEqual(p.pow(6,8), 6**8)
self.assertEqual(p.pow(6,8), 6**8)
p("close")() #this should trigger a new keep-alive request
self.assertEqual(p.pow(6,8), 6**8)
self.assertEqual(p.pow(6,8), 6**8)
self.assertEqual(p.pow(6,8), 6**8)
#they should have all been two request handlers, each having logged at least
#two complete requests
self.assertEqual(len(self.RequestHandler.myRequests), 2)
self.assertGreaterEqual(len(self.RequestHandler.myRequests[-1]), 2)
self.assertGreaterEqual(len(self.RequestHandler.myRequests[-2]), 2)
示例11: test_gzip_decode_limit
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def test_gzip_decode_limit(self):
max_gzip_decode = 20 * 1024 * 1024
data = '\0' * max_gzip_decode
encoded = xmlrpclib.gzip_encode(data)
decoded = xmlrpclib.gzip_decode(encoded)
self.assertEqual(len(decoded), max_gzip_decode)
data = '\0' * (max_gzip_decode + 1)
encoded = xmlrpclib.gzip_encode(data)
with self.assertRaisesRegexp(ValueError,
"max gzipped payload length exceeded"):
xmlrpclib.gzip_decode(encoded)
xmlrpclib.gzip_decode(encoded, max_decode=-1)
#Test special attributes of the ServerProxy object
示例12: test_fail_with_info
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def test_fail_with_info(self):
# use the broken message class
SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass
# Check that errors in the server send back exception/traceback
# info when flag is set
SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True
try:
p = xmlrpclib.ServerProxy(URL)
p.pow(6,8)
except (xmlrpclib.ProtocolError, socket.error), e:
# ignore failures due to non-blocking socket 'unavailable' errors
if not is_unavailable_exception(e) and hasattr(e, "headers"):
# We should get error info in the response
expected_err = "invalid literal for int() with base 10: 'I am broken'"
self.assertEqual(e.headers.get("x-exception"), expected_err)
self.assertTrue(e.headers.get("x-traceback") is not None)
示例13: get_Supervisor
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def get_Supervisor():
sserver = getattr(g, '_supervisor', None)
if sserver is None:
supervisorurl = config.get('SUPERVISOR_URL',
'unix:///var/run/supervisor.sock')
sserver = xmlrpclib.ServerProxy(
'http://127.0.0.1',
transport=supervisor.xmlrpc.SupervisorTransport(
None,
None,
supervisorurl
)
)
g._supervisor = sserver
return sserver
示例14: get_available_pip_pkgs
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def get_available_pip_pkgs(version):
try:
for _ in range(100):
pip_pkgs = dict()
client = xmlrpclib.ServerProxy('https://pypi.python.org/pypi')
raw_pkgs = client.browse(["Programming Language :: Python :: " + version + ""])
all_pkgs = [i[0] for i in raw_pkgs]
if len(all_pkgs) != 0:
for pkg in all_pkgs:
pip_pkgs[pkg] = "N/A"
return pip_pkgs
else:
local('sleep 5')
continue
except Exception as err:
print('Error: {0}'.format(err))
sys.exit(1)
示例15: test_basic
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ServerProxy [as 别名]
def test_basic(self):
# check that flag is false by default
flagval = SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header
self.assertEqual(flagval, False)
# enable traceback reporting
SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True
# test a call that shouldn't fail just as a smoke test
try:
p = xmlrpclib.ServerProxy(URL)
self.assertEqual(p.pow(6,8), 6**8)
except (xmlrpclib.ProtocolError, socket.error), e:
# ignore failures due to non-blocking socket 'unavailable' errors
if not is_unavailable_exception(e):
# protocol error; provide additional information in test output
self.fail("%s\n%s" % (e, getattr(e, "headers", "")))