aboutsummaryrefslogtreecommitdiff
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 /pym/portage/manifest.py
parentManifest: fix NameError in updateAllHashes (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 'pym/portage/manifest.py')
-rw-r--r--pym/portage/manifest.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/pym/portage/manifest.py b/pym/portage/manifest.py
index 4714da032..13efab791 100644
--- a/pym/portage/manifest.py
+++ b/pym/portage/manifest.py
@@ -1,8 +1,8 @@
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-import codecs
import errno
+import io
import portage
portage.proxy.lazyimport.lazyimport(globals(),
@@ -141,7 +141,7 @@ class Manifest(object):
"""Parse a manifest. If myhashdict is given then data will be added too it.
Otherwise, a new dict will be created and returned."""
try:
- fd = codecs.open(_unicode_encode(file_path,
+ fd = io.open(_unicode_encode(file_path,
encoding=_encodings['fs'], errors='strict'), mode='r',
encoding=_encodings['repo.content'], errors='replace')
if myhashdict is None:
@@ -229,7 +229,7 @@ class Manifest(object):
update_manifest = True
if not force:
try:
- f = codecs.open(_unicode_encode(self.getFullname(),
+ f = io.open(_unicode_encode(self.getFullname(),
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
errors='replace')
@@ -519,7 +519,7 @@ class Manifest(object):
mfname = self.getFullname()
if not os.path.exists(mfname):
return rVal
- myfile = codecs.open(_unicode_encode(mfname,
+ myfile = io.open(_unicode_encode(mfname,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'], errors='replace')
lines = myfile.readlines()