def __init__(self, buffer_id, url):
        Buffer.__init__(self, buffer_id, url, False, QColor(255, 255, 255, 255))

        self.add_widget(BrowserWidget())
        self.buffer_widget.setUrl(QUrl(url))
        self.buffer_widget.titleChanged.connect(self.change_title)
        self.buffer_widget.web_page.open_url_in_new_tab.connect(self.open_url)
Beispiel #2
0
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict,
                 module_path, call_emacs):
        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict,
                        module_path, call_emacs, True)

        self.add_widget(QPushButton("Hello, EAF hacker, it's working!!!"))
        self.buffer_widget.setStyleSheet("font-size: 100px")
Beispiel #3
0
        def client_connect_handler(socket):
            tu.check_context()
            sends = 10
            size = 100

            sent = Buffer.create()
            received = Buffer.create()

            @socket.data_handler
            def data_handler(data):
                tu.check_context()
                received.append_buffer(data)
                if received.length == sends * size:
                    tu.azzert(TestUtils.buffers_equal(sent, received))
                    tu.test_complete()

            @socket.drain_handler
            def drain_handler(stream):
                tu.check_context()
                #print "drained\n"

            @socket.end_handler
            def end_handler(stream):
                tu.check_context()
                #print "end\n"

            socket.pause()
            socket.resume()
            socket.write_queue_full
            socket.write_queue_max_size = 100000

            for i in range(0, sends):
                data = TestUtils.gen_buffer(size)
                sent.append_buffer(data)
                socket.write_buffer(data)
Beispiel #4
0
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict):
        dumper(["it's dumping time 2"])

        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict, True,
                        QColor(0, 0, 0, 255))
        # Buffer.__init__(self, buffer_id, url, arguments, True, QColor(0, 0, 0, 255))

        # def __init__(self, buffer_id, url, arguments):

        # with open("/tmp/eaf3.csv", "a") as fo:
        #     wr = csv.writer(fo)
        #     wr.writerow(["runs_now"])

        self.update()

        dumper(list(self.emacs_var_dict.keys()))
        dumper(["it's dumping time 3"])

        self.add_widget(ob_viz(QColor(0, 0, 0, 255)))

        dumper(["it's dumping time 4"])
        self.timer = QTimer(self, timeout=self.update_demo, interval=40)
        self.timer.start()

        self.reload_timer = 0

        self.edge_string = ""
        self.cur_node = ""

        self.update()
    def __init__(self, buffer_id, url, arguments, fit_to_view,
                 background_color):
        Buffer.__init__(self, buffer_id, url, arguments, fit_to_view,
                        background_color)

        self.add_widget(BrowserView())

        self.buffer_widget.loadStarted.connect(self.start_progress)
        self.buffer_widget.loadProgress.connect(self.update_progress)
        self.buffer_widget.loadFinished.connect(self.stop_progress)

        self.buffer_widget.web_page.windowCloseRequested.connect(
            self.request_close_buffer)

        self.search_term = ""

        with open(
                os.path.join(os.path.dirname(__file__), "js",
                             "get_markers.js"), "r") as f:
            self.get_markers_js = f.read()

        with open(
                os.path.join(os.path.dirname(__file__), "js",
                             "goto_marker.js"), "r") as f:
            self.goto_marker_raw = f.read()
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path):
        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict, module_path, True)

        self.add_widget(VideoPlayerWidget())
        self.buffer_widget.play(url)

        self.build_all_methods(self.buffer_widget)
Beispiel #7
0
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict):
        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict, False,
                        QColor(0, 0, 0, 255))

        self.add_widget(PdfViewerWidget(url, config_dir, QColor(0, 0, 0, 255)))
        self.buffer_widget.translate_double_click_word.connect(
            self.translate_text)
Beispiel #8
0
        def client_connect_handler(socket):
            tu.check_context()
            sends = 10
            size = 100

            sent = Buffer.create()
            received = Buffer.create()

            @socket.data_handler
            def data_handler(data):
                tu.check_context()
                received.append_buffer(data)
                if received.length == sends * size:
                    tu.azzert(TestUtils.buffers_equal(sent, received))
                    tu.test_complete()
            @socket.drain_handler
            def drain_handler(stream):
                tu.check_context()
                #print "drained\n"

            @socket.end_handler
            def end_handler(stream):
                tu.check_context()
                #print "end\n"

            socket.pause()
            socket.resume()
            socket.write_queue_full
            socket.write_queue_max_size = 100000

            for i in range(0, sends):
                data = TestUtils.gen_buffer(size)
                sent.append_buffer(data)
                socket.write_buffer(data)
    def __init__(self, buffer_id, url, arguments):
        Buffer.__init__(self, buffer_id, url, arguments, False,
                        QColor(0, 0, 0, 255))

        self.add_widget(PdfViewerWidget(url, QColor(0, 0, 0, 255)))
        self.buffer_widget.send_input_message = self.send_input_message
        self.buffer_widget.translate_double_click_word.connect(
            self.translate_text)
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path):
        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict, module_path, False)

        self.background_color = QColor(0, 0, 0)

        arguments_dict = json.loads(arguments)

        self.add_widget(GitViewerWidget(buffer_id, config_dir, arguments_dict["directory"]))
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict,
                 module_path):
        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict,
                        module_path, True)

        self.background_color = QColor(0, 0, 0)

        self.add_widget(CameraWidget(QColor(0, 0, 0, 255)))
    def __init__(self, buffer_id, url, arguments):
        Buffer.__init__(self, buffer_id, url, arguments, False)

        self.background_color = QColor(get_emacs_var("eaf-emacs-theme-background-color"))

        self.add_widget(FileTransferWidget(url,
                                           get_emacs_var("eaf-emacs-theme-background-color"),
                                           get_emacs_var("eaf-emacs-theme-foreground-color")))
Beispiel #13
0
    def __init__(self, buffer_id, url):
        Buffer.__init__(self, buffer_id, url, False,
                        QColor(255, 255, 255, 255))

        self.url = url
        self.add_widget(BrowserWidget())

        self.load_org_html_file()
class Learner:
	"""Learner object encapsulating a local learner

		Parameters:
		algo_name (str): Algorithm Identifier
		state_dim (int): State size
		action_dim (int): Action size
		actor_lr (float): Actor learning rate
		critic_lr (float): Critic learning rate
		gamma (float): DIscount rate
		tau (float): Target network sync generate
		init_w (bool): Use kaimling normal to initialize?
		**td3args (**kwargs): arguments for TD3 algo


	"""

	def __init__(self, wwid, algo_name, state_dim, action_dim, actor_lr, critic_lr, gamma, tau, init_w = True, **td3args):
		self.td3args = td3args; self.id = id
		self.wwid = wwid
		self.algo = Off_Policy_Algo(wwid, algo_name, state_dim, action_dim, actor_lr, critic_lr, gamma, tau, init_w)
		self.args = td3args['cerl_args']

		#LEARNER STATISTICS
		self.fitnesses = []
		self.ep_lens = []
		self.value = None
		self.visit_count = 0
		self.private_replay_buffer = Buffer(1000000, self.args.buffer_gpu)   #

	def share_memory(self):
		self.algo.share_memory()

	def act(self, state, eps=None): #eps not used, to have common interface with dqn.act
		return self.algo.act(state)

	def step(self, state, action, reward, next_state, done):  #for training blue agent, add experience to reply buffer, and do one learning iteration
		self.private_replay_buffer.add(state, action, reward, next_state, done)
		self.update_parameters(self.private_replay_buffer, self.args.buffer_gpu, self.args.batch_size, iterations=1)

	def save_net(self, path):
		self.algo.save_net(path)

	def update_parameters(self, replay_buffer, buffer_gpu, batch_size, iterations):
		for _ in range(iterations):
			s, ns, a, r, done = replay_buffer.sample(batch_size)
			if not buffer_gpu and torch.cuda.is_available():
				s = s.cuda(); ns = ns.cuda(); a = a.cuda(); r = r.cuda(); done = done.cuda()
			self.algo.update_parameters(s, ns, a, r, done, 1, **self.td3args)


	def update_stats(self, fitness, ep_len, gamma=0.2):  #ms:fitness is the cum reward each whole episode
		self.visit_count += 1	#ms:visit_count is the number of workers per policy
		self.fitnesses.append(fitness)
		self.ep_lens.append(ep_len)

		if self.value == None: self.value = fitness	#ms: moving avg of fitness as value, value used in ucb for policy reallocation
		else: self.value = gamma * fitness + (1-gamma) * self.value
Beispiel #15
0
 def test_create(self):
     buff1 = Buffer.create()
     tu.azzert(0 == buff1.length)
     buff2 = Buffer.create(100)
     tu.azzert(0 == buff1.length)
     str = "oqkdioqjwdijqwed"
     buff3 = Buffer.create_from_str(str)
     tu.azzert(str == buff3.to_string())
     tu.test_complete()
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict):
        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict, True,
                        QColor(0, 0, 0, 255))

        self.add_widget(VideoPlayerWidget())
        self.buffer_widget.play(url)

        self.build_widget_method("play_backward", "seek_backward")
        self.build_widget_method("play_forward", "seek_forward")
Beispiel #17
0
    def __init__(self, buffer_id, url, arguments):
        Buffer.__init__(self, buffer_id, url, arguments, True)

        self.background_color = QColor(0, 0, 0)

        self.add_widget(VideoPlayerWidget())
        self.buffer_widget.play(url)

        self.build_all_methods(self.buffer_widget)
Beispiel #18
0
 def test_create(self):
     buff1 = Buffer.create()
     tu.azzert(0 == buff1.length)
     buff2 = Buffer.create(100)
     tu.azzert(0 == buff1.length)
     str = "oqkdioqjwdijqwed"
     buff3 = Buffer.create_from_str(str)
     tu.azzert(str == buff3.to_string())
     tu.test_complete()
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict,
                 module_path, call_emacs):
        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict,
                        module_path, call_emacs, True)

        self.add_widget(VideoPlayerWidget())
        self.buffer_widget.play(url)

        self.build_widget_method("play_backward", "seek_backward")
        self.build_widget_method("play_forward", "seek_forward")
Beispiel #20
0
    def __init__(self, buffer_id, url, arguments, fit_to_view, background_color):
        Buffer.__init__(self, buffer_id, url, arguments, fit_to_view, background_color)

        self.add_widget(BrowserView())

        self.buffer_widget.loadStarted.connect(self.start_progress)
        self.buffer_widget.loadProgress.connect(self.update_progress)
        self.buffer_widget.loadFinished.connect(self.stop_progress)

        self.buffer_widget.web_page.windowCloseRequested.connect(self.request_close_buffer)
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict):
        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict, True,
                        QColor(0, 0, 0, 255))

        self.add_widget(RSSReaderWidget(config_dir))

        self.buffer_widget.browser.message_to_emacs = self.message_to_emacs
        self.buffer_widget.browser.set_emacs_var = self.set_emacs_var
        self.buffer_widget.browser.eval_in_emacs = self.eval_in_emacs
        self.buffer_widget.browser.send_input_message = self.send_input_message
Beispiel #22
0
    def __init__(self, buffer_id, url, arguments):
        Buffer.__init__(self, buffer_id, url, arguments, True,
                        QColor(0, 0, 0, 255))

        self.add_widget(QTermWidget.QTermWidget())

        self.buffer_widget.setTerminalFont(QFont('Source Code Pro', 14))
        self.buffer_widget.setColorScheme('Linux')

        self.buffer_widget.finished.connect(self.request_close_buffer)
Beispiel #23
0
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict,
                 module_path):
        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict,
                        module_path, True)

        self.add_widget(RSSReaderWidget(buffer_id, config_dir))
        self.buffer_widget.browser.buffer = self

        self.build_all_methods(self.buffer_widget)
        self.build_all_methods(self.buffer_widget.browser)
Beispiel #24
0
    def __init__(self, buffer_id, url, arguments, fit_to_view, background_color):
        Buffer.__init__(self, buffer_id, url, arguments, fit_to_view, background_color)

        self.add_widget(BrowserView())

        self.buffer_widget.loadStarted.connect(self.start_progress)
        self.buffer_widget.loadProgress.connect(self.update_progress)
        self.buffer_widget.loadFinished.connect(self.stop_progress)

        self.buffer_widget.web_page.windowCloseRequested.connect(self.request_close_buffer)
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict,
                 module_path):
        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict,
                        module_path, True)

        arguments_dict = json.loads(arguments)

        self.add_widget(
            GitViewerWidget(buffer_id, config_dir,
                            arguments_dict["directory"]))
Beispiel #26
0
    def __init__(
        self,
        CERL_agent,
        num_workers,
        trainers,
        pomdp_adv=False
    ):  #trainers first is the blue agent and second is the red model
        self.num_workers = num_workers
        self.trainers = trainers
        self.pomdp_adv = pomdp_adv
        self.args = CERL_agent.args
        self.drqn = CERL_agent.args.drqn  #denote if blue uses drqn
        if self.pomdp_adv:
            self.trainers = [trainers[0],
                             None]  #make sure the red model is never used
        self.buffer_gpu = CERL_agent.args.buffer_gpu
        self.batch_size = CERL_agent.args.batch_size
        self.algo = CERL_agent.args.algo
        self.state_dim = CERL_agent.args.state_dim
        self.action_dim = CERL_agent.args.action_dim
        self.buffer = Buffer(BUFFER_SIZE,
                             self.buffer_gpu)  #initialize own replay buffer
        self.data_bucket = self.buffer.tuples
        self.evo_task_pipes = [Pipe() for _ in range(self.num_workers)]
        self.evo_result_pipes = [Pipe() for _ in range(self.num_workers)]
        self.actual_red_worker = Actor(
            CERL_agent.args.state_dim, CERL_agent.args.action_dim, -1,
            'dis')  #this model is shared accross the workers
        self.actual_red_worker.share_memory()
        self.td3args = {
            'policy_noise': 0.2,
            'policy_noise_clip': 0.5,
            'policy_ups_freq': 2,
            'action_low': CERL_agent.args.action_low,
            'action_high': CERL_agent.args.action_high,
            'cerl_args': self.args
        }
        self.renew_learner(
        )  #now we are not using new learner for each iteration
        self.rollout_bucket = [
            self.actual_red_worker for i in range(num_workers)
        ]
        self.workers = [
            Process(target=rollout_worker,
                    args=(id, 3, self.evo_task_pipes[id][1],
                          self.evo_result_pipes[id][0], False,
                          self.data_bucket, self.rollout_bucket, 'dummy_name',
                          None, 'dis', self.trainers, False, self.pomdp_adv))
            for id in range(num_workers)
        ]

        for worker in self.workers:
            worker.start()
        self.evo_flag = [True for _ in range(self.num_workers)]
	def __init__(self, wwid, algo_name, state_dim, action_dim, actor_lr, critic_lr, gamma, tau, init_w = True, **td3args):
		self.td3args = td3args; self.id = id
		self.wwid = wwid
		self.algo = Off_Policy_Algo(wwid, algo_name, state_dim, action_dim, actor_lr, critic_lr, gamma, tau, init_w)
		self.args = td3args['cerl_args']

		#LEARNER STATISTICS
		self.fitnesses = []
		self.ep_lens = []
		self.value = None
		self.visit_count = 0
		self.private_replay_buffer = Buffer(1000000, self.args.buffer_gpu)   #
    def __init__(self, buffer_id, url, config_dir, argument, emacs_var_dict,
                 module_path):
        Buffer.__init__(self, buffer_id, url, argument, emacs_var_dict,
                        module_path, False)

        self.background_color = QColor(
            emacs_var_dict["eaf-emacs-theme-background-color"])

        self.add_widget(
            FileUploaderWidget(
                url, emacs_var_dict["eaf-emacs-theme-background-color"],
                emacs_var_dict["eaf-emacs-theme-foreground-color"]))
Beispiel #29
0
    def __init__(self, buffer_id, url, arguments):
        Buffer.__init__(self, buffer_id, url, arguments, True,
                        QColor(0, 0, 0, 255))

        parser = qutebrowser.get_argparser()
        args = parser.parse_args(arguments.split())
        print('before app.run')
        app.run(args)
        print('after app.run')
        qwidget = app.qApp.topLevelWidgets()[0]
        print(qwidget)
        self.add_widget(qwidget)
Beispiel #30
0
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict,
                 module_path):
        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict,
                        module_path, False)

        self.delete_temp_file = arguments == "temp_pdf_file"
        self.add_widget(
            PdfViewerWidget(url, config_dir, QColor(0, 0, 0, 255), buffer_id,
                            emacs_var_dict))
        self.buffer_widget.translate_double_click_word.connect(
            self.translate_text)

        self.build_all_methods(self.buffer_widget)
Beispiel #31
0
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, call_emacs):
        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict, module_path, call_emacs, False)

        self.delete_temp_file = arguments == "temp_pdf_file"
        self.add_widget(PdfViewerWidget(url, config_dir, QColor(0, 0, 0, 255), buffer_id, emacs_var_dict, call_emacs))
        self.buffer_widget.translate_double_click_word.connect(self.translate_text)

        for method_name in ["scroll_up", "scroll_down", "scroll_up_page",
                            "scroll_down_page", "scroll_to_home", "scroll_to_end",
                            "zoom_reset", "zoom_in", "zoom_out",
                            "save_current_pos", "jump_to_saved_pos",
                            "scroll_right", "scroll_left",
                            "toggle_read_mode", "toggle_inverted_mode", "toggle_mark_link"]:
            self.build_widget_method(method_name)
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict):
        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict, True, QColor(0, 0, 0, 255))

        self.add_widget(RSSReaderWidget(config_dir))

        for method_name in ["next_subscription", "prev_subscription", "next_article", "prev_article",
                            "first_subscription", "last_subscription", "first_article", "last_article"]:
            self.build_widget_method(method_name)

        for method_name in ["scroll_up", "scroll_down", "scroll_up_page", "scroll_down_page", "scroll_to_begin", "scroll_to_bottom",
                         "search_text_forward", "search_text_backward"]:
            self.build_browser_method(method_name)

        self.build_browser_method("action_quit", "search_quit")
