diff --git a/build_tools/i18n/fonts.py b/build_tools/i18n/fonts.py index e125e59b2fc..7f10c1098d9 100644 --- a/build_tools/i18n/fonts.py +++ b/build_tools/i18n/fonts.py @@ -6,7 +6,6 @@ import argparse import base64 import functools -import io import json import logging import mimetypes @@ -354,7 +353,7 @@ def _write_inline_font(file_object, font_path, font_family, weight): """ Inlines a font as base64 encoding within a CSS file """ - with io.open(font_path, mode="rb") as f: + with open(font_path, mode="rb") as f: data = f.read() data_uri = "data:application/x-font-woff;charset=utf-8;base64,\\\n{}".format( "\\\n".join(_chunks(base64.b64encode(data).decode())) @@ -417,7 +416,7 @@ def _get_lang_strings(locale_dir): continue file_path = os.path.join(locale_dir, file_name) - with io.open(file_path, mode="r", encoding="utf-8") as f: + with open(file_path, mode="r", encoding="utf-8") as f: lang_strings = json.load(f).values() for s in lang_strings: diff --git a/build_tools/i18n/utils.py b/build_tools/i18n/utils.py index 4b96ec773b3..9c64772761c 100644 --- a/build_tools/i18n/utils.py +++ b/build_tools/i18n/utils.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import functools -import io import json import logging import os @@ -52,7 +51,7 @@ def available_languages(): Returns all available languages including English and in-context language. Callers should filter as needed. """ - with io.open(LANGUAGE_INFO_PATH, mode="r", encoding="utf-8") as f: + with open(LANGUAGE_INFO_PATH, mode="r", encoding="utf-8") as f: return json.load(f) @@ -88,7 +87,7 @@ def json_dump_formatted(data, file_path): os.makedirs(dir_name) # Format and write the JSON file - with io.open(file_path, mode="w+", encoding="utf-8") as file_object: + with open(file_path, mode="w+", encoding="utf-8") as file_object: # Manage unicode for the JSON dumping json.dump( data, diff --git a/docker/entrypoint.py b/docker/entrypoint.py index 2a5e0a15669..b5c22d4661c 100644 --- a/docker/entrypoint.py +++ b/docker/entrypoint.py @@ -13,13 +13,9 @@ import re import subprocess import sys - - -# py2+py3 compatible imports via http://python-future.org/compatible_idioms.html -try: - from urllib.request import Request, build_opener, HTTPRedirectHandler -except ImportError: - from urllib2 import Request, HTTPRedirectHandler, build_opener +from urllib.request import build_opener +from urllib.request import HTTPRedirectHandler +from urllib.request import Request logging.basicConfig(level=logging.INFO) diff --git a/kolibri/core/analytics/test/test_utils.py b/kolibri/core/analytics/test/test_utils.py index df5d6b11815..5fb63d651a9 100644 --- a/kolibri/core/analytics/test/test_utils.py +++ b/kolibri/core/analytics/test/test_utils.py @@ -2,7 +2,6 @@ import csv import datetime import hashlib -import io import os import random import uuid @@ -79,7 +78,7 @@ def setUpTestData(cls): # Load in the user data from the csv file to give a predictable source of user data data_path = os.path.join(USER_CSV_PATH) - with io.open(data_path, mode="r", encoding="utf-8") as f: + with open(data_path, mode="r", encoding="utf-8") as f: users = [data for data in csv.DictReader(f)] cls.facilities = user_data.get_or_create_facilities( diff --git a/kolibri/core/auth/constants/facility_presets.py b/kolibri/core/auth/constants/facility_presets.py index f0d826ad370..51464c8a210 100644 --- a/kolibri/core/auth/constants/facility_presets.py +++ b/kolibri/core/auth/constants/facility_presets.py @@ -1,11 +1,10 @@ -import io import json import os presets_file = os.path.abspath( os.path.join(os.path.dirname(__file__), "./facility_configuration_presets.json") ) -with io.open(presets_file, mode="r", encoding="utf-8") as f: +with open(presets_file, mode="r", encoding="utf-8") as f: presets = json.load(f) choices = [(key, key) for key in presets] diff --git a/kolibri/core/content/management/commands/generate_schema.py b/kolibri/core/content/management/commands/generate_schema.py index 269a8516d84..fb18261589c 100644 --- a/kolibri/core/content/management/commands/generate_schema.py +++ b/kolibri/core/content/management/commands/generate_schema.py @@ -1,5 +1,4 @@ import inspect -import io import json import os import shutil @@ -137,7 +136,7 @@ def handle(self, *args, **options): metadata, False, True, True, True, False, nocomments=False ) - with io.open( + with open( SQLALCHEMY_CLASSES_PATH_TEMPLATE.format( name=coerce_version_name_to_valid_module_path(version) ), @@ -157,7 +156,7 @@ def handle(self, *args, **options): data[table_name] = [get_dict(r) for r in session.query(record).all()] data_path = DATA_PATH_TEMPLATE.format(name=version) - with io.open(data_path, mode="w", encoding="utf-8") as f: + with open(data_path, mode="w", encoding="utf-8") as f: json.dump(data, f) shutil.rmtree( diff --git a/kolibri/core/content/test/test_channel_import.py b/kolibri/core/content/test/test_channel_import.py index aedff2adf33..2dd1eaef739 100644 --- a/kolibri/core/content/test/test_channel_import.py +++ b/kolibri/core/content/test/test_channel_import.py @@ -1,4 +1,3 @@ -import io import json import logging import os @@ -420,7 +419,7 @@ def set_content_fixture(self, db_path_mock): metadata = load_metadata(self.schema_name) data_path = DATA_PATH_TEMPLATE.format(name=self.data_name) - with io.open(data_path, mode="r", encoding="utf-8") as f: + with open(data_path, mode="r", encoding="utf-8") as f: data = json.load(f) metadata.bind = self.content_engine @@ -536,7 +535,7 @@ def alternate_existing_channel(request): class ContentImportDataTestBase(ContentImportTestBase): def set_content_fixture(self): data_path = DATA_PATH_TEMPLATE.format(name=self.data_name) - with io.open(data_path, mode="r", encoding="utf-8") as f: + with open(data_path, mode="r", encoding="utf-8") as f: data = json.load(f) self.content_engine = create_engine("sqlite://") @@ -553,7 +552,7 @@ def set_content_fixture(self): class ContentImportPartialChannelDataTestBase(ContentImportTestBase): def set_content_fixture(self): data_path = DATA_PATH_TEMPLATE.format(name=self.data_name) - with io.open(data_path, mode="r", encoding="utf-8") as fp: + with open(data_path, mode="r", encoding="utf-8") as fp: data = json.load(fp) self.content_engine = create_engine("sqlite://") diff --git a/kolibri/core/content/utils/paths.py b/kolibri/core/content/utils/paths.py index 04d0b4943ed..ec73fb1af3a 100644 --- a/kolibri/core/content/utils/paths.py +++ b/kolibri/core/content/utils/paths.py @@ -1,4 +1,3 @@ -import io import os import re @@ -293,7 +292,7 @@ def get_zip_content_base_path(): def get_sandbox_html_filename(): global SANDBOX_FILENAME if SANDBOX_FILENAME is None or getattr(settings, "DEVELOPER_MODE", None): - with io.open( + with open( os.path.abspath( os.path.join(os.path.dirname(__file__), "../build/sandbox_filename") ), diff --git a/kolibri/core/content/utils/stopwords.py b/kolibri/core/content/utils/stopwords.py index dfa1cb56c1c..1541cbae252 100644 --- a/kolibri/core/content/utils/stopwords.py +++ b/kolibri/core/content/utils/stopwords.py @@ -1,4 +1,3 @@ -import io import json import os @@ -8,7 +7,7 @@ os.path.dirname(__file__), os.path.pardir, "constants", "stopwords-all.json" ) ) -with io.open(stopwords_path, mode="r", encoding="utf-8") as f: +with open(stopwords_path, mode="r", encoding="utf-8") as f: stopwords = json.load(f) # load into a set diff --git a/kolibri/core/deviceadmin/utils.py b/kolibri/core/deviceadmin/utils.py index 9c3bc6940a5..73c2799a1b4 100644 --- a/kolibri/core/deviceadmin/utils.py +++ b/kolibri/core/deviceadmin/utils.py @@ -1,4 +1,3 @@ -import io import logging import os import re @@ -103,9 +102,8 @@ def dbbackup(old_version, dest_folder=None): backup_path = os.path.join(dest_folder, fname) - # Setting encoding=utf-8: io.open() is Python 2 compatible # See: https://github.com/learningequality/kolibri/issues/2875 - with io.open(backup_path, **KWARGS_IO_WRITE) as f: + with open(backup_path, **KWARGS_IO_WRITE) as f: # If the connection hasn't been opened yet, then open it if not db.connections["default"].connection: db.connections["default"].connect() @@ -138,7 +136,6 @@ def dbrestore(from_file): else: logger.info("In memory database, not truncating: {}".format(dst_file)) - # Setting encoding=utf-8: io.open() is Python 2 compatible # See: https://github.com/learningequality/kolibri/issues/2875 with open(from_file, **KWARGS_IO_READ) as f: db.connections["default"].connect() diff --git a/kolibri/core/logger/management/commands/generateuserdata.py b/kolibri/core/logger/management/commands/generateuserdata.py index 099f3731634..112930026bf 100644 --- a/kolibri/core/logger/management/commands/generateuserdata.py +++ b/kolibri/core/logger/management/commands/generateuserdata.py @@ -1,5 +1,4 @@ import csv -import io import logging import os import random @@ -111,7 +110,7 @@ def handle(self, *args, **options): data_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "user_data.csv") ) - with io.open(data_path, mode="r", encoding="utf-8") as f: + with open(data_path, mode="r", encoding="utf-8") as f: user_data = [data for data in csv.DictReader(f)] n_seed = options["seed"] diff --git a/kolibri/core/sqlite/utils.py b/kolibri/core/sqlite/utils.py index fdd01196a1a..535eef1b155 100644 --- a/kolibri/core/sqlite/utils.py +++ b/kolibri/core/sqlite/utils.py @@ -1,4 +1,3 @@ -import io import logging import os import sqlite3 @@ -110,7 +109,7 @@ def repair_sqlite_db(connection): # now, let's try to repair it, if possible: # os.remove(original_path) fixed_db_path = "{}.2".format(original_path) - with io.open(fixed_db_path, **KWARGS_IO_WRITE) as f: + with open(fixed_db_path, **KWARGS_IO_WRITE) as f: # If the connection hasn't been opened yet, then open it try: for line in connection.connection.iterdump(): diff --git a/kolibri/core/utils/nothing.py b/kolibri/core/utils/nothing.py index 336a9099d76..1f7f28b2d24 100644 --- a/kolibri/core/utils/nothing.py +++ b/kolibri/core/utils/nothing.py @@ -7,11 +7,9 @@ def __init__(self, kind=None): def __repr__(self): return "Nothing(%s)" % self.kind - def __nonzero__(self): + def __bool__(self): return False - __bool__ = __nonzero__ # this is for python3 - def __eq__(self, other): try: return self.kind == other.kind diff --git a/kolibri/core/webpack/hooks.py b/kolibri/core/webpack/hooks.py index c61d9d16e21..53dcd1bf254 100644 --- a/kolibri/core/webpack/hooks.py +++ b/kolibri/core/webpack/hooks.py @@ -6,7 +6,6 @@ you should put them in ``yourapp/assets/src``. """ import codecs -import io import json import logging import os @@ -176,7 +175,7 @@ def frontend_messages(self): lang_code = get_language() frontend_message_file = self.frontend_message_file(lang_code) if frontend_message_file: - with io.open(frontend_message_file, mode="r", encoding="utf-8") as f: + with open(frontend_message_file, mode="r", encoding="utf-8") as f: message_file_content = json.load(f) return message_file_content diff --git a/kolibri/plugins/qti_viewer/kolibri_plugin.py b/kolibri/plugins/qti_viewer/kolibri_plugin.py index 6f9f9df2983..04752095786 100644 --- a/kolibri/plugins/qti_viewer/kolibri_plugin.py +++ b/kolibri/plugins/qti_viewer/kolibri_plugin.py @@ -1,7 +1,3 @@ -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals - from le_utils.constants import format_presets from kolibri.core.content import hooks as content_hooks diff --git a/kolibri/utils/i18n.py b/kolibri/utils/i18n.py index 74e2c578c2f..589c14fa161 100644 --- a/kolibri/utils/i18n.py +++ b/kolibri/utils/i18n.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import importlib -import io import json import locale import os @@ -32,7 +31,7 @@ def _get_language_info(): file_path = os.path.abspath( os.path.join(os.path.dirname(kolibri.__file__), "locale", "language_info.json") ) - with io.open(file_path, encoding="utf-8") as f: + with open(file_path, encoding="utf-8") as f: languages = json.load(f) output = {} for language in languages: diff --git a/kolibri/utils/pskolibri/common.py b/kolibri/utils/pskolibri/common.py index 829c61f3676..ae012013f4a 100644 --- a/kolibri/utils/pskolibri/common.py +++ b/kolibri/utils/pskolibri/common.py @@ -1,5 +1,4 @@ import functools -import io import os import sys from collections import namedtuple @@ -129,7 +128,7 @@ def cache_deactivate(): def open_binary(fname, **kwargs): - return io.open(fname, "rb", **kwargs) + return open(fname, "rb", **kwargs) def open_text(fname, **kwargs): @@ -138,4 +137,4 @@ def open_text(fname, **kwargs): """ kwargs.setdefault("encoding", ENCODING) kwargs.setdefault("errors", ENCODING_ERRS) - return io.open(fname, "rt", **kwargs) + return open(fname, "rt", **kwargs)