def projects_matching_classifier(classifier): """Find all projects matching the specified trove classifier.""" client = xmlrpc.client.ServerProxy('http://pypi.python.org/pypi') try: logging.info('Fetching project list for {!r}'.format(classifier)) return (result[0].lower() for result in client.browse([classifier])) finally: client('close')()
def __init__(self, xmlrpc_server, fetch_increment=200): SearchEngine.__init__(self) if _use_pyxmlrpc: (host, port) = xmlrpc_server.split(':') self._server = client(host, int(port)) else: self._server = Server("http://" + xmlrpc_server) self._fetch_increment = fetch_increment
def __init__(self, host, port, timeout=-1.0): self.host = host # host self.port = port # server port self.timeout = timeout # xmlrpc timeout self.client = xmlrpc.client(host, port) xmlrpc.setLogLevel(LOG_LEVEL) self.cmds = self.__talk__('getclient') if not self.cmds: raise ClientError, 'could not get command list'
def exampleActiveFds(): i = 0 c = xmlrpc.client('localhost', PORT, '/blah') c.nbExecute('echo', ['hello', 'world'], activeFdCall, i) c.work(0.0) while 1: (inFd, outFd, excFd) = c.activeFds() select.select(inFd, outFd, excFd) c.work(0.0)
def exampleFault(): try: c = xmlrpc.client('localhost', PORT, '/blah') print c.execute('fault', ['Hello, World!']) except xmlrpc.fault: f = sys.exc_value sys.stderr.write('xmlrpc fault occurred:\n') sys.stderr.write('faultCode is: %s\n' % f.faultCode) sys.stderr.write('faultString is: %s\n' % f.faultString) traceback.print_exc() sys.exit(1)
def __talk__(self, command, *args): args = filter(lambda x,y=NONE: (x is not y), args) if not self.client: raise ClientError, ERR_CLOSE try: return self.client.execute(command, args, timeout=self.timeout) except: self.client = xmlrpc.client(self.host, self.port) return self.client.execute(command, args, timeout=self.timeout)
from xmlrpc import client return client.ServerProxy('http://localhost:%d' % SERVER_PORT) if __name__ == "__main__": from argparse import ArgumentParser parser = ArgumentParser() parser.add_argument('-l', '--list', action='store_true') parser.add_argument('-r', '--running', action='store_true') parser.add_argument('-s', '--start') parser.add_argument('-t', '--stop', type=int) parser.add_argument('-k', '--kill', type=int) parser.add_argument('--log', type=int) args = parser.parse_args() c = client() if args.list: print('Available games:') for n in c.games(): print(' * ', n) if args.running: print('Running games:') for n in c.runningGames(): print(' * ', n) if args.start is not None: print(c.startGame(args.start)) if args.stop is not None: print(c.stopGame(args.stop))
class XMLRPCCall: """Single XML-RPC Calling A simple variante of the XMLRPCClient which handles the setup of the Config class. Use these steps: 1.) Create an instance: client = XMLRPCCall () # this class supports several keyword arguments: # - server (str), default '127.0.0.1': the server to connect to # - port (int), default 8080: the port to connect to the server # - secure (bool), default False: if True use SSL # - path (str), default None: the path to access the XML-RPC universe # - user (str), default None: username for basic authentication # - passwd (str), default None: password for basic authentication # - allow_none (bool), default False: if True, allow None as valid value # - use_datetime (bool), default False: if True, allow datetime.datetime as valid value # - timeout (float), default 2.0: Timeout for communication to the server # - silent (bool), default False: if used as a context manager, control propagation of an exception during execution # - callback (callable), default None: if used as a context manager, call this callable with the exception information, if an exception occurs 2.) Use the instance: client ().some_remote_method () 3.) Or used as a context manager: with XMLRPCCall () as client: client ().some_remote_method () """ __slots__ = ['remote', 'timeout', 'otimeout', 'silent', 'callback'] def __init__ (self, server: str = '127.0.0.1', port: int = 8080, secure: bool = False, path: Optional[str] = None, user: Optional[str] = None, passwd: Optional[str] = None, allow_none: bool = False, use_datetime: bool = False, timeout: Optional[float] = 2.0, silent: bool = False, callback: Optional[Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], bool]] = None ) -> None: prefix = 'xmlrpc-call' cfg = Config () cfg[f'{prefix}.host'] = server cfg[f'{prefix}.port'] = str (port) cfg[f'{prefix}.secure'] = str (secure) if path: cfg[f'{prefix}.path'] = path if user and passwd: cfg[f'{prefix}.user'] = user cfg[f'{prefix}.passwd'] = passwd cfg[f'{prefix}.allow_none'] = str (allow_none) cfg[f'{prefix}.use_datetime'] = str (use_datetime) self.remote = XMLRPCClient (cfg, prefix) self.timeout = timeout self.otimeout: Optional[float] = None self.silent = silent self.callback = callback def __enter__ (self) -> XMLRPCCall: self.otimeout = socket.getdefaulttimeout () socket.setdefaulttimeout (self.timeout) return self def __exit__ (self, exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], traceback: Optional[TracebackType]) -> Optional[bool]: socket.setdefaulttimeout (self.otimeout) rc = self.silent if self.callback is not None: rc = self.callback (exc_type, exc_value, traceback) return rc def __call__ (self) -> XMLRPCClient: return self.remote
def examplePostpone(): c = xmlrpc.client('localhost', PORT, '/blah') print c.execute('postpone', ['Hello, World!'])
def exampleClient(): c = xmlrpc.client('localhost', PORT, '/blah') print c.execute('echo', [u'X & ; : > < X'])
def exampleAuthClient(): c = xmlrpc.client('localhost', PORT, '/blah') print c.execute('echo', ['Hello, World!'], 1.0, TEST_NAME, TEST_PASS)
from xmlrpc import client from datetime import datetime, timedelta if __name__=='__main__': calls = 10000 # server = Server("http://localhost:4000"); server = client("localhost", 4000); start_time = datetime.utcnow() x = 1; while x <= calls: # y = server.test.go(x); y = server.execute("test.go", [x]) print "%s -> %s" % (x,y) x += 1 elapsed_seconds = max((datetime.utcnow()-start_time).seconds, 1) print "---------------------------------------------------" print "%s calls in %s seconds => %s calls/sec" % (calls, elapsed_seconds, float(calls) / float(elapsed_seconds))
print("Server error :(\n") print("Try again!\n") return elif (ret_list[0] == "Error" and ret_list[1]): print(f"Error: {ret_list[1]}\n") return else: if (not resultdict): x = 1 else: x = len(resultdict) + 1 resultdict[x] = ret_list print("PATH FOUND!\n") print(f">>Result<<\n {ret_list[0]} in {ret_list[1]}\n") if __name__ == "__main__": # Fancy animation + connection check print("\nStarting WikiFinder™...") for i in tqdm(range(4)): time.sleep(0.23) print("\n\n") try: s = xmlrpc.client.ServerProxy('http://127.0.0.1:7999') if (s.up(1)): client() except Exception as e: print("\nCannot currently connect to the server, try again later!\n") print(e)
def reconnect(self): self.client = xmlrpc.client(self.host, self.port)
def exampleNbClient(): c = xmlrpc.client('localhost', PORT) r = c.nbExecute('echo', ['hello', 'world'], callback, 'Extra Args') c.work(10)
import xmlrpc.client import time import random import sys class client(): def __init__(self, server, port, access, cid): self.server_host = server self.port = int(port) self.access = int(access) self.id = int(cid) self.log = "Client type: Reader \nClient Name: " + str(self.id) + "\nrSeq sSeq oVal \n\n" self.con = xmlrpc.client.ServerProxy('http://' + server + ':' + port, allow_none=True) def run(self): for i in range(self.access): rv = self.con.read(self.id) if rv: self.log += str(rv[1]) + " " + str(rv[1]) + " " + str(rv[0]) + "\n" secs = random.randint(0, 10) time.sleep(secs) fo = open("log" + str(self.id), "w") fo.write(self.log) fo.close() if __name__ == '__main__': my_client = client(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]) print('reader ' + sys.argv[4]) my_client.run()
#!/usr/local/bin/python2.0 -O import sys import xmlrpc if len(sys.argv) != 3: sys.stderr.write('usage: %s host port\n' % sys.argv[0]) sys.exit(0) host = sys.argv[1] port = int(sys.argv[2]) c = xmlrpc.client(host, port) xmlrpc.setLogLevel(0) print c.execute('kill', []) c = None