mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-10-07 18:07:03 +02:00
Switch from codecs.getreader to io.TextIOWrapper, refs #230
This commit is contained in:
parent
726219c350
commit
1e9eb875a6
2 changed files with 4 additions and 4 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
import base64
|
import base64
|
||||||
import click
|
import click
|
||||||
import codecs
|
|
||||||
from click_default_group import DefaultGroup
|
from click_default_group import DefaultGroup
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
@ -8,6 +7,7 @@ import pathlib
|
||||||
import sqlite_utils
|
import sqlite_utils
|
||||||
from sqlite_utils.db import AlterError
|
from sqlite_utils.db import AlterError
|
||||||
import textwrap
|
import textwrap
|
||||||
|
import io
|
||||||
import itertools
|
import itertools
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
@ -665,7 +665,7 @@ def insert_upsert_implementation(
|
||||||
if encoding and not (csv or tsv):
|
if encoding and not (csv or tsv):
|
||||||
raise click.ClickException("--encoding must be used with --csv or --tsv")
|
raise click.ClickException("--encoding must be used with --csv or --tsv")
|
||||||
encoding = encoding or "utf-8"
|
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:
|
if pk and len(pk) == 1:
|
||||||
pk = pk[0]
|
pk = pk[0]
|
||||||
if csv or tsv:
|
if csv or tsv:
|
||||||
|
|
|
||||||
|
|
@ -105,9 +105,9 @@ class UpdateWrapper:
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def file_progress(file, silent=False, **kwargs):
|
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
|
yield file
|
||||||
else:
|
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:
|
with click.progressbar(length=file_length, **kwargs) as bar:
|
||||||
yield UpdateWrapper(file, bar.update)
|
yield UpdateWrapper(file, bar.update)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue