示例#1
0
	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, "")
示例#2
0
	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'))
示例#3
0
	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,{})
示例#4
0
	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")
示例#5
0
	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)
示例#6
0
	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)
示例#7
0
文件: bubaxy.py 项目: Enr1g/bubaxy
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()
示例#8
0
文件: bubaxy.py 项目: Enr1g/bubaxy
    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))
示例#9
0
	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))
示例#10
0
	def test_callRemotely_returnsText(self) :
		p = ServiceProxy("http://myhost:80")
		result = p.callRemotely("service")
		self.assertEqual(result, "Hola")
示例#11
0
	def test_callRemotely_anouncesAsUserAgent(self) :
		p = ServiceProxy("http://myhost:80")
		p.callRemotely("service")

		self.assertEqual(self.query.user_agent,
			"python-service-proxy/1.0")