From a86890002ffe48e9d66f364bc21d6ff59708aefb Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Mon, 5 Oct 2015 19:20:08 +0100 Subject: [PATCH] Remove redundant io imports --- gramps/cli/clidbman.py | 11 +++++------ gramps/cli/test/cli_test.py | 7 +++---- gramps/gen/dbstate.py | 7 +++---- gramps/gen/filters/_filterlist.py | 5 ++--- gramps/gen/plug/_pluginreg.py | 3 +-- gramps/gen/plug/docbackend/docbackend.py | 3 +-- gramps/gen/plug/report/_options.py | 6 +++--- gramps/gen/utils/configmanager.py | 3 +-- gramps/gen/utils/file.py | 3 +-- gramps/gen/utils/resourcepath.py | 3 +-- gramps/gui/aboutdialog.py | 3 +-- gramps/gui/widgets/grampletbar.py | 3 +-- gramps/gui/widgets/grampletpane.py | 3 +-- gramps/plugins/database/bsddb_support/write.py | 3 +-- gramps/plugins/docgen/asciidoc.py | 4 +--- gramps/plugins/export/exportgedcom.py | 3 +-- gramps/plugins/importer/importprogen.py | 4 +--- 17 files changed, 28 insertions(+), 46 deletions(-) diff --git a/gramps/cli/clidbman.py b/gramps/cli/clidbman.py index 9f0a29c7e..0803d7307 100644 --- a/gramps/cli/clidbman.py +++ b/gramps/cli/clidbman.py @@ -33,7 +33,6 @@ creating, and deleting of databases. import os import sys import time -import io from urllib.parse import urlparse from urllib.request import urlopen, url2pathname import tempfile @@ -200,7 +199,7 @@ class CLIDbManager(object): dirpath = os.path.join(dbdir, dpath) path_name = os.path.join(dirpath, NAME_FILE) if os.path.isfile(path_name): - file = io.open(path_name, 'r', encoding='utf8') + file = open(path_name, 'r', encoding='utf8') name = file.readline().strip() file.close() @@ -259,7 +258,7 @@ class CLIDbManager(object): name_list = [ name[0] for name in self.current_names ] title = find_next_db_name(name_list) - name_file = io.open(path_name, "w", encoding='utf8') + name_file = open(path_name, "w", encoding='utf8') name_file.write(title) name_file.close() @@ -372,10 +371,10 @@ class CLIDbManager(object): try: filepath = conv_to_unicode(filepath, 'utf8') new_text = conv_to_unicode(new_text, 'utf8') - name_file = io.open(filepath, "r", encoding='utf8') + name_file = open(filepath, "r", encoding='utf8') old_text=name_file.read() name_file.close() - name_file = io.open(filepath, "w", encoding='utf8') + name_file = open(filepath, "w", encoding='utf8') name_file.write(new_text) name_file.close() except (OSError, IOError) as msg: @@ -477,7 +476,7 @@ def find_locker_name(dirpath): """ try: fname = os.path.join(dirpath, "lock") - ifile = io.open(fname, 'r', encoding='utf8') + ifile = open(fname, 'r', encoding='utf8') username = ifile.read().strip() # feature request 2356: avoid genitive form last = _("Locked by %s") % username diff --git a/gramps/cli/test/cli_test.py b/gramps/cli/test/cli_test.py index cc9f08497..60127538c 100644 --- a/gramps/cli/test/cli_test.py +++ b/gramps/cli/test/cli_test.py @@ -24,7 +24,6 @@ import sys import os import unittest import re -import io import subprocess from gramps.gen.const import TEMP_DIR @@ -55,7 +54,7 @@ class Test(unittest.TestCase): @classmethod def setUpClass(cls): if not os.path.exists(min1r): - with io.open(min1r, "w") as f: + with open(min1r, "w") as f: f.write(test_ged) @classmethod @@ -86,7 +85,7 @@ class Test(unittest.TestCase): "executed CLI command %r" % gcmd) # simple validation o output self.assertTrue(os.path.isfile(ofile), "output file created") - with io.open(ofile) as f: + with open(ofile) as f: content = f.read() g = re.search("INDI", content) self.assertTrue(g, "found 'INDI' in output file") @@ -102,7 +101,7 @@ class Test(unittest.TestCase): pass bogofiles = [os.path.join(ddir, fn) for fn in ("family.db", "lock")] for fn in bogofiles: - with io.open(fn, "w") as f: + with open(fn, "w") as f: f.write("garbage") # ~same as test 2 diff --git a/gramps/gen/dbstate.py b/gramps/gen/dbstate.py index be17e6439..ee57f231e 100644 --- a/gramps/gen/dbstate.py +++ b/gramps/gen/dbstate.py @@ -24,7 +24,6 @@ Provide the database state class """ import sys import os -import io from .db import DbReadBase from .proxy.proxybase import ProxyDbBase @@ -190,7 +189,7 @@ class DbState(Callback): dirpath = os.path.join(dbdir, dpath) path_name = os.path.join(dirpath, "name.txt") if os.path.isfile(path_name): - file = io.open(path_name, 'r', encoding='utf8') + file = open(path_name, 'r', encoding='utf8') name = file.readline().strip() file.close() if dbname == name: @@ -199,14 +198,14 @@ class DbState(Callback): backend = None fname = os.path.join(dirpath, "database.txt") if os.path.isfile(fname): - ifile = io.open(fname, 'r', encoding='utf8') + ifile = open(fname, 'r', encoding='utf8') backend = ifile.read().strip() ifile.close() else: backend = "bsddb" try: fname = os.path.join(dirpath, "lock") - ifile = io.open(fname, 'r', encoding='utf8') + ifile = open(fname, 'r', encoding='utf8') locked_by = ifile.read().strip() locked = True ifile.close() diff --git a/gramps/gen/filters/_filterlist.py b/gramps/gen/filters/_filterlist.py index 3c308c26c..745cb54f0 100644 --- a/gramps/gen/filters/_filterlist.py +++ b/gramps/gen/filters/_filterlist.py @@ -27,7 +27,6 @@ from xml.sax import make_parser, SAXParseException import os import sys import collections -import io #------------------------------------------------------------------------- # @@ -104,7 +103,7 @@ class FilterList(object): if os.path.isfile(self.file): parser = make_parser() parser.setContentHandler(FilterParser(self)) - the_file = io.open(self.file, 'r', encoding='utf8') + the_file = open(self.file, 'r', encoding='utf8') parser.parse(the_file) the_file.close() except (IOError, OSError): @@ -121,7 +120,7 @@ class FilterList(object): return l.replace('"', '"') def save(self): - f = io.open(self.file, 'w', encoding='utf8') + f = open(self.file, 'w', encoding='utf8') f.write("\n") f.write('\n') for namespace in self.filter_namespaces: diff --git a/gramps/gen/plug/_pluginreg.py b/gramps/gen/plug/_pluginreg.py index 368a90f8f..ab8474502 100644 --- a/gramps/gen/plug/_pluginreg.py +++ b/gramps/gen/plug/_pluginreg.py @@ -33,7 +33,6 @@ import os import sys import re import traceback -import io #------------------------------------------------------------------------- # @@ -1131,7 +1130,7 @@ class PluginRegister(object): lenpd = len(self.__plugindata) full_filename = os.path.join(dir, filename) try: - fd = io.open(full_filename, "r", encoding='utf-8') + fd = open(full_filename, "r", encoding='utf-8') except Exception as msg: print(_('ERROR: Failed reading plugin registration %(filename)s') % \ {'filename' : filename}) diff --git a/gramps/gen/plug/docbackend/docbackend.py b/gramps/gen/plug/docbackend/docbackend.py index e4cb1aa88..e2182d223 100644 --- a/gramps/gen/plug/docbackend/docbackend.py +++ b/gramps/gen/plug/docbackend/docbackend.py @@ -28,7 +28,6 @@ #------------------------------------------------------------------------ from ...const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext -import io #------------------------------------------------------------------------ # @@ -143,7 +142,7 @@ class DocBackend(object): % self.filename) self._checkfilename() try: - self.__file = io.open(self.filename, "w", encoding="utf-8") + self.__file = open(self.filename, "w", encoding="utf-8") except IOError as msg: errmsg = "%s\n%s" % (_("Could not create %s") % self.filename, msg) raise DocBackendError(errmsg) diff --git a/gramps/gen/plug/report/_options.py b/gramps/gen/plug/report/_options.py index 5d78c612b..d760976b3 100644 --- a/gramps/gen/plug/report/_options.py +++ b/gramps/gen/plug/report/_options.py @@ -32,7 +32,7 @@ Report option handling, including saving and parsing. # Standard Python modules # #------------------------------------------------------------------------- -import os, io +import os import copy from xml.sax.saxutils import escape @@ -504,7 +504,7 @@ class OptionListCollection(_options.OptionListCollection): if os.path.isfile(self.filename): p = make_parser() p.setContentHandler(OptionParser(self)) - the_file = io.open(self.filename, encoding="utf-8") + the_file = open(self.filename, encoding="utf-8") p.parse(the_file) the_file.close() except (IOError, OSError, SAXParseException): @@ -1000,7 +1000,7 @@ class DocOptionListCollection(_options.OptionListCollection): if os.path.isfile(self.filename): p = make_parser() p.setContentHandler(DocOptionParser(self)) - the_file = io.open(self.filename, encoding="utf-8") + the_file = open(self.filename, encoding="utf-8") p.parse(the_file) the_file.close() except (IOError, OSError, SAXParseException): diff --git a/gramps/gen/utils/configmanager.py b/gramps/gen/utils/configmanager.py index c7199e333..6947671f7 100644 --- a/gramps/gen/utils/configmanager.py +++ b/gramps/gen/utils/configmanager.py @@ -36,7 +36,6 @@ import configparser import errno import copy import logging -import io from ..const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext @@ -334,7 +333,7 @@ class ConfigManager(object): if exp.errno != errno.EEXIST: raise try: - key_file = io.open(filename, "w", encoding="utf-8") + key_file = open(filename, "w", encoding="utf-8") except IOError as err: logging.warn("Failed to open %s because %s", filename, str(err)) diff --git a/gramps/gen/utils/file.py b/gramps/gen/utils/file.py index 18ca99388..ef687cc26 100644 --- a/gramps/gen/utils/file.py +++ b/gramps/gen/utils/file.py @@ -32,7 +32,6 @@ File and folder related utility functions import os import sys import shutil -import io import hashlib import logging LOG = logging.getLogger(".gen.utils.file") @@ -228,7 +227,7 @@ def create_checksum(full_path): """ full_path = os.path.normpath(full_path) try: - with io.open(full_path, 'rb') as media_file: + with open(full_path, 'rb') as media_file: md5sum = hashlib.md5(media_file.read()).hexdigest() except IOError: md5sum = '' diff --git a/gramps/gen/utils/resourcepath.py b/gramps/gen/utils/resourcepath.py index 11beac187..49c243514 100644 --- a/gramps/gen/utils/resourcepath.py +++ b/gramps/gen/utils/resourcepath.py @@ -18,7 +18,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # import sys -import io import os import logging LOG = logging.getLogger("ResourcePath") @@ -61,7 +60,7 @@ class ResourcePath(object): resource_path = tmp_path elif installed: try: - with io.open(resource_file, encoding='utf-8', + with open(resource_file, encoding='utf-8', errors='strict') as fp: resource_path = conv_to_unicode(fp.readline()) except UnicodeError as err: diff --git a/gramps/gui/aboutdialog.py b/gramps/gui/aboutdialog.py index ceeccd4ef..c9ddcf795 100644 --- a/gramps/gui/aboutdialog.py +++ b/gramps/gui/aboutdialog.py @@ -27,7 +27,6 @@ #------------------------------------------------------------------------- import os import sys -import io ##import logging ##_LOG = logging.getLogger(".GrampsAboutDialog") @@ -215,7 +214,7 @@ def _get_authors(): parser = make_parser() parser.setContentHandler(AuthorParser(authors, contributors)) - authors_file = io.open(AUTHORS_FILE, encoding='utf-8') + authors_file = open(AUTHORS_FILE, encoding='utf-8') parser.parse(authors_file) authors_file.close() diff --git a/gramps/gui/widgets/grampletbar.py b/gramps/gui/widgets/grampletbar.py index c7266a731..20c1b90c6 100644 --- a/gramps/gui/widgets/grampletbar.py +++ b/gramps/gui/widgets/grampletbar.py @@ -42,7 +42,6 @@ _ = glocale.translation.gettext import time import os import configparser -import io #------------------------------------------------------------------------- # @@ -198,7 +197,7 @@ class GrampletBar(Gtk.Notebook): """ filename = self.configfile try: - fp = io.open(filename, "w", encoding='utf-8') + fp = open(filename, "w", encoding='utf-8') except IOError: LOG.warning("Failed writing '%s'; gramplets not saved" % filename) return diff --git a/gramps/gui/widgets/grampletpane.py b/gramps/gui/widgets/grampletpane.py index bfe5ca4c9..d55852590 100644 --- a/gramps/gui/widgets/grampletpane.py +++ b/gramps/gui/widgets/grampletpane.py @@ -33,7 +33,6 @@ from gi.repository import Gtk from gi.repository import Pango import time import os -import io import configparser import logging @@ -1184,7 +1183,7 @@ class GrampletPane(Gtk.ScrolledWindow): return # something is the matter filename = self.configfile try: - fp = io.open(filename, "w", encoding='utf-8') + fp = open(filename, "w", encoding='utf-8') except IOError as err: LOG.warn("Failed to open %s because $s; gramplets not saved", filename, str(err)) diff --git a/gramps/plugins/database/bsddb_support/write.py b/gramps/plugins/database/bsddb_support/write.py index ccd7b3f2a..949fa4f1c 100644 --- a/gramps/plugins/database/bsddb_support/write.py +++ b/gramps/plugins/database/bsddb_support/write.py @@ -35,7 +35,6 @@ import pickle import os import time import bisect -import io from functools import wraps import logging from sys import maxsize, getfilesystemencoding, version_info @@ -2613,7 +2612,7 @@ def clear_lock_file(name): def write_lock_file(name): if not os.path.isdir(name): os.mkdir(name) - f = io.open(os.path.join(name, DBLOCKFN), "w", encoding='utf8') + f = open(os.path.join(name, DBLOCKFN), "w", encoding='utf8') if win(): user = get_env_var('USERNAME') host = get_env_var('USERDOMAIN') diff --git a/gramps/plugins/docgen/asciidoc.py b/gramps/plugins/docgen/asciidoc.py index a91105c29..5bda7d2aa 100644 --- a/gramps/plugins/docgen/asciidoc.py +++ b/gramps/plugins/docgen/asciidoc.py @@ -28,7 +28,6 @@ # python modules # #------------------------------------------------------------------------ -import io import sys #------------------------------------------------------------------------ @@ -156,8 +155,7 @@ class AsciiDoc(BaseDoc, TextDoc): self.filename = filename try: - self.f = io.open(self.filename,"w", - errors = 'backslashreplace') + self.f = open(self.filename, "w", errors = 'backslashreplace') except Exception as msg: errmsg = "%s\n%s" % (_("Could not create %s") % self.filename, msg) raise ReportError(errmsg) diff --git a/gramps/plugins/export/exportgedcom.py b/gramps/plugins/export/exportgedcom.py index 72a0e5c3f..c56dda299 100644 --- a/gramps/plugins/export/exportgedcom.py +++ b/gramps/plugins/export/exportgedcom.py @@ -34,7 +34,6 @@ #------------------------------------------------------------------------- import os import time -import io #------------------------------------------------------------------------- # @@ -239,7 +238,7 @@ class GedcomWriter(UpdateCallback): """ self.dirname = os.path.dirname (filename) - self.gedcom_file = io.open(filename, "w", encoding='utf-8') + self.gedcom_file = open(filename, "w", encoding='utf-8') self._header(filename) self._submitter() self._individuals() diff --git a/gramps/plugins/importer/importprogen.py b/gramps/plugins/importer/importprogen.py index fd365990b..ef64b8df9 100644 --- a/gramps/plugins/importer/importprogen.py +++ b/gramps/plugins/importer/importprogen.py @@ -468,10 +468,8 @@ class PG30_Def: raise ProgenError(_("Cannot find DEF file: %(deffname)s") % locals()) # This can throw a IOError - import io lines = None - with io.open(fname, buffering=1, - encoding='cp437', errors='strict') as f: + with open(fname, buffering=1, encoding='cp437', errors='strict') as f: lines = f.readlines() lines = [l.strip() for l in lines] content = '\n'.join(lines).encode('utf-8')