def test_callRemotely_badHost(self) : p = ServiceProxy("http://badhost:80") try : p.callRemotely("service") self.fail("Exception expected") except urllib2.URLError as e : self.assertEqual(e.message, "")
def test_callRemotely_withArg(self) : p = ServiceProxy("http://myhost:80") p.callRemotely("service", a="boo") self.assertEqual(self.query.path,'/service') self.assertEqual(self.query.method,'POST') self.assertEqual(self.params,dict(a='boo'))
def test_callRemotely_noArgs(self) : p = ServiceProxy("http://myhost:80") p.callRemotely("service") self.assertEqual(self.query.path,'/service') self.assertEqual(self.query.method,'POST') self.assertEqual(self.query.params,{})
def test_callRemotely_internalError(self) : p = ServiceProxy("http://myhost:80") try : p.callRemotely("service", error="Message") self.fail("Exception expected") except RemoteError as e : self.assertEqual(e.message, "Message")
def test_callRemotely_internalError(self) : p = ServiceProxy("http://myhost:80") try : p.callRemotely("service", error="Message") self.fail("Exception expected") except urllib2.HTTPError as e : self.assertEqual(e.reason, "Internal Server Error") self.assertEqual(e.read(), "Message") self.assertEqual(e.getcode(), 500)
def test_callRemotely_notFoundError(self) : p = ServiceProxy("http://myhost") try : p.callRemotely("service", notfound="Message") self.fail("Exception expected") except urllib2.HTTPError as e : self.assertEqual(e.reason, "Not found") self.assertEqual(e.read(), "Message") self.assertEqual(e.getcode(), 404)
async def master_socket_handler(loop, master_socket): while True: sock, _ = await loop.sock_accept(master_socket) try: ServiceProxy(sock, service_type, target, loop) except ConnectionRefusedError as e: logger.warning("%s: %s", e, target) sock.close()
if args.net: target = args.net.split(':', 2) target[1] = int(target[1]) target = tuple(target) service_type = 'net' else: target = args.cmd service_type = 'cmd' logger.info(args) master_socket = socket.socket() master_socket.setblocking(0) master_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) master_socket.bind(('127.0.0.1', args.port)) master_socket.listen(1000) loop = BushLoop() ServiceProxy.set_chunk_size(args.chunk_size) ServiceProxy.update_patterns(args.patterns) def evaler(): cmd = sys.stdin.readline() code = compile(cmd, '<input>', 'single') eval(code, globals(), globals()) loop.add_reader(sys.stdin.fileno(), evaler) loop.run_until_complete(master_socket_handler(loop, master_socket))
def test_callRemotely_withIntArgs(self) : p = ServiceProxy("http://myhost:80") p.callRemotely("service", a=1) self.assertEqual(self.query.path,'/service') self.assertEqual(self.params,dict(a=1))
def test_callRemotely_returnsText(self) : p = ServiceProxy("http://myhost:80") result = p.callRemotely("service") self.assertEqual(result, "Hola")
def test_callRemotely_anouncesAsUserAgent(self) : p = ServiceProxy("http://myhost:80") p.callRemotely("service") self.assertEqual(self.query.user_agent, "python-service-proxy/1.0")