You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2020/02/20 18:23:13 UTC
[allura] branch db/8351 created (now a66a778)
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a change to branch db/8351
in repository https://gitbox.apache.org/repos/asf/allura.git.
at a66a778 [#8351] use codecs.open instead of io.open when dumping json https://stackoverflow.com/a/31343739/
This branch includes the following new commits:
new a66a778 [#8351] use codecs.open instead of io.open when dumping json https://stackoverflow.com/a/31343739/
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[allura] 01/01: [#8351] use codecs.open instead of io.open when
dumping json https://stackoverflow.com/a/31343739/
Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch db/8351
in repository https://gitbox.apache.org/repos/asf/allura.git
commit a66a778597e0b708c669cedac2f3cc36d4600903
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Thu Feb 20 13:22:10 2020 -0500
[#8351] use codecs.open instead of io.open when dumping json https://stackoverflow.com/a/31343739/
---
Allura/allura/scripts/trac_export.py | 4 ++--
Allura/allura/tasks/export_tasks.py | 4 ++--
Allura/allura/tests/test_tasks.py | 4 +---
ForgeImporters/forgeimporters/base.py | 4 ++--
ForgeImporters/forgeimporters/tests/test_base.py | 4 ++--
scripts/teamforge-import.py | 7 ++++---
scripts/trac_export_wiki.py | 4 ++--
7 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/Allura/allura/scripts/trac_export.py b/Allura/allura/scripts/trac_export.py
index 9d6a991..6b47385 100644
--- a/Allura/allura/scripts/trac_export.py
+++ b/Allura/allura/scripts/trac_export.py
@@ -30,12 +30,12 @@ import time
import re
from optparse import OptionParser
from itertools import islice
+import codecs
from bs4 import BeautifulSoup, NavigableString
import dateutil.parser
import pytz
import six
-from io import open
try:
from forgeimporters.base import ProjectExtractor
@@ -326,7 +326,7 @@ def main():
out_file = sys.stdout
if options.out_filename:
- out_file = open(options.out_filename, 'w')
+ out_file = codecs.open(options.out_filename, 'w', encoding='utf-8')
out_file.write(
json.dumps(doc, cls=DateJSONEncoder, indent=2, sort_keys=True))
# It's bad habit not to terminate lines
diff --git a/Allura/allura/tasks/export_tasks.py b/Allura/allura/tasks/export_tasks.py
index dfc4d61..9693e1a 100644
--- a/Allura/allura/tasks/export_tasks.py
+++ b/Allura/allura/tasks/export_tasks.py
@@ -21,6 +21,7 @@ import os
import os.path
import logging
import shutil
+import codecs
import tg
from tg import app_globals as g, tmpl_context as c
@@ -29,7 +30,6 @@ from allura.tasks import mail_tasks
from allura.lib.decorators import task
from allura.lib import helpers as h
from allura.model.repository import zipdir
-from io import open
log = logging.getLogger(__name__)
@@ -102,7 +102,7 @@ class BulkExport(object):
tool = app.config.options.mount_point
json_file = os.path.join(export_path, '%s.json' % tool)
try:
- with open(json_file, 'w') as f:
+ with codecs.open(json_file, 'w', encoding='utf-8') as f:
app.bulk_export(f, export_path, with_attachments)
except Exception:
log.error('Error exporting: %s on %s', tool,
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index 79e873c..8f63478 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -641,12 +641,10 @@ class TestExportTasks(unittest.TestCase):
@mock.patch('allura.tasks.export_tasks.shutil')
@mock.patch('allura.tasks.export_tasks.zipdir')
- @mock.patch('forgewiki.wiki_main.ForgeWikiApp.bulk_export')
@td.with_wiki
- def test_bulk_export(self, wiki_bulk_export, zipdir, shutil):
+ def test_bulk_export(self, zipdir, shutil):
M.MonQTask.query.remove()
export_tasks.bulk_export(['wiki'])
- assert_equal(wiki_bulk_export.call_count, 1)
temp = '/tmp/bulk_export/p/test/test'
zipfn = '/tmp/bulk_export/p/test/test.zip'
zipdir.assert_called_with(temp, zipfn)
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index 14ceeb1..f4e78c9 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -26,7 +26,7 @@ from collections import defaultdict
import traceback
from six.moves.urllib.parse import urlparse
from datetime import datetime
-from io import open
+import codecs
from six.moves import filter
import six
try:
@@ -665,6 +665,6 @@ def save_importer_upload(project, filename, data):
except OSError as e:
if e.errno != errno.EEXIST:
raise
- with open(dest_file, 'w') as fp:
+ with codecs.open(dest_file, 'w', encoding='utf-8') as fp:
fp.write(data)
return dest_file
diff --git a/ForgeImporters/forgeimporters/tests/test_base.py b/ForgeImporters/forgeimporters/tests/test_base.py
index 8049ea5..f23ee8f 100644
--- a/ForgeImporters/forgeimporters/tests/test_base.py
+++ b/ForgeImporters/forgeimporters/tests/test_base.py
@@ -367,10 +367,10 @@ def test_save_importer_upload(giup, os):
os.makedirs.side_effect = OSError(errno.EEXIST, 'foo')
_open = mock.MagicMock()
fp = _open.return_value.__enter__.return_value
- with mock.patch.object(base, 'open', _open):
+ with mock.patch.object(base.codecs, 'open', _open):
base.save_importer_upload('project', 'file', 'data')
os.makedirs.assert_called_once_with('path')
- _open.assert_called_once_with('path/file', 'w')
+ _open.assert_called_once_with('path/file', 'w', encoding='utf-8')
fp.write.assert_called_once_with('data')
os.makedirs.side_effect = OSError(errno.EACCES, 'foo')
diff --git a/scripts/teamforge-import.py b/scripts/teamforge-import.py
index 25fa95f..44a4483 100644
--- a/scripts/teamforge-import.py
+++ b/scripts/teamforge-import.py
@@ -35,6 +35,7 @@ from datetime import datetime
from six.moves.configparser import ConfigParser
import random
import string
+import codecs
import sqlalchemy
from suds.client import Client
@@ -161,7 +162,7 @@ def main():
get_news(project)
if not options.skip_unsupported_check:
check_unsupported_tools(project)
- with open(os.path.join(options.output_dir, 'users.json'), 'w') as user_file:
+ with codecs.open(os.path.join(options.output_dir, 'users.json'), 'w', encoding='utf-8') as user_file:
json.dump(users, user_file, default=str)
except:
log.exception('Error extracting %s' % pid)
@@ -681,7 +682,7 @@ def save(content, project, *paths):
out_file = os.path.join(options.output_dir, project.id, *paths)
if not os.path.exists(os.path.dirname(out_file)):
os.makedirs(os.path.dirname(out_file))
- with open(out_file, 'w') as out:
+ with codecs.open(out_file, 'w', encoding='utf-8') as out:
out.write(content.encode('utf-8'))
@@ -717,7 +718,7 @@ def download_file(tool, url_path, *filepaths):
'returnToUrl': url,
'sfsubmit': 'submit'
}))
- with open(out_file, 'w') as out:
+ with codecs.open(out_file, 'w', encoding='utf-8') as out:
out.write(resp.fp.read())
return out_file
diff --git a/scripts/trac_export_wiki.py b/scripts/trac_export_wiki.py
index d698c04..8cf4089 100755
--- a/scripts/trac_export_wiki.py
+++ b/scripts/trac_export_wiki.py
@@ -21,9 +21,9 @@ from __future__ import unicode_literals
from __future__ import absolute_import
import sys
from optparse import OptionParser
+import codecs
from tracwikiimporter.scripts.wiki_from_trac.extractors import WikiExporter
-from io import open
def parse_options():
@@ -54,6 +54,6 @@ if __name__ == '__main__':
out = sys.stdout
if options.out_filename:
- out = open(options.out_filename, 'w')
+ out = codecs.open(options.out_filename, 'w', encoding='utf-8')
exporter.export(out)