# -*- coding: utf-8 -*-
"""Data interface functions for the mudpy engine."""
-# Copyright (c) 2004-2012 Jeremy Stanley <fungi@yuggoth.org>. Permission
+# Copyright (c) 2004-2013 Jeremy Stanley <fungi@yuggoth.org>. Permission
# 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
+import sys
+
+# TODO: remove this check after the switch to py3k
+try:
+ import configparser
+except ImportError:
+ import ConfigParser as configparser
+
+import mudpy
+
class DataFile:
def load(self):
"""Read a file and create elements accordingly."""
- import ConfigParser
- import mudpy.misc
- import os
- import os.path
- self.data = ConfigParser.RawConfigParser()
+ self.data = configparser.RawConfigParser()
self.modified = False
if os.access(self.filename, os.R_OK):
self.data.read(self.filename)
def save(self):
"""Write the data, if necessary."""
- import codecs
- import os
- import os.path
- import re
- import stat
# when modified, writeable and has content or the file exists
if self.modified and self.is_writeable() and (
# if it's marked private, chmod it appropriately
if self.filename in self.universe.private_files and oct(
stat.S_IMODE(os.stat(self.filename)[stat.ST_MODE])
- ) != 0600:
- os.chmod(self.filename, 0600)
+ ) != 0o0600:
+ os.chmod(self.filename, 0o0600)
- # write it back sorted, instead of using ConfigParser
+ # write it back sorted, instead of using configparser
sections = self.data.sections()
sections.sort()
for section in sections:
universe=None
):
"""Return an absolute file path based on configuration."""
- import os
- import os.path
- import sys
# make sure to get rid of any surrounding quotes first thing
if file_name:
# if there's only one file loaded, try to work around a chicken<egg
elif hasattr(universe, "files") and len(
universe.files
- ) == 1 and not universe.files[universe.files.keys()[0]].is_writeable():
- data_file = universe.files[universe.files.keys()[0]].data
+ ) == 1 and not universe.files[
+ list(universe.files.keys())[0]].is_writeable():
+ data_file = universe.files[list(universe.files.keys())[0]].data
# try for a fallback default directory
if not default_dir and data_file.has_option(