summaryrefslogtreecommitdiffstats
path: root/bin/repoman
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-07-10 16:26:24 -0700
committerZac Medico <zmedico@gentoo.org>2011-07-10 16:55:05 -0700
commit8cc8d12a674ab6271183e5c35202263a36497279 (patch)
tree22365e2c613d04151a2d2da5ff3e25e37f84c554 /bin/repoman
parent906b62b24d8a845356d59abc5acd39db2174ce0f (diff)
downloadportage-8cc8d12a674ab6271183e5c35202263a36497279.tar.gz
portage-8cc8d12a674ab6271183e5c35202263a36497279.tar.bz2
portage-8cc8d12a674ab6271183e5c35202263a36497279.zip
Migrate from codecs.open() to io.open().
The io.open() function is the same as the built-in open() function in python3, and its implementation is optimized in python-2.7 and later. In addition to the possible performance improvement, this also allows us to avoid any future compatibility issues with codecs.open() that may arise if it is delegated to the built-in open() function as discussed in PEP 400. The main caveat involved with io.open() is that TextIOWrapper.write() raises TypeError if given raw bytes, unlike the streams returned from codecs.open(). This is mainly an issue for python2 since literal strings are raw bytes. We handle this by wrapping TextIOWrapper.write() arguments with our _unicode_decode() function. Also, the atomic_ofstream class overrides the write() method in python2 so that it performs automatic coercion to unicode when necessary.
Diffstat (limited to 'bin/repoman')
-rwxr-xr-xbin/repoman10
1 files changed, 5 insertions, 5 deletions
diff --git a/bin/repoman b/bin/repoman
index d1d393a82..3e0203681 100755
--- a/bin/repoman
+++ b/bin/repoman
@@ -9,10 +9,10 @@
from __future__ import print_function
import calendar
-import codecs
import copy
import errno
import formatter
+import io
import logging
import optparse
import re
@@ -700,7 +700,7 @@ for path in portdb.porttrees:
desc_path = os.path.join(path, 'profiles', 'profiles.desc')
try:
- desc_file = codecs.open(_unicode_encode(desc_path,
+ desc_file = io.open(_unicode_encode(desc_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'], errors='replace')
except EnvironmentError:
@@ -1209,7 +1209,7 @@ for x in scanlist:
continue
try:
line = 1
- for l in codecs.open(_unicode_encode(os.path.join(checkdir, y),
+ for l in io.open(_unicode_encode(os.path.join(checkdir, y),
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content']):
line +=1
@@ -1822,7 +1822,7 @@ for x in scanlist:
pkg.mtime = None
try:
# All ebuilds should have utf_8 encoding.
- f = codecs.open(_unicode_encode(full_path,
+ f = io.open(_unicode_encode(full_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'])
try:
@@ -2319,7 +2319,7 @@ else:
commitmessage = options.commitmsg
if options.commitmsgfile:
try:
- f = codecs.open(_unicode_encode(options.commitmsgfile,
+ f = io.open(_unicode_encode(options.commitmsgfile,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace')
commitmessage = f.read()