* [gentoo-portage-dev] [PATCH] bintree.populate: binhost connection failure triggers TypeError (bug 532784)
@ 2015-05-04 4:52 Zac Medico
2015-05-04 6:25 ` Brian Dolbec
0 siblings, 1 reply; 4+ messages in thread
From: Zac Medico @ 2015-05-04 4:52 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Zac Medico
Since commit 4496ee37d6fa327ada635c67500e82f830141a9e, binhost
connection errors result in a TypeError. Fix it to call the unicode
function correctly (with only a single argument). Also, handle
a possible UnicodeDecodeError.
Fixes: 4496ee37d6fa ("bintree.py: fix str() calls for Python 2 (532784)")
X-Gentoo-Bug: 532784
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=532784
---
pym/portage/dbapi/bintree.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
index b37f388..4043016 100644
--- a/pym/portage/dbapi/bintree.py
+++ b/pym/portage/dbapi/bintree.py
@@ -961,8 +961,12 @@ class binarytree(object):
# With Python 2, the EnvironmentError message may
# contain bytes or unicode, so use _unicode to ensure
# safety with all locales (bug #532784).
- writemsg("!!! %s\n\n" % _unicode(e,
- _encodings["stdio"], errors="replace"))
+ try:
+ error_msg = _unicode(e)
+ except UnicodeDecodeError as uerror:
+ error_msg = _unicode(uerror.object,
+ encoding='utf_8', errors='replace')
+ writemsg("!!! %s\n\n" % error_msg)
del e
pkgindex = None
if proc is not None:
--
2.3.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] bintree.populate: binhost connection failure triggers TypeError (bug 532784)
2015-05-04 4:52 [gentoo-portage-dev] [PATCH] bintree.populate: binhost connection failure triggers TypeError (bug 532784) Zac Medico
@ 2015-05-04 6:25 ` Brian Dolbec
2015-05-04 6:37 ` Zac Medico
0 siblings, 1 reply; 4+ messages in thread
From: Brian Dolbec @ 2015-05-04 6:25 UTC (permalink / raw
To: gentoo-portage-dev
On Sun, 3 May 2015 21:52:33 -0700
Zac Medico <zmedico@gentoo.org> wrote:
> Since commit 4496ee37d6fa327ada635c67500e82f830141a9e, binhost
> connection errors result in a TypeError. Fix it to call the unicode
> function correctly (with only a single argument). Also, handle
> a possible UnicodeDecodeError.
>
> Fixes: 4496ee37d6fa ("bintree.py: fix str() calls for Python 2
> (532784)") X-Gentoo-Bug: 532784
> X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=532784
> ---
> pym/portage/dbapi/bintree.py | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/pym/portage/dbapi/bintree.py
> b/pym/portage/dbapi/bintree.py index b37f388..4043016 100644
> --- a/pym/portage/dbapi/bintree.py
> +++ b/pym/portage/dbapi/bintree.py
> @@ -961,8 +961,12 @@ class binarytree(object):
> # With Python 2, the
> EnvironmentError message may # contain bytes or unicode, so use
> _unicode to ensure # safety with all locales (bug #532784).
> - writemsg("!!! %s\n\n" % _unicode(e,
> - _encodings["stdio"],
> errors="replace"))
> + try:
> + error_msg = _unicode(e)
> + except UnicodeDecodeError as uerror:
> + error_msg =
> _unicode(uerror.object,
> + encoding='utf_8',
> errors='replace')
> + writemsg("!!! %s\n\n" % error_msg)
> del e
> pkgindex = None
> if proc is not None:
Isn't this backwards from what was reported. It generated a
UnicodeDecodeError when using additional args to unicode(). It needed
to convert it to string so errors= needed to not be passed in.
--
Brian Dolbec <dolsen>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] bintree.populate: binhost connection failure triggers TypeError (bug 532784)
2015-05-04 6:25 ` Brian Dolbec
@ 2015-05-04 6:37 ` Zac Medico
2015-05-04 6:48 ` Brian Dolbec
0 siblings, 1 reply; 4+ messages in thread
From: Zac Medico @ 2015-05-04 6:37 UTC (permalink / raw
To: gentoo-portage-dev
On 05/03/2015 11:25 PM, Brian Dolbec wrote:
> Isn't this backwards from what was reported. It generated a
> UnicodeDecodeError when using additional args to unicode().
It was actually a TypeError.
> It needed
> to convert it to string so errors= needed to not be passed in.
Yeah, the first unicode call fixes that.
If a UnicodeDecodeError is then raised (not a TypeError), the second
unicode call decodes the UnicodeError.object attribute, which is
guaranteed to be a string that can be passed to unicode using the three
argument form.
--
Thanks,
Zac
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] bintree.populate: binhost connection failure triggers TypeError (bug 532784)
2015-05-04 6:37 ` Zac Medico
@ 2015-05-04 6:48 ` Brian Dolbec
0 siblings, 0 replies; 4+ messages in thread
From: Brian Dolbec @ 2015-05-04 6:48 UTC (permalink / raw
To: gentoo-portage-dev
On Sun, 03 May 2015 23:37:52 -0700
Zac Medico <zmedico@gentoo.org> wrote:
> On 05/03/2015 11:25 PM, Brian Dolbec wrote:
> > Isn't this backwards from what was reported. It generated a
> > UnicodeDecodeError when using additional args to unicode().
>
> It was actually a TypeError.
>
> > It needed
> > to convert it to string so errors= needed to not be passed in.
>
> Yeah, the first unicode call fixes that.
>
> If a UnicodeDecodeError is then raised (not a TypeError), the second
> unicode call decodes the UnicodeError.object attribute, which is
> guaranteed to be a string that can be passed to unicode using the
> three argument form.
OK then :)
--
Brian Dolbec <dolsen>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-05-04 6:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-04 4:52 [gentoo-portage-dev] [PATCH] bintree.populate: binhost connection failure triggers TypeError (bug 532784) Zac Medico
2015-05-04 6:25 ` Brian Dolbec
2015-05-04 6:37 ` Zac Medico
2015-05-04 6:48 ` Brian Dolbec
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox