def get(self, link: str, source: str = None) -> str: if link.startswith('/'): link = link[1:] if not link.startswith('http://'): link = self.get_url(source) + link return clean_text(urlopen(link).read().decode())
def _eject_next_input(self): new_input = self._dynamic_input_function() if new_input is None: return new_input = clean_text(new_input) self._input_lines += new_input.strip().split('\n')
def _eject_next_input(self): new_input = self._dynamic_input_function() if new_input is None: return new_input = clean_text(new_input) if new_input.endswith('\n'): new_input = new_input[:-1] self._input_lines += new_input.split('\n')
def eject_next_input(self, curr_output: str) -> Optional[str]: if len(self.input_funcs) == 0: return None input_function = self.input_funcs[0] trigger_count = input_function.trigger_count if trigger_count > 0: input_function.trigger() next_func = input_function.input_function new_input: Optional[str] try: obj = next_func(curr_output) if isinstance(obj, str) or obj is None: new_input = obj elif isinstance(obj, CheckResult): if obj.is_correct: raise TestPassed() else: raise WrongAnswer(obj.feedback) else: raise UnexpectedError( 'Dynamic input should return ' + f'str or CheckResult objects only. Found: {type(obj)}') except BaseException as ex: from hstest.stage_test import StageTest StageTest.curr_test_run.set_error_in_test(ex) return None if input_function.trigger_count == 0: self.input_funcs.pop(0) if new_input is not None: new_input = clean_text(new_input) return new_input
def read_page(self, link: str) -> str: return clean_text(urlopen(link).read().decode())
def get_partial_output() -> str: return clean_text(OutputHandler._mock_out.partial)
def get_dynamic_output() -> str: return clean_text(OutputHandler._mock_out.dynamic)
def get_err() -> str: return clean_text(OutputHandler._mock_err.cloned)
def get_output() -> str: return clean_text(OutputHandler._mock_out.cloned)
def get(self, link: str, *, source: str = None) -> str: if not link.startswith('http://'): link = self.get_url(link, source=source) return clean_text(urlopen(link).read().decode())
def get(self, link: str) -> str: if not link.startswith('http://'): link = self.get_url(link) return clean_text(urlopen(link).read().decode())
def read_page(self, link: str) -> str: """ Deprecated, use get(...) instead """ return clean_text(urlopen(link).read().decode())