diff --git a/plugins/Karma/plugin.py b/plugins/Karma/plugin.py index 91cdad38c..92fdd7f6c 100644 --- a/plugins/Karma/plugin.py +++ b/plugins/Karma/plugin.py @@ -199,7 +199,7 @@ class SqliteKarmaDB(object): def load(self, channel, filename): filename = conf.supybot.directories.data.dirize(filename) - fd = file(filename) + fd = open(filename) reader = csv.reader(fd) db = self._getDb(channel) cursor = db.cursor() diff --git a/plugins/Status/plugin.py b/plugins/Status/plugin.py index b3966f35b..279b90545 100644 --- a/plugins/Status/plugin.py +++ b/plugins/Status/plugin.py @@ -153,7 +153,7 @@ class Status(callbacks.Plugin): cmd = 'ps -o rss -p %s' % pid try: inst = subprocess.Popen(cmd.split(), close_fds=True, - stdin=file(os.devnull), + stdin=open(os.devnull), stdout=subprocess.PIPE, stderr=subprocess.PIPE) except OSError: diff --git a/plugins/Unix/plugin.py b/plugins/Unix/plugin.py index 21e22b1ea..e8ccdf635 100644 --- a/plugins/Unix/plugin.py +++ b/plugins/Unix/plugin.py @@ -212,7 +212,7 @@ class Unix(callbacks.Plugin): inst = subprocess.Popen(args, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - stdin=file(os.devnull)) + stdin=open(os.devnull)) except OSError, e: irc.error(_('It seems the configured fortune command was ' 'not available.'), Raise=True) @@ -242,8 +242,8 @@ class Unix(callbacks.Plugin): try: inst = subprocess.Popen([wtfCmd, something], close_fds=True, stdout=subprocess.PIPE, - stderr=file(os.devnull), - stdin=file(os.devnull)) + stderr=open(os.devnull), + stdin=open(os.devnull)) except OSError: irc.error(_('It seems the configured wtf command was not ' 'available.'), Raise=True) @@ -292,7 +292,7 @@ class Unix(callbacks.Plugin): try: inst = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - stdin=file(os.devnull)) + stdin=open(os.devnull)) except OSError, e: irc.error('It seems the configured ping command was ' 'not available (%s).' % e, Raise=True) @@ -325,7 +325,7 @@ class Unix(callbacks.Plugin): inst = subprocess.Popen(args, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - stdin=file(os.devnull)) + stdin=open(os.devnull)) except OSError, e: irc.error('It seems the configured uptime command was ' 'not available.', Raise=True) @@ -353,7 +353,7 @@ class Unix(callbacks.Plugin): inst = subprocess.Popen(args, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - stdin=file(os.devnull)) + stdin=open(os.devnull)) except OSError, e: irc.error('It seems the configured uptime command was ' 'not available.', Raise=True) @@ -382,7 +382,7 @@ class Unix(callbacks.Plugin): try: inst = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - stdin=file(os.devnull)) + stdin=open(os.devnull)) except OSError, e: irc.error('It seems the requested command was ' 'not available (%s).' % e, Raise=True) diff --git a/plugins/__init__.py b/plugins/__init__.py index 5c86f5162..e15f28dce 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -267,7 +267,7 @@ class ChannelUserDB(ChannelUserDictionary): ChannelUserDictionary.__init__(self) self.filename = filename try: - fd = file(self.filename) + fd = open(self.filename) except EnvironmentError, e: log.warning('Couldn\'t open %s: %s.', self.filename, e) return @@ -564,7 +564,7 @@ class PeriodicFileDownloader(object): return confDir = conf.supybot.directories.data() newFilename = os.path.join(confDir, utils.file.mktemp()) - outfd = file(newFilename, 'wb') + outfd = open(newFilename, 'wb') start = time.time() s = infd.read(4096) while s: diff --git a/scripts/supybot b/scripts/supybot index 595a600da..0d24388ff 100644 --- a/scripts/supybot +++ b/scripts/supybot @@ -184,7 +184,7 @@ if __name__ == '__main__': i18n.getLocaleFromRegistryFilename(registryFilename) try: # The registry *MUST* be opened before importing log or conf. - registry.open(registryFilename) + registry.open_registry(registryFilename) shutil.copy(registryFilename, registryFilename + '.bak') except registry.InvalidRegistryFile, e: s = '%s in %s. Please fix this error and start supybot again.' % \ @@ -290,7 +290,7 @@ if __name__ == '__main__': pidFile = conf.supybot.pidFile() if pidFile: try: - fd = file(pidFile, 'w') + fd = open(pidFile, 'w') pid = os.getpid() fd.write('%s%s' % (pid, os.linesep)) fd.close() @@ -319,10 +319,10 @@ if __name__ == '__main__': 'userdata.conf') # Let's open this now since we've got our directories setup. if not os.path.exists(userdataFilename): - fd = file(userdataFilename, 'w') + fd = open(userdataFilename, 'w') fd.write('\n') fd.close() - registry.open(userdataFilename) + registry.open_registry(userdataFilename) import supybot.irclib as irclib import supybot.ircmsgs as ircmsgs diff --git a/scripts/supybot-botchk b/scripts/supybot-botchk index 468bead4f..4c72c55fb 100644 --- a/scripts/supybot-botchk +++ b/scripts/supybot-botchk @@ -33,7 +33,7 @@ VERBOSE = False def readPid(filename): - fd = file(filename) + fd = open(filename) try: return int(fd.read().strip()) finally: diff --git a/scripts/supybot-plugin-create b/scripts/supybot-plugin-create index a515946f8..c695c0509 100644 --- a/scripts/supybot-plugin-create +++ b/scripts/supybot-plugin-create @@ -266,7 +266,7 @@ def main(): os.mkdir(pathname) def writeFile(filename, s): - fd = file(os.path.join(pathname, filename), 'w') + fd = open(os.path.join(pathname, filename), 'w') try: fd.write(s) finally: diff --git a/scripts/supybot-plugin-doc b/scripts/supybot-plugin-doc index c5b2950db..88f9a1159 100644 --- a/scripts/supybot-plugin-doc +++ b/scripts/supybot-plugin-doc @@ -46,7 +46,7 @@ if not os.path.exists('doc-conf'): registryFilename = os.path.join('doc-conf', 'doc.conf') try: - fd = file(registryFilename, 'w') + fd = open(registryFilename, 'w') fd.write(""" supybot.directories.data: doc-data supybot.directories.conf: doc-conf @@ -62,7 +62,7 @@ except EnvironmentError, e: error('Unable to open %s for writing.' % registryFilename) import supybot.registry as registry -registry.open(registryFilename) +registry.open_registry(registryFilename) import supybot.log as log import supybot.conf as conf @@ -228,7 +228,7 @@ def genDoc(m, options): path = os.path.join(options.outputDir, '%s.%s' % (Plugin.name, options.format)) try: - fd = file(path, 'w') + fd = open(path, 'w') except EnvironmentError, e: error('Unable to open %s for writing.' % path) f = getattr(Plugin, 'render%s' % options.format.upper(), None) diff --git a/scripts/supybot-test b/scripts/supybot-test index c0a500713..a950a07d9 100644 --- a/scripts/supybot-test +++ b/scripts/supybot-test @@ -43,7 +43,7 @@ if not os.path.exists('test-conf'): os.mkdir('test-conf') registryFilename = os.path.join('test-conf', 'test.conf') -fd = file(registryFilename, 'w') +fd = open(registryFilename, 'w') fd.write(""" supybot.directories.data: test-data supybot.directories.conf: test-conf @@ -62,7 +62,7 @@ supybot.databases.users.allowUnregistration: True fd.close() import supybot.registry as registry -registry.open(registryFilename) +registry.open_registry(registryFilename) import supybot.log as log import supybot.conf as conf @@ -159,7 +159,7 @@ if __name__ == '__main__': if options.trace: traceFilename = conf.supybot.directories.log.dirize('trace.log') - fd = file(traceFilename, 'w') + fd = open(traceFilename, 'w') sys.settrace(utils.gen.callTracer(fd)) atexit.register(fd.close) atexit.register(lambda : sys.settrace(None)) diff --git a/src/ircdb.py b/src/ircdb.py index a2b1495bd..1331f17f1 100644 --- a/src/ircdb.py +++ b/src/ircdb.py @@ -42,7 +42,7 @@ import supybot.world as world import supybot.ircutils as ircutils import supybot.registry as registry import supybot.unpreserve as unpreserve -from utils.iter import imap, ilen, ifilter +from itertools import imap, ifilter def isCapability(capability): return len(capability.split(None, 1)) == 1 @@ -844,7 +844,7 @@ class IgnoresDB(object): def open(self, filename): self.filename = filename - fd = file(self.filename) + fd = open(self.filename) for line in utils.file.nonCommentNonEmptyLines(fd): try: line = line.rstrip('\r\n') diff --git a/src/registry.py b/src/registry.py index c1f06b23b..03698b187 100644 --- a/src/registry.py +++ b/src/registry.py @@ -62,12 +62,12 @@ class NonExistentRegistryEntry(RegistryException): _cache = utils.InsensitivePreservingDict() _lastModified = 0 -def open(filename, clear=False): +def open_registry(filename, clear=False): """Initializes the module by loading the registry file into memory.""" global _lastModified if clear: _cache.clear() - _fd = file(filename) + _fd = open(filename) fd = utils.file.nonCommentNonEmptyLines(_fd) acc = '' slashEnd = re.compile(r'\\*$') diff --git a/src/unpreserve.py b/src/unpreserve.py index a275d94f0..66f9dca1f 100644 --- a/src/unpreserve.py +++ b/src/unpreserve.py @@ -40,7 +40,7 @@ class Reader(object): return s.lower() def readFile(self, filename): - self.read(file(filename)) + self.read(open(filename)) def read(self, fd): lineno = 0 diff --git a/src/utils/file.py b/src/utils/file.py index 50ab27c97..6f77f54bb 100644 --- a/src/utils/file.py +++ b/src/utils/file.py @@ -39,9 +39,9 @@ from iter import ifilter import crypt def contents(filename): - return file(filename).read() + return open(filename).read() -def open(filename, mode='wb', *args, **kwargs): +def open_mkdir(filename, mode='wb', *args, **kwargs): """filename -> file object. Returns a file object for filename, creating as many directories as may be @@ -53,15 +53,15 @@ def open(filename, mode='wb', *args, **kwargs): raise ValueError, 'utils.file.open expects to write.' (dirname, basename) = os.path.split(filename) os.makedirs(dirname) - return file(filename, mode, *args, **kwargs) + return open(filename, mode, *args, **kwargs) def copy(src, dst): """src, dst -> None Copies src to dst, using this module's 'open' function to open dst. """ - srcfd = file(src) - dstfd = open(dst, 'wb') + srcfd = open(src) + dstfd = open_mkdir(dst, 'wb') shutil.copyfileobj(srcfd, dstfd) def writeLine(fd, line): @@ -70,14 +70,14 @@ def writeLine(fd, line): fd.write('\n') def readLines(filename): - fd = file(filename) + fd = open(filename) try: return [line.rstrip('\r\n') for line in fd.readlines()] finally: fd.close() def touch(filename): - fd = file(filename, 'w') + fd = open(filename, 'w') fd.close() def mktemp(suffix=''): @@ -190,7 +190,7 @@ class AtomicFile(file): # rename a file (and shutil.move will use os.rename if # possible), we first check if we have the write permission # and only then do we write. - fd = file(self.filename, 'a') + fd = open(self.filename, 'a') fd.close() shutil.move(self.tempFilename, self.filename) diff --git a/src/utils/transaction.py b/src/utils/transaction.py index 5d4caeacf..82fea76bd 100644 --- a/src/utils/transaction.py +++ b/src/utils/transaction.py @@ -84,7 +84,7 @@ class TransactionMixin(python.Object): raise InvalidCwd(expected) def _journalCommands(self): - journal = file(self._journalName) + journal = open(self._journalName) for line in journal: line = line.rstrip('\n') (command, rest) = line.split(None, 1) @@ -112,8 +112,8 @@ class Transaction(TransactionMixin): raise FailedAcquisition(self.txnDir, e) os.mkdir(self.dirize(self.ORIGINALS)) os.mkdir(self.dirize(self.REPLACEMENTS)) - self._journal = file(self._journalName, 'a') - cwd = file(self.dirize('cwd'), 'w') + self._journal = open(self._journalName, 'a') + cwd = open(self.dirize('cwd'), 'w') cwd.write(os.getcwd()) cwd.close() @@ -179,7 +179,7 @@ class Transaction(TransactionMixin): self._journalCommand('append', filename, length) replacement = self._replacement(filename) File.copy(filename, replacement) - return file(replacement, 'a') + return open(replacement, 'a') def commit(self, removeWhenComplete=True): self._journal.close() @@ -218,7 +218,7 @@ class Rollback(TransactionMixin): shutil.copy(self._original(filename), filename) def rollbackAppend(self, filename, length): - fd = file(filename, 'a') + fd = open(filename, 'a') fd.truncate(int(length)) fd.close() diff --git a/test/test_registry.py b/test/test_registry.py index e92f98ba7..6d18d2148 100644 --- a/test/test_registry.py +++ b/test/test_registry.py @@ -171,7 +171,7 @@ class ValuesTestCase(SupyTestCase): conf.supybot.reply.whenAddressedBy.chars.set('\\') filename = conf.supybot.directories.conf.dirize('backslashes.conf') registry.close(conf.supybot, filename) - registry.open(filename) + registry.open_registry(filename) self.assertEqual(conf.supybot.reply.whenAddressedBy.chars(), '\\') # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: