From 1e9eb875a64dfc65d786f4c6a52f6ba08b25b86b Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 14 Feb 2021 10:33:26 -0800 Subject: [PATCH] Switch from codecs.getreader to io.TextIOWrapper, refs #230 --- sqlite_utils/cli.py | 4 ++-- sqlite_utils/utils.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sqlite_utils/cli.py b/sqlite_utils/cli.py index 03ac3f5..3cb61af 100644 --- a/sqlite_utils/cli.py +++ b/sqlite_utils/cli.py @@ -1,6 +1,5 @@ import base64 import click -import codecs from click_default_group import DefaultGroup from datetime import datetime import hashlib @@ -8,6 +7,7 @@ import pathlib import sqlite_utils from sqlite_utils.db import AlterError import textwrap +import io import itertools import json import os @@ -665,7 +665,7 @@ def insert_upsert_implementation( if encoding and not (csv or tsv): raise click.ClickException("--encoding must be used with --csv or --tsv") encoding = encoding or "utf-8" - json_file = codecs.getreader(encoding)(json_file) + json_file = io.TextIOWrapper(json_file, encoding=encoding) if pk and len(pk) == 1: pk = pk[0] if csv or tsv: diff --git a/sqlite_utils/utils.py b/sqlite_utils/utils.py index a158b2b..9d5dac6 100644 --- a/sqlite_utils/utils.py +++ b/sqlite_utils/utils.py @@ -105,9 +105,9 @@ class UpdateWrapper: @contextlib.contextmanager def file_progress(file, silent=False, **kwargs): - if silent or file.raw.fileno() == 0: # 0 = stdin + if silent or file.fileno() == 0: # 0 = stdin yield file else: - file_length = os.path.getsize(file.raw.name) + file_length = os.path.getsize(file.name) with click.progressbar(length=file_length, **kwargs) as bar: yield UpdateWrapper(file, bar.update)