def write_savefile_header(ofile, encoding, information): write = ofile.write write(Global.begin_of_header_EOL) write(Global.encoding_decl_EOL_fmt.format(nonstd_encoding=encoding)) stable_repr_print(ofile, information, **_1level_expand_kwargs) write('\n') write(Global.end_of_header_EOL)
def pprint1(obj, *, file=None): ofile = sys.stdout if file is None else file del file stable_repr_print(ofile, obj , indent='', depth=0, maybe_max_depth=1 , has_head_eol_when_indent=False )
def write_tuple(self, ofile, tuple_): assert type(tuple_) is tuple it = iter(tuple_) write = ofile.write write('[') # !!!!! for obj in it: stable_repr_print(ofile, obj) write('\n') break for obj in it: write(',') stable_repr_print(ofile, obj) write('\n') write(']') ofile.write('\n')
def write_line(self, ofile, obj): stable_repr_print(ofile, obj) ofile.write('\n')
def write_body(self, ofile, obj): stable_repr_print(ofile, obj, depth=0) ofile.write('\n')
value = safe_eval(line[1:]) state = state2 else: assert state == state2 if not comment_line_rex.match(line[1:]): raise SaveFileException(f'bad format: {line!r}') yield case0, key, value del case0, key, value state = state0 def write_item(self, ofile, case, key, value): if case not in self.all_cases: raise ValueError(f'bad case: {case!r}') write = ofile.write write(case) stable_repr_print(ofile, key); write('\n') if case != self.caseDELETE: write(': ') stable_repr_print(ofile, value); write('\n') write('.\n') @override def write_body(self, ofile, mapping): #self.write_items(ofile, mapping.items()) pairs = sorted_mapping_by_SortableIterReprable(mapping, key=None, reverse=False, SortableIterReprable=None) self.write_items(ofile, pairs) def write_items(self, ofile, pairs): write_item = self.write_item case = self.caseNEWorOVERWRITE for key, value in pairs: write_item(ofile, case, key, value)