From 3a2229d8923d5240b2a7c95dafc8a6e0b35e06da Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Sat, 17 Jan 2015 01:16:13 +0000 Subject: [PATCH] Write files directly from yaml.dump Simplify data file writing by passing a file descriptor directly to the yaml.dump method rather than unnecessarily passing a string back out of it and into a separate writer. --- lib/mudpy/data.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/mudpy/data.py b/lib/mudpy/data.py index ca47f83..b3ca5a8 100644 --- a/lib/mudpy/data.py +++ b/lib/mudpy/data.py @@ -4,7 +4,6 @@ # to use, copy, modify, and distribute this software is granted under # terms provided in the LICENSE file distributed with this software. -import codecs import os import re import stat @@ -144,7 +143,7 @@ class DataFile: os.rename(self.filename, self.filename + ".0") # our data file - file_descriptor = codecs.open(self.filename, "w", "utf-8") + file_descriptor = open(self.filename, "w") # if it's marked private, chmod it appropriately if self.filename in self.universe.private_files and oct( @@ -152,9 +151,9 @@ class DataFile: ) != 0o0600: os.chmod(self.filename, 0o0600) - # write, flush and close the file - file_descriptor.write(yaml.dump(self.data)) - file_descriptor.flush() + # write and close the file + yaml.dump(self.data, allow_unicode=True, default_flow_style=False, + stream=file_descriptor) file_descriptor.close() # unset the modified flag -- 2.11.0