1
0
Fork 0
mirror of https://github.com/veekun/pokedex.git synced 2024-08-20 18:16:34 +00:00

Open CSVs with io.open, rather than using six.

This commit is contained in:
qvalador 2018-08-23 00:17:56 -04:00
parent 65127e83e0
commit 8406878eee
2 changed files with 7 additions and 17 deletions

View file

@ -5,6 +5,7 @@ import csv
import fnmatch
import os.path
import sys
from io import open
import six
import sqlalchemy.sql.util
@ -16,7 +17,6 @@ from pokedex.defaults import get_default_csv_dir
from pokedex.db.dependencies import find_dependent_tables
from pokedex.db.oracle import rewrite_long_table_names
def _get_table_names(metadata, patterns):
"""Returns a list of table names from the given metadata. If `patterns`
exists, only tables matching one of the patterns will be returned.
@ -210,10 +210,7 @@ def load(session, tables=[], directory=None, drop_tables=False, verbose=False, s
try:
csvpath = "%s/%s.csv" % (directory, table_name)
if six.PY2:
csvfile = open(csvpath, 'r')
else:
csvfile = open(csvpath, 'r', encoding="utf8")
csvfile = open(csvpath, 'r', encoding='utf-8')
except IOError:
# File doesn't exist; don't load anything!
print_done('missing?')
@ -419,7 +416,7 @@ def dump(session, tables=[], directory=None, verbose=False, langs=None):
# CSV module only works with bytes on 2 and only works with text on 3!
if six.PY3:
writer = csv.writer(open(filename, 'w', newline='', encoding="utf8"), lineterminator='\n')
writer = csv.writer(open(filename, 'w', newline='', encoding='utf-8'), lineterminator='\n')
columns = [col.name for col in table.columns]
else:
writer = csv.writer(open(filename, 'wb'), lineterminator='\n')

View file

@ -25,10 +25,10 @@ from __future__ import print_function
import binascii
import csv
import io
import os
import re
from collections import defaultdict
from io import open
import six
from six.moves import zip
@ -262,15 +262,11 @@ class Translations(object):
def reader_for_class(self, cls, reader_class=csv.reader):
tablename = cls.__table__.name
csvpath = os.path.join(self.csv_directory, tablename + '.csv')
if six.PY2:
read = open(csvpath, 'r')
else:
read = open(csvpath, 'r', encoding='utf-8')
return reader_class(read, lineterminator='\n')
return reader_class(open(csvpath, 'r', encoding='utf-8'), lineterminator='\n')
def writer_for_lang(self, lang):
csvpath = os.path.join(self.translation_directory, '%s.csv' % lang)
return csv.writer(io.open(csvpath, 'w', newline='', encoding="utf8"), lineterminator='\n')
return csv.writer(open(csvpath, 'w', encoding='utf-8', newline=''), lineterminator='\n')
def yield_source_messages(self, language_id=None):
"""Yield all messages from source CSV files
@ -311,10 +307,7 @@ class Translations(object):
"""
path = os.path.join(self.csv_directory, 'translations', '%s.csv' % lang)
try:
if six.PY2:
file = open(path, 'r')
else:
file = open(path, 'r', encoding="utf8")
file = open(path, 'r', encoding='utf-8')
except IOError:
return ()
return yield_translation_csv_messages(file)