Python xmlrpclib.ServerProxy() Examples
The following are 30
code examples of xmlrpclib.ServerProxy().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
xmlrpclib
, or try the search function
.
Example #1
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 6 votes |
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)
Example #2
Source File: test_fetcher.py From pyspider with Apache License 2.0 | 6 votes |
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'
Example #3
Source File: test_xmlrpc.py From BinderFilter with MIT License | 6 votes |
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)
Example #4
Source File: test_xmlrpc.py From BinderFilter with MIT License | 6 votes |
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", "")))
Example #5
Source File: test_xmlrpc.py From BinderFilter with MIT License | 6 votes |
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", "")))
Example #6
Source File: test_xmlrpc.py From BinderFilter with MIT License | 6 votes |
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", "")))
Example #7
Source File: OpenNebula.py From im with GNU General Public License v3.0 | 6 votes |
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)
Example #8
Source File: get_list_available_pkgs.py From incubator-dlab with Apache License 2.0 | 6 votes |
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)
Example #9
Source File: conftest.py From Flask-Large-Application-Example with MIT License | 6 votes |
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.
Example #10
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 6 votes |
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)
Example #11
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 6 votes |
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
Example #12
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 6 votes |
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", "")))
Example #13
Source File: supervisorclient.py From minemeld-core with Apache License 2.0 | 6 votes |
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
Example #14
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 6 votes |
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", "")))
Example #15
Source File: tests.py From pyroma with MIT License | 6 votes |
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
Example #16
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 6 votes |
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.
Example #17
Source File: OpenNebula.py From im with GNU General Public License v3.0 | 6 votes |
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
Example #18
Source File: supervisorapi.py From minemeld-core with Apache License 2.0 | 5 votes |
def _restart_engine(): LOG.info('Restarting minemeld-engine') 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 ) ) try: result = sserver.supervisor.stopProcess('minemeld-engine', False) if not result: LOG.error('Stop minemeld-engine returned False') return except xmlrpclib.Fault as e: LOG.error('Error stopping minemeld-engine: {!r}'.format(e)) LOG.info('Stopped minemeld-engine for API request') now = time.time() info = None while (time.time()-now) < 60*10*1000: info = sserver.supervisor.getProcessInfo('minemeld-engine') if info['statename'] in ('FATAL', 'STOPPED', 'UNKNOWN', 'EXITED'): break gevent.sleep(5) else: LOG.error('Timeout during minemeld-engine restart') return sserver.supervisor.startProcess('minemeld-engine', False) LOG.info('Started minemeld-engine')
Example #19
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_bad_gzip_request(self): t = self.Transport() t.encode_threshold = None t.fake_gzip = True p = xmlrpclib.ServerProxy(URL, transport=t) cm = self.assertRaisesRegexp(xmlrpclib.ProtocolError, re.compile(r"\b400\b")) with cm: p.pow(6, 8)
Example #20
Source File: test_xmlrpc.py From BinderFilter with MIT License | 5 votes |
def test_bad_gzip_request(self): t = self.Transport() t.encode_threshold = None t.fake_gzip = True p = xmlrpclib.ServerProxy(URL, transport=t) cm = self.assertRaisesRegexp(xmlrpclib.ProtocolError, re.compile(r"\b400\b")) with cm: p.pow(6, 8)
Example #21
Source File: test_xmlrpc.py From BinderFilter with MIT License | 5 votes |
def test_transport(self): t = xmlrpclib.Transport() p = xmlrpclib.ServerProxy(self.url, transport=t) self.assertEqual(p('transport'), t) # This is a contrived way to make a failure occur on the server side # in order to test the _send_traceback_header flag on the server
Example #22
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_transport(self): p = xmlrpclib.ServerProxy(URL) #do some requests with close. self.assertEqual(p.pow(6,8), 6**8) p("transport").close() #same as above, really. self.assertEqual(p.pow(6,8), 6**8) self.assertEqual(len(self.RequestHandler.myRequests), 2) #A test case that verifies that gzip encoding works in both directions #(for a request and the response)
Example #23
Source File: test_xmlrpc.py From BinderFilter with MIT License | 5 votes |
def test_fail_no_info(self): # use the broken message class SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass 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"): # The two server-side error headers shouldn't be sent back in this case self.assertTrue(e.headers.get("X-exception") is None) self.assertTrue(e.headers.get("X-traceback") is None)
Example #24
Source File: test_xmlrpc.py From BinderFilter with MIT License | 5 votes |
def test_gsip_response(self): t = self.Transport() p = xmlrpclib.ServerProxy(URL, transport=t) old = self.requestHandler.encode_threshold self.requestHandler.encode_threshold = None #no encoding self.assertEqual(p.pow(6,8), 6**8) a = t.response_length self.requestHandler.encode_threshold = 0 #always encode self.assertEqual(p.pow(6,8), 6**8) b = t.response_length self.requestHandler.encode_threshold = old self.assertTrue(a>b) #Test special attributes of the ServerProxy object
Example #25
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_close(self): p = xmlrpclib.ServerProxy(self.url) self.assertEqual(p('close')(), None)
Example #26
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_transport(self): t = xmlrpclib.Transport() p = xmlrpclib.ServerProxy(self.url, transport=t) self.assertEqual(p('transport'), t) # This is a contrived way to make a failure occur on the server side # in order to test the _send_traceback_header flag on the server
Example #27
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_fail_no_info(self): # use the broken message class SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass 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"): # The two server-side error headers shouldn't be sent back in this case self.assertTrue(e.headers.get("X-exception") is None) self.assertTrue(e.headers.get("X-traceback") is None)
Example #28
Source File: test_xmlrpc.py From BinderFilter with MIT License | 5 votes |
def test_gzip_request(self): t = self.Transport() t.encode_threshold = None p = xmlrpclib.ServerProxy(URL, transport=t) self.assertEqual(p.pow(6,8), 6**8) a = self.RequestHandler.content_length t.encode_threshold = 0 #turn on request encoding self.assertEqual(p.pow(6,8), 6**8) b = self.RequestHandler.content_length self.assertTrue(a>b)
Example #29
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 5 votes |
def issue_request(self, transport_class): """Return an HTTP request made via transport_class.""" transport = transport_class() proxy = xmlrpclib.ServerProxy("http://example.com/", transport=transport) try: proxy.pow(6, 8) except RuntimeError: return transport.fake_socket.getvalue() return None
Example #30
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_gzip_response(self): t = self.Transport() p = xmlrpclib.ServerProxy(URL, transport=t) old = self.requestHandler.encode_threshold self.requestHandler.encode_threshold = None #no encoding self.assertEqual(p.pow(6,8), 6**8) a = t.response_length self.requestHandler.encode_threshold = 0 #always encode self.assertEqual(p.pow(6,8), 6**8) b = t.response_length self.requestHandler.encode_threshold = old self.assertTrue(a>b)