def load_conf(infile: str, flog: TextIOWrapper = None) -> dict: ''' Loads user configuration file. @param infile: Path and name of the user input YAML configuration file @type infile: str @param flog: Log file to record raised events @type flog: TextIOWrapper (file object) @return: User configuration file as YAML object @rtype: dict ''' try: if infile and os.path.isfile(infile): with open(infile, 'r') as f: return yaml.load(f) else: print('Error: No user configuration file is specified') return None except: result = 'Error: "load_conf" function has error(vifi_server): ' if flog: flog.write(result) traceback.print_exc(file=flog) else: print(result) traceback.print_exc()
def write(ctx: click.Context, file: TextIOWrapper) -> None: """Writes results from last command to a file.""" if file.name.split(".")[-1] == "wiki": file.write(PARSERS[ctx.obj["last"]](ctx.obj["export"], print_date=False)) else: file.write(json.dumps(ctx.obj["export"]))
def serialization(wf: _io.TextIOWrapper, pNode: TreeNode): if (pNode == None): wf.write("$\n") return else: wf.write(str(pNode.val) + "\n") serialization(wf, pNode.left) serialization(wf, pNode.right)
def read_to_file(self, file: _io.TextIOWrapper) -> str: """ Decompress the object file and write to text file and return the text :param file: Open text file object for writing decompressed text to :return text: Returns the decompressed text as a string """ text = self.decompress() file.write(text) return text
def msmarco_write(query_ids: List[int], doc_ids: List[int], preds: List[int], msmarco_file: _io.TextIOWrapper): assert len(set(query_ids)) == 1 query_id = query_ids[0] rank = 1 logger.info("writing to MSMarco file...") for idx in preds: doc_id = doc_ids[idx] msmarco_file.write("\t".join((str(query_id), str(doc_id), str(rank))) + "\n") rank += 1
def test_issue25862(): # CPython issue #25862 # Assertion failures occurred in tell() after read() and write(). from _io import TextIOWrapper, BytesIO t = TextIOWrapper(BytesIO(b'test'), encoding='ascii') t.read(1) t.read() t.tell() t = TextIOWrapper(BytesIO(b'test'), encoding='ascii') t.read(1) t.write('x') t.tell()
def _write_select_content(cls, output: _io.TextIOWrapper, select: SelectParser.SelectContent) -> None: output.write("{ " + cls._MARK_LINE) # If it doesn't have a `default` case, then it is a blocking `select`, so we have `while` in `define` output.write( f"{'if' if cls._select_has_default_case(select) else 'while'} (true) {cls._MARK_LINE}" ) output.write("{ " + cls._MARK_LINE) for case in select: cls._write_case_content(output, case) output.write("} \\\n") # /while output.write("}\n") # /define
def _write_define_header(cls, output: _io.TextIOWrapper, index: int, select: SelectParser.SelectContent) -> None: output.write(cls._DEFINE_PREFIX) output.write(str(index)) parameters: typing.List[str] = [] for case in select: receiver: str = case[cls._INDICES_CASE.receiver] if case[ cls._INDICES_CASE.receiver] else "nullptr" sender: str = case[cls._INDICES_CASE.sender] if case[ cls._INDICES_CASE.sender] else "nullptr" read_from_channel: bool = cls._is_read_from_channel(sender) # The default case is not appearing in the `define`'s header. if cls._is_default_case(case): continue parameters.append(sender if read_from_channel else receiver) parameters.append(str(read_from_channel).lower()) parameters.append( receiver or "nullptr" if read_from_channel else sender)
def myPrintTable2D(file: _io.TextIOWrapper, table: list): for i in range(len(table)): if i % 4 == 2: for j in range(len(table[i])): file.write("[%.3f,%.3f] " % (table[i][j], table[i + 1][j])) else: if i % 4 != 3: for j in range(len(table[i])): file.write("%f " % table[i][j]) file.write("\n")
def write_with_timestamps(file: _io.TextIOWrapper, entries: Iterable[str]) -> None: for e in entries: file.write(add_timestamp(e))
def output_error(self, stream: _io.TextIOWrapper, error: Exception): for arg in error.args: stream.write(str(arg)) stream.write("\n")