public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/_sets/
Date: Fri, 28 Oct 2011 07:21:21 +0000 (UTC)	[thread overview]
Message-ID: <49cb5f96ebdb73e6b55ce171426fb2e1aefc01ae.zmedico@gentoo> (raw)

commit:     49cb5f96ebdb73e6b55ce171426fb2e1aefc01ae
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 28 07:21:05 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Oct 28 07:21:05 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=49cb5f96

SetConfig: use read_file/readfp for unicode

---
 pym/portage/_sets/__init__.py |   38 ++++++++++++++++++++++++++++++++++----
 1 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/pym/portage/_sets/__init__.py b/pym/portage/_sets/__init__.py
index 34ca74b..88a4b3b 100644
--- a/pym/portage/_sets/__init__.py
+++ b/pym/portage/_sets/__init__.py
@@ -6,21 +6,27 @@ from __future__ import print_function
 __all__ = ["SETPREFIX", "get_boolean", "SetConfigError",
 	"SetConfig", "load_default_config"]
 
+import io
+import logging
 import sys
 try:
-	from configparser import NoOptionError
+	from configparser import NoOptionError, ParsingError
 	if sys.hexversion >= 0x3020000:
 		from configparser import ConfigParser as SafeConfigParser
 	else:
 		from configparser import SafeConfigParser
 except ImportError:
-	from ConfigParser import SafeConfigParser, NoOptionError
+	from ConfigParser import SafeConfigParser, NoOptionError, ParsingError
 from portage import os
 from portage import load_mod
+from portage import _unicode_decode
+from portage import _unicode_encode
+from portage import _encodings
 from portage.const import USER_CONFIG_PATH, GLOBAL_CONFIG_PATH
 from portage.const import _ENABLE_SET_CONFIG
 from portage.exception import PackageSetNotFound
 from portage.localization import _
+from portage.util import writemsg_level
 
 SETPREFIX = "@"
 
@@ -48,7 +54,32 @@ class SetConfig(object):
 			})
 
 		if _ENABLE_SET_CONFIG:
-			self._parser.read(paths)
+			# use read_file/readfp in order to control decoding of unicode
+			try:
+				# Python >=3.2
+				read_file = self._parser.read_file
+			except AttributeError:
+				read_file = self._parser.readfp
+
+			for p in paths:
+				f = None
+				try:
+					f = io.open(_unicode_encode(p,
+						encoding=_encodings['fs'], errors='strict'),
+						mode='r', encoding=_encodings['repo.content'],
+						errors='replace')
+				except EnvironmentError:
+					pass
+				else:
+					try:
+						read_file(f)
+					except ParsingError as e:
+						writemsg_level(_unicode_decode(
+							_("!!! Error while reading sets config file: %s\n")
+							) % e, level=logging.ERROR, noiselevel=-1)
+				finally:
+					if f is not None:
+						f.close()
 		else:
 			self._create_default_config()
 
@@ -206,7 +237,6 @@ class SetConfig(object):
 		except KeyError:
 			raise PackageSetNotFound(setname)
 		myatoms = myset.getAtoms()
-		parser = self._parser
 
 		if ignorelist is None:
 			ignorelist = set()



             reply	other threads:[~2011-10-28  7:21 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-28  7:21 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-12-09  4:25 [gentoo-commits] proj/portage:master commit in: pym/portage/_sets/ Zac Medico
2015-03-09 19:53 Zac Medico
2015-02-11 19:11 Brian Dolbec
2015-02-11 16:17 Brian Dolbec
2014-12-10 20:14 Arfrever Frehtes Taifersar Arahesis
2014-12-08  0:42 Zac Medico
2014-05-12 10:13 Alexander Berntsen
2012-10-18  3:12 Zac Medico
2012-10-18  3:06 Zac Medico
2012-10-18  3:02 Zac Medico
2012-10-18  2:52 Zac Medico
2012-09-05 20:37 Zac Medico
2012-09-04 20:41 Zac Medico
2012-09-04 20:41 Zac Medico
2012-09-02 22:32 Zac Medico
2012-09-02 20:19 Zac Medico
2012-09-01  4:29 Zac Medico
2012-05-14  1:02 Zac Medico
2012-05-14  0:51 Zac Medico
2011-07-24  1:35 Zac Medico
2011-07-21 16:15 Zac Medico
2011-06-06  2:01 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49cb5f96ebdb73e6b55ce171426fb2e1aefc01ae.zmedico@gentoo \
    --to=zmedico@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox