Re: [gentoo-portage-dev] [PATCH 2/2] portage.util.configparser: Commonize portable config file reading routine

2016-05-24 Thread Michał Górny
On Sun, 22 May 2016 11:04:51 -0700
Zac Medico  wrote:

> On 05/22/2016 01:41 AM, Michał Górny wrote:
> > ---
> >  pym/portage/_sets/__init__.py  | 29 ++-
> >  pym/portage/repository/config.py   | 38 ++---
> >  pym/portage/util/_desktop_entry.py | 20 ++---
> >  pym/portage/util/configparser.py   | 57 
> > +-
> >  4 files changed, 64 insertions(+), 80 deletions(-)  
> 
> These patches look good. Note that the _native_kwargs function is not
> really needed anymore, because it was just a workaround for this issue
> which only affected python 2.6.4 and earlier:
> 
>http://bugs.python.org/issue4978

Pushed now, thanks.

I'll do a global _native_kwargs cleanup in a separate patch.

-- 
Best regards,
Michał Górny



pgpXQJxBE7cZ3.pgp
Description: OpenPGP digital signature


Re: [gentoo-portage-dev] [PATCH 2/2] portage.util.configparser: Commonize portable config file reading routine

2016-05-22 Thread Zac Medico
On 05/22/2016 01:41 AM, Michał Górny wrote:
> ---
>  pym/portage/_sets/__init__.py  | 29 ++-
>  pym/portage/repository/config.py   | 38 ++---
>  pym/portage/util/_desktop_entry.py | 20 ++---
>  pym/portage/util/configparser.py   | 57 
> +-
>  4 files changed, 64 insertions(+), 80 deletions(-)

These patches look good. Note that the _native_kwargs function is not
really needed anymore, because it was just a workaround for this issue
which only affected python 2.6.4 and earlier:

   http://bugs.python.org/issue4978
-- 
Thanks,
Zac



[gentoo-portage-dev] [PATCH 2/2] portage.util.configparser: Commonize portable config file reading routine

2016-05-22 Thread Michał Górny
---
 pym/portage/_sets/__init__.py  | 29 ++-
 pym/portage/repository/config.py   | 38 ++---
 pym/portage/util/_desktop_entry.py | 20 ++---
 pym/portage/util/configparser.py   | 57 +-
 4 files changed, 64 insertions(+), 80 deletions(-)

diff --git a/pym/portage/_sets/__init__.py b/pym/portage/_sets/__init__.py
index ec42f7c..6d69bda 100644
--- a/pym/portage/_sets/__init__.py
+++ b/pym/portage/_sets/__init__.py
@@ -22,7 +22,7 @@ from portage.exception import PackageSetNotFound
 from portage.localization import _
 from portage.util import writemsg_level
 from portage.util.configparser import (SafeConfigParser,
-   NoOptionError, ParsingError)
+   NoOptionError, ParsingError, read_configs)
 
 SETPREFIX = "@"
 
@@ -50,32 +50,7 @@ class SetConfig(object):
})
 
if _ENABLE_SET_CONFIG:
-   # 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()
+   read_configs(self._parser, paths)
else:
self._create_default_config()
 
diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py
index 9039886..a23f4bd 100644
--- a/pym/portage/repository/config.py
+++ b/pym/portage/repository/config.py
@@ -17,7 +17,8 @@ from portage.eapi import 
eapi_allows_directories_on_profile_level_and_repository
 from portage.env.loaders import KeyValuePairFileLoader
 from portage.util import (normalize_path, read_corresponding_eapi_file, 
shlex_split,
stack_lists, writemsg, writemsg_level, _recursive_file_list)
-from portage.util.configparser import SafeConfigParser, ConfigParserError
+from portage.util.configparser import (SafeConfigParser, ConfigParserError,
+   read_configs)
 from portage.util._path import isdir_raise_eaccess
 from portage.util.path import first_existing
 from portage.localization import _
@@ -542,15 +543,6 @@ class RepoConfigLoader(object):
"""Parse files in paths to load config"""
parser = SafeConfigParser(defaults=default_opts)
 
-   # use read_file/readfp in order to control decoding of unicode
-   try:
-   # Python >=3.2
-   read_file = parser.read_file
-   source_kwarg = 'source'
-   except AttributeError:
-   read_file = parser.readfp
-   source_kwarg = 'filename'
-
recursive_paths = []
for p in paths:
if isinstance(p, basestring):
@@ -558,31 +550,7 @@ class RepoConfigLoader(object):
else:
recursive_paths.append(p)
 
-   for p in recursive_paths:
-   if isinstance(p, basestring):
-   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:
-   # The 'source' keyword argument is 
needed since otherwise
-