def test_timeout_cancel(self):
        server = api.tcp_listener(('0.0.0.0', 0))
        bound_port = server.getsockname()[1]

        def client_connected((conn, addr)):
            conn.close()

        def go():
            client = util.tcp_socket()

            desc = greenio.GreenSocket(client)
            desc.connect(('127.0.0.1', bound_port))
            try:
                api.trampoline(desc, read=True, write=True, timeout=0.1)
            except api.TimeoutError:
                assert False, "Timed out"

            server.close()
            client.close()

        api.call_after(0, go)

        api.tcp_server(server, client_connected)

        check_hub()
Exemple #2
0
    def test_timeout_cancel(self):
        server = api.tcp_listener(('0.0.0.0', 0))
        bound_port = server.getsockname()[1]

        def client_connected((conn, addr)):
            conn.close()

        def go():
            client = util.tcp_socket()

            desc = greenio.GreenSocket(client)
            desc.connect(('127.0.0.1', bound_port))
            try:
                api.trampoline(desc, read=True, write=True, timeout=0.1)
            except api.TimeoutError:
                assert False, "Timed out"

            server.close()
            client.close()

        api.call_after(0, go)

        api.tcp_server(server, client_connected)

        check_hub()
Exemple #3
0
 def test_pauseresume_producing(self):
     self.conn.pauseProducing()
     call_after(DELAY * 5, self.conn.resumeProducing)
     self.conn.write('hi\r\n')
     result = with_timeout(DELAY * 10,
                           self.conn.read,
                           timeout_value='timed out')
     self.assertEqual('you said hi. BYE', result)
 def test(self):
     try:
         sock = socket.socket()
         api.call_after(0, sock.close)
         sock.connect(('python.org', 81))
     except Exception:
         api.sleep(0)
     else:
         assert False, 'expected an error here'
 def test(self):
     try:
         sock = socket.socket()
         api.call_after(0, sock.close)
         sock.connect(('python.org', 81))
     except Exception:
         api.sleep(0)
     else:
         assert False, 'expected an error here'
Exemple #6
0
def _check_timeout():
	now = time.time()
	for client in _client_queues:
		# if longer then 10 minutes
		if now - _client_queues[client].last > 1000 * 60 * 10:
			# once this is distributed, need to check db to see if we should disconnect client
			login_db.execute("update clients set status='offline', last=? where user=?", (time.time(), _client_queues[client].user))
			login_db.commit()

			del _client_queues[client]
		else:
			login_db.execute("update clients set last=? where user=?", (time.time(), _client_queues[client].user))
			login_db.commit()

	api.call_after(60, _check_timeout)
    def test_server(self):
        connected = []
        server = api.tcp_listener(('0.0.0.0', 0))
        bound_port = server.getsockname()[1]

        def accept_twice((conn, addr)):
            connected.append(True)
            conn.close()
            if len(connected) == 2:
                server.close()

        api.call_after(0, api.connect_tcp, ('127.0.0.1', bound_port))
        api.call_after(0, api.connect_tcp, ('127.0.0.1', bound_port))
        try:
            api.tcp_server(server, accept_twice)
        except:
            api.sleep(0.1)
            raise

        assert len(connected) == 2
        check_hub()
Exemple #8
0
    def test_server(self):
        connected = []
        server = api.tcp_listener(('0.0.0.0', 0))
        bound_port = server.getsockname()[1]

        def accept_twice((conn, addr)):
            connected.append(True)
            conn.close()
            if len(connected) == 2:
                server.close()

        api.call_after(0, api.connect_tcp, ('127.0.0.1', bound_port))
        api.call_after(0, api.connect_tcp, ('127.0.0.1', bound_port))
        try:
            api.tcp_server(server, accept_twice)
        except:
            api.sleep(0.1)
            raise

        assert len(connected) == 2
        check_hub()
 def test_pauseresume_producing(self):
     self.conn.pauseProducing()
     call_after(DELAY*5, self.conn.resumeProducing)
     self.conn.write('hi\r\n')
     result = with_timeout(DELAY*10, self.conn.read, timeout_value='timed out')
     self.assertEqual('you said hi. BYE', result)
Exemple #10
0
def login():
    """ login an to a login endpoint """

    parser = OptionParser(usage="usage: %prog [options] firstname lastname")

    logger = logging.getLogger("client.example")

    parser.add_option(
        "-l",
        "--loginuri",
        dest="loginuri",
        default="https://login.aditi.lindenlab.com/cgi-bin/login.cgi",
        help="specified the target loginuri")
    parser.add_option(
        "-r",
        "--region",
        dest="region",
        default=None,
        help="specifies the region (regionname/x/y/z) to connect to")
    parser.add_option("-q",
                      "--quiet",
                      dest="quiet",
                      default=False,
                      action="store_true",
                      help="log warnings and above (default is debug)")
    parser.add_option("-d",
                      "--verbose",
                      dest="verbose",
                      default=False,
                      action="store_true",
                      help="log info and above (default is debug)")
    parser.add_option(
        "-p",
        "--password",
        dest="password",
        default=None,
        help="specifies password instead of being prompted for one")

    (options, args) = parser.parse_args()

    if len(args) != 2:
        parser.error("Expected 2 arguments")

    (firstname, lastname) = args

    console = logging.StreamHandler()
    formatter = logging.Formatter(
        '%(asctime)-30s%(name)-30s: %(levelname)-8s %(message)s')
    console.setFormatter(formatter)
    logging.getLogger('').addHandler(console)

    # setting the level for the handler above seems to be a no-op
    # it needs to be set for the logger, here the root logger
    # otherwise it is NOTSET(=0) which means to log nothing.
    if options.verbose:
        logging.getLogger('').setLevel(logging.INFO)
    elif options.quiet:
        logging.getLogger('').setLevel(logging.WARNING)
    else:
        logging.getLogger('').setLevel(logging.DEBUG)

    # example from a pure agent perspective

    #grab a password!
    if options.password:
        password = options.password
    else:
        password = getpass.getpass()

    # prep instance settings
    settings = Settings()

    settings.ENABLE_INVENTORY_MANAGEMENT = False
    settings.ENABLE_COMMUNICATIONS_TRACKING = False
    settings.ENABLE_OBJECT_TRACKING = False
    settings.ENABLE_UDP_LOGGING = True
    settings.ENABLE_EQ_LOGGING = True
    settings.ENABLE_CAPS_LOGGING = True
    settings.MULTIPLE_SIM_CONNECTIONS = False

    #First, initialize the agent
    client = Agent(settings)

    # Now let's log it in
    api.spawn(client.login,
              options.loginuri,
              firstname,
              lastname,
              password,
              start_location=options.region,
              connect_region=True)

    # wait for the agent to connect to it's region
    while client.connected == False:
        api.sleep(0)

    while client.region.connected == False:
        api.sleep(0)

    print "Requesting offline messages..."
    fetch_offline_ims(client)

    # NOTE: No indication of complete, so just give the process 2 seconds
    api.call_after(2, client.logout)

    while client.running:
        api.sleep(0)
 def func():
     call_after(0.1, self.lst.pop)
 def func():
     call_after(0.1, self.lst.pop)