Python xmlrpc.client.ServerProxy() Examples
The following are 30
code examples of xmlrpc.client.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
xmlrpc.client
, or try the search function
.
Example #1
Source File: test_xmlrpc.py From ironpython3 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, OSError) as 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 #2
Source File: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_basic(self): # check that flag is false by default flagval = xmlrpc.server.SimpleXMLRPCServer._send_traceback_header self.assertEqual(flagval, False) # enable traceback reporting xmlrpc.server.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, OSError) as 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 #3
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 #4
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 #5
Source File: device_state.py From droidbot with MIT License | 6 votes |
def __get_content_free_state_str(self): if self.device.humanoid is not None: import json from xmlrpc.client import ServerProxy proxy = ServerProxy("http://%s/" % self.device.humanoid) state_str = proxy.render_content_free_view_tree(json.dumps({ "view_tree": self.view_tree, "screen_res": [self.device.display_info["width"], self.device.display_info["height"]] })) else: view_signatures = set() for view in self.views: view_signature = DeviceState.__get_content_free_view_signature(view) if view_signature: view_signatures.add(view_signature) state_str = "%s{%s}" % (self.foreground_activity, ",".join(sorted(view_signatures))) import hashlib return hashlib.md5(state_str.encode('utf-8')).hexdigest()
Example #6
Source File: pypi_repository.py From poet with MIT License | 6 votes |
def search(self, query, mode=0): results = [] search = { 'name': query } if mode == self.SEARCH_FULLTEXT: search['summary'] = query client = ServerProxy(self._url) hits = client.search(search, 'or') for hit in hits: results.append({ 'name': hit['name'], 'description': hit['summary'], 'version': hit['version'] }) return results
Example #7
Source File: serializers.py From koku with GNU Affero General Public License v3.0 | 6 votes |
def update(self, instance, validated_data): """Update a Provider instance from validated data.""" billing_source = validated_data.get("billing_source") authentication = validated_data.get("authentication") try: with ServerProxy(SOURCES_CLIENT_BASE_URL) as sources_client: if billing_source: billing_source = self._update_billing_source(instance, billing_source) sources_client.update_billing_source(instance.source_id, billing_source) if authentication: authentication = self._update_authentication(instance, authentication) sources_client.update_authentication(instance.source_id, authentication) except Fault as error: LOG.error(f"Sources update error: {error}") raise SourcesStorageError(str(error)) except (ConnectionRefusedError, gaierror, ProtocolError) as error: LOG.error(f"Sources update dependency error: {error}") raise SourcesDependencyError(f"Sources-client: {error}") return get_source_instance(instance.source_id)
Example #8
Source File: pypi_repository.py From poet with MIT License | 6 votes |
def find_packages(self, name, constraint=None): packages = [] if constraint is not None: version_parser = VersionParser() constraint = version_parser.parse_constraints(constraint) with ServerProxy(self._url) as client: versions = client.package_releases(name, True) if constraint: versions = constraint.select([Version.coerce(v) for v in versions]) for version in versions: try: packages.append(Package(name, version)) except ValueError: continue return packages
Example #9
Source File: plaso_xmlrpc.py From plaso with Apache License 2.0 | 6 votes |
def Open(self, hostname, port): """Opens a RPC communication channel to the server. Args: hostname (str): hostname or IP address to connect to for requests. port (int): port to connect to for requests. Returns: bool: True if the communication channel was established. """ server_url = 'http://{0:s}:{1:d}'.format(hostname, port) try: self._xmlrpc_proxy = xmlrpclib.ServerProxy( server_url, allow_none=True) except SocketServer.socket.error as exception: logger.warning(( 'Unable to connect to RPC server on {0:s}:{1:d} with error: ' '{2!s}').format(hostname, port, exception)) return False return True
Example #10
Source File: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.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) p("close")() #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 #11
Source File: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.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, OSError) as 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 #12
Source File: test_xmlrpc.py From ironpython3 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': '<class \'exceptions.Exception\'>:' # 'method "this_is_not_exists" is not supported'>}] self.assertEqual(result.results[0]['faultCode'], 1) self.assertEqual(result.results[0]['faultString'], '<class \'Exception\'>:method "this_is_not_exists" ' 'is not supported') except (xmlrpclib.ProtocolError, OSError) as 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: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.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': '<class \'exceptions.Exception\'>:' # 'method "this_is_not_exists" is not supported'>}] self.assertEqual(result.results[0]['faultCode'], 1) self.assertEqual(result.results[0]['faultString'], '<class \'Exception\'>:method "this_is_not_exists" ' 'is not supported') except (xmlrpclib.ProtocolError, OSError) as 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 #14
Source File: device_state.py From droidbot with MIT License | 6 votes |
def __get_state_str_raw(self): if self.device.humanoid is not None: import json from xmlrpc.client import ServerProxy proxy = ServerProxy("http://%s/" % self.device.humanoid) return proxy.render_view_tree(json.dumps({ "view_tree": self.view_tree, "screen_res": [self.device.display_info["width"], self.device.display_info["height"]] })) else: view_signatures = set() for view in self.views: view_signature = DeviceState.__get_view_signature(view) if view_signature: view_signatures.add(view_signature) return "%s{%s}" % (self.foreground_activity, ",".join(sorted(view_signatures)))
Example #15
Source File: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_fail_with_info(self): # use the broken message class xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass # Check that errors in the server send back exception/traceback # info when flag is set xmlrpc.server.SimpleXMLRPCServer._send_traceback_header = True try: p = xmlrpclib.ServerProxy(URL) p.pow(6,8) except (xmlrpclib.ProtocolError, OSError) as 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) else: self.fail('ProtocolError not raised')
Example #16
Source File: test_xmlrpc.py From ironpython3 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) p("close")() #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: _api.py From dephell with MIT License | 6 votes |
def search(self, query: Iterable[str]) -> List[Dict[str, str]]: fields = self._parse_query(query=query) logger.debug('search on PyPI', extra=dict(query=fields)) invalid_fields = set(fields) - _fields if invalid_fields: raise InvalidFieldsError(fields=invalid_fields) with ServerProxy('https://pypi.org/pypi') as client: response = client.search(fields, 'and') results = [] for info in response: results.append(dict( name=info['name'], version=info['version'], description=info['summary'], url='https://pypi.org/project/{}/'.format(info['name']), )) return results
Example #18
Source File: test_xmlrpc.py From ironpython3 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) p("close")() #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 #19
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 #20
Source File: test_xmlrpc.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_introspection3(self): try: # test native doc p = xmlrpclib.ServerProxy(URL) myfunction = p.system.methodHelp('my_function') self.assertEqual(myfunction, 'This is my function') except (xmlrpclib.ProtocolError, OSError) as 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 #21
Source File: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_path1(self): p = xmlrpclib.ServerProxy(URL+"/foo") self.assertEqual(p.pow(6,8), 6**8) self.assertRaises(xmlrpclib.Fault, p.add, 6, 8)
Example #22
Source File: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.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 #23
Source File: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_close(self): p = xmlrpclib.ServerProxy(self.url) self.assertEqual(p('close')(), None)
Example #24
Source File: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.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) p("close")() b = t.response_length self.requestHandler.encode_threshold = old self.assertTrue(a>b)
Example #25
Source File: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.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.assertRaisesRegex(xmlrpclib.ProtocolError, re.compile(r"\b400\b")) with cm: p.pow(6, 8) p("close")()
Example #26
Source File: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.0 | 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) p("close")()
Example #27
Source File: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.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) p("close")() 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 #28
Source File: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_path3(self): p = xmlrpclib.ServerProxy(URL+"/is/broken") self.assertRaises(xmlrpclib.Fault, p.add, 6, 8) #A test case that verifies that a server using the HTTP/1.1 keep-alive mechanism #does indeed serve subsequent requests on the same connection
Example #29
Source File: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_path2(self): p = xmlrpclib.ServerProxy(URL+"/foo/bar") self.assertEqual(p.add(6,8), 6+8) self.assertRaises(xmlrpclib.Fault, p.pow, 6, 8)
Example #30
Source File: test_xmlrpc.py From ironpython3 with Apache License 2.0 | 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) p("close")()