Beispiel #33
0
	def __init__(self, args, model_constructor, env_constructor):
		self.args = args

		#MP TOOLS
		self.manager = Manager()

		#Algo
		sac_keyargs = {}
		sac_keyargs['autotune'] = args.autotune
		sac_keyargs['entropy'] = True
		self.algo = SAC(args, model_constructor, args.gamma, **sac_keyargs)

		# #Save best policy
		# self.best_policy = model_constructor.make_model('actor')

		#Init BUFFER
		self.replay_buffer = Buffer(args.buffer_size)
		self.data_bucket = self.replay_buffer.tuples

		#Initialize Rollout Bucket
		self.rollout_bucket = self.manager.list()
		self.rollout_bucket.append(model_constructor.make_model('Gaussian_FF'))

		############## MULTIPROCESSING TOOLS ###################
		#Learner rollout workers
		self.task_pipes = [Pipe() for _ in range(args.rollout_size)]
		self.result_pipes = [Pipe() for _ in range(args.rollout_size)]
		self.workers = [Process(target=rollout_worker, args=(id, 'pg', self.task_pipes[id][1], self.result_pipes[id][0], self.data_bucket, self.rollout_bucket, env_constructor)) for id in range(args.rollout_size)]
		for worker in self.workers: worker.start()
		self.roll_flag = [True for _ in range(args.rollout_size)]

		#Test bucket
		self.test_bucket = self.manager.list()
		self.test_bucket.append(model_constructor.make_model('Gaussian_FF'))

		#5 Test workers
		self.test_task_pipes = [Pipe() for _ in range(env_constructor.dummy_env.test_size)]
		self.test_result_pipes = [Pipe() for _ in range(env_constructor.dummy_env.test_size)]
		self.test_workers = [Process(target=rollout_worker, args=(id, 'test', self.test_task_pipes[id][1], self.test_result_pipes[id][0], None, self.test_bucket, env_constructor)) for id in range(env_constructor.dummy_env.test_size)]
		for worker in self.test_workers: worker.start()
		self.test_flag = False

		#Trackers
		self.best_score = 0.0; self.gen_frames = 0; self.total_frames = 0; self.test_score = None; self.test_std = None; self.test_trace = []; self.rollout_fits_trace = []

		self.ep_len = 0
		self.r1_reward = 0
		self.num_footsteps = 0
		self.best_shaped_score = 0.0
Beispiel #34
0
 def open_handler(err, file):
     tu.check_context()
     tu.azzert(err == None)
     num_chunks = 100;
     chunk_size = 1000;
     tot_buff = Buffer.create()
     self.written = 0
     for i in range(0, num_chunks):
         buff = TestUtils.gen_buffer(chunk_size)
         tot_buff.append_buffer(buff)
         def write_handler(err, res):
             tu.check_context()
             self.written += 1
             if self.written == num_chunks:
               # all written
               tot_read = Buffer.create()
               self.read = 0
               for j in range(0, num_chunks):
                 pos = j * chunk_size
                 def read_handler(err, buff):
                     tu.check_context
                     tu.azzert(err == None)
                     self.read += 1
                     if self.read == num_chunks:
                         # all read
                         tu.azzert(TestUtils.buffers_equal(tot_buff, tot_read))
                         def close_handler(err, res):
                             tu.check_context()
                             tu.test_complete()
                         file.close(close_handler)
                 file.read(tot_read, pos, pos, chunk_size, read_handler)
         file.write(buff, i * chunk_size, write_handler)
Beispiel #35
0
    def request_handler(req):
        tu.check_context()
        tu.azzert(req.uri == uri)
        tu.azzert(req.method == method)
        tu.azzert(req.path == path)
        tu.azzert(req.query == query)
        tu.azzert(req.headers['header1'] == 'vheader1')
        tu.azzert(req.headers['header2'] == 'vheader2')
        tu.azzert(req.params['param1'] == 'vparam1')
        tu.azzert(req.params['param2'] == 'vparam2')
        req.response.put_header('rheader1', 'vrheader1')
        req.response.put_header('rheader2', 'vrheader2')
        body = Buffer.create()

        @req.data_handler
        def data_handler(data):
            tu.check_context()
            body.append_buffer(data)
        req.response.chunked = chunked

        @req.end_handler
        def end_handler(stream):
            tu.check_context()
            if not chunked:
                req.response.put_header('Content-Length', body.length)
            req.response.write_buffer(body)
            if chunked:
                req.response.put_trailer('trailer1', 'vtrailer1')
                req.response.put_trailer('trailer2', 'vtrailer2')
            req.response.end()
                def write_handler(err, res):
                    tu.check_thread()
                    self.written += 1
                    if self.written == num_chunks:
                        # all written
                        tot_read = Buffer.create()
                        self.read = 0
                        for j in range(0, num_chunks):
                            pos = j * chunk_size

                            def read_handler(err, buff):
                                tu.check_thread
                                tu.azzert(err == None)
                                self.read += 1
                                if self.read == num_chunks:
                                    # all read
                                    tu.azzert(TestUtils.buffers_equal(tot_buff, tot_read))

                                    def close_handler(err, res):
                                        tu.check_thread()
                                        tu.test_complete()

                                    file.close(close_handler)

                            file.read_at_pos(tot_read, pos, pos, chunk_size, read_handler)
