Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions build_tools/i18n/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import argparse
import base64
import functools
import io
import json
import logging
import mimetypes
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions build_tools/i18n/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import functools
import io
import json
import logging
import os
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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,
Expand Down
10 changes: 3 additions & 7 deletions docker/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions kolibri/core/analytics/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import csv
import datetime
import hashlib
import io
import os
import random
import uuid
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions kolibri/core/auth/constants/facility_presets.py
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
5 changes: 2 additions & 3 deletions kolibri/core/content/management/commands/generate_schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import inspect
import io
import json
import os
import shutil
Expand Down Expand Up @@ -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)
),
Expand All @@ -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(
Expand Down
7 changes: 3 additions & 4 deletions kolibri/core/content/test/test_channel_import.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import io
import json
import logging
import os
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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://")

Expand All @@ -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://")

Expand Down
3 changes: 1 addition & 2 deletions kolibri/core/content/utils/paths.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import io
import os
import re

Expand Down Expand Up @@ -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")
),
Expand Down
3 changes: 1 addition & 2 deletions kolibri/core/content/utils/stopwords.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import io
import json
import os

Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions kolibri/core/deviceadmin/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import io
import logging
import os
import re
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions kolibri/core/logger/management/commands/generateuserdata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import csv
import io
import logging
import os
import random
Expand Down Expand Up @@ -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"]
Expand Down
3 changes: 1 addition & 2 deletions kolibri/core/sqlite/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import io
import logging
import os
import sqlite3
Expand Down Expand Up @@ -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():
Expand Down
4 changes: 1 addition & 3 deletions kolibri/core/utils/nothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions kolibri/core/webpack/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
you should put them in ``yourapp/assets/src``.
"""
import codecs
import io
import json
import logging
import os
Expand Down Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions kolibri/plugins/qti_viewer/kolibri_plugin.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions kolibri/utils/i18n.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import importlib
import io
import json
import locale
import os
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions kolibri/utils/pskolibri/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import functools
import io
import os
import sys
from collections import namedtuple
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Loading