Beispiel #37
0
 def open_handler(err, file):
     tu.check_context()
     tu.azzert(err == None)
     num_chunks = 100;
     chunk_size = 1000;
     tot_buff = Buffer.create()
     write_stream = file.write_stream
     for i in range(0, num_chunks):
         buff = TestUtils.gen_buffer(chunk_size)
         tot_buff.append_buffer(buff)
         write_stream.write_buffer(buff)
     def close_handler(err, file):
         def open_handler2(err, file):
             tu.check_context()
             tu.azzert(err == None)
             read_stream = file.read_stream
             tot_read = Buffer.create()
             def data_handler(data):
                 tot_read.append_buffer(data)  
             read_stream.data_handler(data_handler)
             def end_handler(stream):
                 tu.azzert(TestUtils.buffers_equal(tot_buff, tot_read))
                 tu.check_context
                 def close_handler2(err, result):
                     tu.check_context()
                     tu.test_complete()
                 file.close(close_handler2)
             read_stream.end_handler(end_handler)
         FileSystem.open(filename, handler=open_handler2)
     
     file.close(close_handler)
Beispiel #38
0
    def request_handler(req):
        tu.check_context()
        tu.azzert(req.uri == uri)
        tu.azzert(req.method == method)
        tu.azzert(req.path == path)
        tu.azzert(req.query == query)
        tu.azzert(req.headers["header1"] == "vheader1")
        tu.azzert(req.headers["header2"] == "vheader2")
        tu.azzert(req.params["param1"] == "vparam1")
        tu.azzert(req.params["param2"] == "vparam2")
        req.response.put_header("rheader1", "vrheader1")
        req.response.put_header("rheader2", "vrheader2")
        body = Buffer.create()

        @req.data_handler
        def data_handler(data):
            tu.check_context()
            body.append_buffer(data)

        req.response.chunked = chunked

        @req.end_handler
        def end_handler(stream):
            tu.check_context()
            if method != "HEAD" and method != "CONNECT":
                if not chunked:
                    req.response.put_header("Content-Length", body.length)
                req.response.write_buffer(body)
                if chunked:
                    req.response.put_trailer("trailer1", "vtrailer1")
                    req.response.put_trailer("trailer2", "vtrailer2")
            req.response.end()
Beispiel #39
0
 def test_append_buff(self):
     buff_len = 100
     buff1 = self.create_buffer(buff_len)
     buff2 = Buffer.create()
     buff2.append_buffer(buff1)
     tu.azzert(buff_len == buff2.length, 'Invalid length')
     tu.test_complete()
Beispiel #40
0
 def test_set_buff_with_offset(self):
     buff_len = 100
     buff1 = self.create_buffer(buff_len)
     buff2 = Buffer.create()
     buff2.set_buffer(0, buff1, 50, 50)
     tu.azzert(50 == buff2.length, 'Invalid length')
     tu.test_complete()
Beispiel #41
0
def connect_handler(socket):
    @socket.data_handler
    def data_handler(data):
        print "Echo client received %s"% data
    for i in range(10):
        print "Echo client sending %d"% i
        socket.write_buffer(Buffer.create_from_str("%d"% i))
    def test_append_int(self):
        buff1 = Buffer.create()
        for i in range(100):
          buff1.append_int(i)

        for i in range(100):
          val = buff1.get_int(i)
          tu.azzert(val == i)
Beispiel #43
0
 def set_fixnum(self, num_bytes):
     buff1 = Buffer.create()
     for i in range(-128,128):
         buff1.set_fixnum((i + 128) * num_bytes, i << ((num_bytes -1) * 8), num_bytes)
     for i in range(-128,128):
         val = buff1.get_fixnum((i + 128) * num_bytes, num_bytes)
         tu.azzert(val == i << ((num_bytes -1)* 8))
     tu.test_complete()
Beispiel #44
0
 def test_length(self):
     buff1 = Buffer.create()
     tu.azzert(buff1.length == 0)
     num = 50
     for i in range(0,num):
         buff1.append_fixnum(i, 1)
     tu.azzert(buff1.length == num, "Received %d expected %d"% (buff1.length, num))
     tu.test_complete()
Beispiel #45
0
 def test_copy(self):
     str = "iajdoiqwjdiqwdioqwdjiqwd"
     buff1 = Buffer.create(str)
     buff2 = buff1.copy()
     tu.azzert(buff1.length == buff2.length)
     for i in range(0,buff1.length):
         tu.azzert(buff1.get_byte(i) == buff2.get_byte(i))
     tu.test_complete()
Beispiel #46
0
        def client_connect_handler(err, socket):
            tu.azzert(err == None)
            tu.check_thread()
            tu.azzert(socket.local_address[0] is not None)
            tu.azzert(socket.local_address[1] > -1)
            tu.azzert(socket.remote_address[0] is not None)
            tu.azzert(socket.remote_address[1] > -1)

            sends = 10
            size = 100

            sent = Buffer.create()
            received = Buffer.create()

            @socket.data_handler
            def data_handler(data):
                tu.check_thread()
                received.append_buffer(data)

                if received.length == sends * size:
                    tu.azzert(TestUtils.buffers_equal(sent, received))
                    tu.test_complete()

            #Just call the methods. Real testing is done in java tests
            @socket.drain_handler
            def drain_handler():
                tu.check_thread()

            @socket.end_handler
            def end_handler():
                tu.check_thread()

            @socket.close_handler
            def close_handler():
                tu.check_thread()

            socket.pause()
            socket.resume()
            socket.write_queue_full
            socket.write_queue_max_size = 100000

            for i in range(0, sends):
                data = TestUtils.gen_buffer(size)
                sent.append_buffer(data)
                socket.write(data)
Beispiel #47
0
    def append_float(self, num_bytes):
        buff1 = Buffer.create()
        for i in range(0,100):
            buff1.append_float(i, num_bytes)

        for i in range(0,100):
            val = buff1.get_float(i * num_bytes, num_bytes)
            tu.azzert(val == i)
        tu.test_complete()
Beispiel #48
0
def connect_handler(err, socket):
    if err is None:
        def data_handler(data):
            print "Echo client received %s"%data

        socket.data_handler(data_handler)
        for i in range(10):
            print "Echo client sending %d"%i
            socket.write(Buffer.create_from_str("%d"% i))
    else:
        print 'Failed to connect %s' % err
Beispiel #49
0
        def client_connect_handler(socket):
            tu.check_context()
            sent = 'some-string'
            received = Buffer.create()

            @socket.data_handler
            def data_handler(data):
                tu.check_context()
                received.append_buffer(data)

                if received.length == len(sent):
                    tu.azzert(sent == received.to_string())
                    tu.test_complete()

            socket.write_str(sent)
Beispiel #50
0
 def open_handler2(err, file):
     tu.check_context()
     tu.azzert(err == None)
     read_stream = file.read_stream
     tot_read = Buffer.create()
     def data_handler(data):
         tot_read.append_buffer(data)  
     read_stream.data_handler(data_handler)
     def end_handler(stream):
         tu.azzert(TestUtils.buffers_equal(tot_buff, tot_read))
         tu.check_context
         def close_handler2(err, result):
             tu.check_context()
             tu.test_complete()
         file.close(close_handler2)
     read_stream.end_handler(end_handler)
Beispiel #51
0
        def connect_handler(ws):
            tu.check_context()
            received = Buffer.create()

            @ws.data_handler
            def data_handler(buff):
                tu.check_context()
                received.append_buffer(buff)
                if received.length == buff.length:
                    tu.azzert(TestUtils.buffers_equal(buff, received))
                    tu.test_complete()
        
            if binary:
                ws.write_binary_frame(self.buff)
            else:
                ws.write_text_frame(self.str_)
Beispiel #52
0
    def request_handler(req):
        tu.check_thread()
        tu.azzert(req.version == 'HTTP_1_1')
        tu.azzert(req.uri == uri)
        tu.azzert(req.method == method)
        tu.azzert(req.path == path)
        tu.azzert(req.query == query)
        tu.azzert(req.headers['header1'] == 'vheader1')
        tu.azzert(req.headers['header2'] == 'vheader2')
        tu.azzert(req.params['param1'] == 'vparam1')
        tu.azzert(req.params['param2'] == 'vparam2')


        headers = req.headers
        tu.azzert(headers.contains('header1'))
        tu.azzert(headers.contains('header2'))
        tu.azzert(headers.contains('header3'))
        tu.azzert(not headers.is_empty)

        headers.remove('header3')
        tu.azzert(not headers.contains('header3'))

        req.response.put_header('rheader1', 'vrheader1')
        req.response.put_header('rheader2', 'vrheader2')
        body = Buffer.create()

        @req.data_handler
        def data_handler(data):
            tu.check_thread()
            body.append_buffer(data)

        if method != 'HEAD' and method != 'CONNECT':
            req.response.chunked = chunked

        @req.end_handler
        def end_handler():
            tu.check_thread()
            if method != 'HEAD' and method != 'CONNECT':
                if not chunked:
                    req.response.put_header('Content-Length', str(body.length))
                req.response.write(body)
                if chunked:
                    req.response.put_trailer('trailer1', 'vtrailer1')
                    req.response.put_trailer('trailer2', 'vtrailer2')
            req.response.end()
Beispiel #53
0
        def listen_handler (err, serv):
            tu.azzert(err is None)
            client.port = 8080

            def post_handler(resp):
                # assert the response
                tu.azzert(200 == resp.status_code)
                @resp.body_handler
                def body_handler(body):
                    tu.azzert(0 == body.length)
                tu.test_complete()

            req = client.post("/form", post_handler)
            buffer = Buffer.create()
            buffer.append_str('framework=vertx&runson=jvm')
            req.put_header('content-length', str(buffer.length))
            req.put_header('content-type', 'application/x-www-form-urlencoded')
            req.write(buffer).end()
Beispiel #54
0
    def test_delimited(self):
        str = ""
        iters = 100
        for i in range(0, iters):
            str += "line %s"% i
            if i != iters - 1:
                str += "\n" 

        self.lines = []
        def each_line(line):
            self.lines.append(line)
        parser = RecordParser.new_delimited("\n", each_line)
        
        parser.input(Buffer.create_from_str(str))

        count = 0
        for line in self.lines:    
            tu.azzert("line %i"% count == line.to_string())
            count += 1
        tu.test_complete()
Beispiel #55
0
    def response_handler(resp):
        tu.check_context()
        tu.azzert(200 == resp.status_code)
        tu.azzert('vrheader1' == resp.headers['rheader1'])
        tu.azzert('vrheader2' == resp.headers['rheader2'])
        body = Buffer.create()
        
        @resp.data_handler
        def data_handler(data):
            tu.check_context()
            body.append_buffer(data)

        @resp.end_handler
        def end_handler(stream):
            tu.check_context()
            tu.azzert(TestUtils.buffers_equal(sent_buff, body))
            if chunked:
                tu.azzert('vtrailer1' == resp.trailers['trailer1'])
                tu.azzert('vtrailer2' == resp.trailers['trailer2'])
            tu.test_complete()
Beispiel #56
0
    def response_handler(resp):
        tu.check_context()
        tu.azzert(200 == resp.status_code)
        tu.azzert("vrheader1" == resp.headers["rheader1"])
        tu.azzert("vrheader2" == resp.headers["rheader2"])
        body = Buffer.create()

        @resp.data_handler
        def data_handler(data):
            tu.check_context()
            body.append_buffer(data)

        @resp.end_handler
        def end_handler(stream):
            tu.check_context()
            if method != "HEAD" and method != "CONNECT":
                tu.azzert(TestUtils.buffers_equal(sent_buff, body))
                if chunked:
                    tu.azzert("vtrailer1" == resp.trailers["trailer1"])
                    tu.azzert("vtrailer2" == resp.trailers["trailer2"])
            tu.test_complete()
Beispiel #57
0
        def listen_handler (err, serv):
            tu.azzert(err is None)
            client.port = 8080

            def post_handler(resp):
                # assert the response
                tu.azzert(200 == resp.status_code)
                @resp.body_handler
                def body_handler(body):
                    tu.azzert(0 == body.length)
                tu.test_complete()

            req = client.post("/form", post_handler)
            boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO"
            buffer = Buffer.create()
            b = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"tmp-0.txt\"\r\n" + "Content-Type: image/gif\r\n" + "\r\n" + content + "\r\n" + "--" + boundary + "--\r\n"

            buffer.append_str(b)
            req.put_header('content-length', str(buffer.length))
            req.put_header('content-type', 'multipart/form-data; boundary=' + boundary)
            req.write(buffer).end()
Beispiel #58
0
        def client_connect_handler(err, socket):
            tu.azzert(err == None)
            tu.check_thread()
            tu.azzert(socket.local_address[0] is not None)
            tu.azzert(socket.local_address[1] > -1)
            tu.azzert(socket.remote_address[0] is not None)
            tu.azzert(socket.remote_address[1] > -1)

            sent = 'some-string'
            received = Buffer.create()

            @socket.data_handler
            def data_handler(data):
                tu.check_thread()
                received.append_buffer(data)

                if received.length == len(sent):
                    tu.azzert(sent == received.to_string())
                    tu.test_complete()

            socket.write_str(sent)
Beispiel #59
0
    def response_handler(resp):
        tu.check_thread()
        tu.azzert(200 == resp.status_code)
        tu.azzert('vrheader1' == resp.headers['rheader1'])
        tu.azzert('vrheader2' == resp.headers['rheader2'])
        body = Buffer.create()
        
        @resp.data_handler
        def data_handler(data):
            tu.check_thread()
            body.append_buffer(data)

        @resp.end_handler
        def end_handler():
            tu.check_thread()
            if method != 'HEAD' and method != 'CONNECT':
                tu.azzert(TestUtils.buffers_equal(sent_buff, body))
                if chunked:
                    tu.azzert('vtrailer1' == resp.trailers['trailer1'])
                    tu.azzert('vtrailer2' == resp.trailers['trailer2'])

            resp.headers.clear()
            tu.azzert(resp.headers.is_empty)
            tu.test_complete()
Beispiel #60
0
    def __init__(self, buffer_id, url, arguments):
        Buffer.__init__(self, buffer_id, url, arguments, False, QColor(0, 0, 0, 255))

        self.add_widget(AirShareWidget(url, QColor(0, 0, 0, 255)))