FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora Development

 
 
LinkBack Thread Tools
 
Old 11-11-2008, 03:38 PM
Chris Lumens
 
Default 470733 - yet more unicode errors

Here's the latest in our continuing war against UnicodeDecodeError. I
don't want to claim victory yet, but I think this patch gets us closer.

The real problem is in assembling the string in AnacondaCallback, as
usual. All the rest of the patch is just me converting our typical
unicode() call into a function so we can be more lazy in the future.

- Chris


diff --git a/yuminstall.py b/yuminstall.py
index a962639..53f6327 100644
--- a/yuminstall.py
+++ b/yuminstall.py
@@ -67,21 +67,31 @@ urlgrabber.grabber.default_grabber.opts.user_agent = "%s (anaconda)/%s" %(produc
import iutil
import isys

+def toUTF8(str):
+ if type(str) != unicode:
+ return unicode(str, encoding='utf-8')
+ else:
+ return str
+
def size_string (size):
def number_format(s):
return locale.format("%s", s, 1)

+ retval = None
+
if size > 1024 * 1024:
size = size / (1024*1024)
- return _("%s MB") %(number_format(size),)
+ retval = _("%s MB") %(number_format(size),)
elif size > 1024:
size = size / 1024
- return _("%s KB") %(number_format(size),)
+ retval = _("%s KB") %(number_format(size),)
else:
if size == 1:
- return _("%s Byte") %(number_format(size),)
+ retval = _("%s Byte") %(number_format(size),)
else:
- return _("%s Bytes") %(number_format(size),)
+ retval = _("%s Bytes") %(number_format(size),)
+
+ return toUTF8(retval)

class AnacondaCallback:

@@ -155,14 +165,12 @@ class AnacondaCallback:
repo = self.repos.getRepo(po.repoid)

pkgStr = "%s-%s-%s.%s" % (po.name, po.version, po.release, po.arch)
- s = _("<b>Installing %s</b> (%s)
") %(pkgStr, size_string(hdr['size']))
- summary = gettext.ldgettext("redhat-dist", hdr['summary'] or "")
- if type(summary) != unicode:
- summary = unicode(summary, encoding='utf-8')
+ s = toUTF8(_("<b>Installing %s</b> (%s)
")) %(pkgStr, size_string(hdr['size']))
+ summary = toUTF8(gettext.ldgettext("redhat-dist", hdr['summary'] or ""))
s += summary.strip()
self.progress.set_label(s)

- self.instLog.write(self.modeText % pkgStr)
+ self.instLog.write(self.modeText % str(pkgStr))

self.instLog.flush()
self.openfile = None
@@ -645,9 +653,7 @@ class AnacondaYum(YumSorter):
else:
buttons = [_("Re_boot"), _("_Retry")]

- pkgFile = os.path.basename(package.returnSimple('relativepat h'))
- if type(pkgFile) != unicode:
- pkgFile = unicode(pkgFile, encoding='utf-8')
+ pkgFile = toUTF8(os.path.basename(package.returnSimple('rela tivepath')))

rc = self.anaconda.intf.messageWindow(_("Error"),
_("The file %s cannot be opened. This is due to a missing "
@@ -839,11 +845,8 @@ class AnacondaYum(YumSorter):
msg = _("There was an error running your transaction for "
"the following reason(s): %s.
") % ', '.join(uniqueProbs.values())

- if type(spaceprob) != unicode:
- spaceprob = unicode(spaceprob, encoding='utf-8')
-
- if type(fileprob) != unicode:
- fileprob = unicode(fileprob, encoding='utf-8')
+ spaceprob = toUTF8(spaceprob)
+ fileprob = toUTF8(fileprob)

if len(self.anaconda.backend.getRequiredMedia()) > 1:
intf.detailedMessageWindow(_("Error Running Transaction"),

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 11-11-2008, 07:08 PM
David Cantrell
 
Default 470733 - yet more unicode errors

On Tue, Nov 11, 2008 at 11:38:50AM -0500, Chris Lumens wrote:
> Here's the latest in our continuing war against UnicodeDecodeError. I
> don't want to claim victory yet, but I think this patch gets us closer.
>
> The real problem is in assembling the string in AnacondaCallback, as
> usual. All the rest of the patch is just me converting our typical
> unicode() call into a function so we can be more lazy in the future.
>
> - Chris
>
>
> diff --git a/yuminstall.py b/yuminstall.py
> index a962639..53f6327 100644
> --- a/yuminstall.py
> +++ b/yuminstall.py
> @@ -67,21 +67,31 @@ urlgrabber.grabber.default_grabber.opts.user_agent = "%s (anaconda)/%s" %(produc
> import iutil
> import isys
>
> +def toUTF8(str):
> + if type(str) != unicode:
> + return unicode(str, encoding='utf-8')
> + else:
> + return str
> +

toUTF8() doesn't strike me as the best way. Can we not go with try/except and
catch UnicodeDecodeError rather than looking at the type of the str? End
result is the same, I guess, but when I see code looking at types of variables
like this, it reminds me of various FailCode from Java at GT.

> def size_string (size):
> def number_format(s):
> return locale.format("%s", s, 1)
>
> + retval = None
> +
> if size > 1024 * 1024:
> size = size / (1024*1024)
> - return _("%s MB") %(number_format(size),)
> + retval = _("%s MB") %(number_format(size),)
> elif size > 1024:
> size = size / 1024
> - return _("%s KB") %(number_format(size),)
> + retval = _("%s KB") %(number_format(size),)
> else:
> if size == 1:
> - return _("%s Byte") %(number_format(size),)
> + retval = _("%s Byte") %(number_format(size),)
> else:
> - return _("%s Bytes") %(number_format(size),)
> + retval = _("%s Bytes") %(number_format(size),)
> +
> + return toUTF8(retval)
>
> class AnacondaCallback:
>
> @@ -155,14 +165,12 @@ class AnacondaCallback:
> repo = self.repos.getRepo(po.repoid)
>
> pkgStr = "%s-%s-%s.%s" % (po.name, po.version, po.release, po.arch)
> - s = _("<b>Installing %s</b> (%s)
") %(pkgStr, size_string(hdr['size']))
> - summary = gettext.ldgettext("redhat-dist", hdr['summary'] or "")
> - if type(summary) != unicode:
> - summary = unicode(summary, encoding='utf-8')
> + s = toUTF8(_("<b>Installing %s</b> (%s)
")) %(pkgStr, size_string(hdr['size']))
> + summary = toUTF8(gettext.ldgettext("redhat-dist", hdr['summary'] or ""))
> s += summary.strip()
> self.progress.set_label(s)
>
> - self.instLog.write(self.modeText % pkgStr)
> + self.instLog.write(self.modeText % str(pkgStr))
>
> self.instLog.flush()
> self.openfile = None
> @@ -645,9 +653,7 @@ class AnacondaYum(YumSorter):
> else:
> buttons = [_("Re_boot"), _("_Retry")]
>
> - pkgFile = os.path.basename(package.returnSimple('relativepat h'))
> - if type(pkgFile) != unicode:
> - pkgFile = unicode(pkgFile, encoding='utf-8')
> + pkgFile = toUTF8(os.path.basename(package.returnSimple('rela tivepath')))
>
> rc = self.anaconda.intf.messageWindow(_("Error"),
> _("The file %s cannot be opened. This is due to a missing "
> @@ -839,11 +845,8 @@ class AnacondaYum(YumSorter):
> msg = _("There was an error running your transaction for "
> "the following reason(s): %s.
") % ', '.join(uniqueProbs.values())
>
> - if type(spaceprob) != unicode:
> - spaceprob = unicode(spaceprob, encoding='utf-8')
> -
> - if type(fileprob) != unicode:
> - fileprob = unicode(fileprob, encoding='utf-8')
> + spaceprob = toUTF8(spaceprob)
> + fileprob = toUTF8(fileprob)
>
> if len(self.anaconda.backend.getRequiredMedia()) > 1:
> intf.detailedMessageWindow(_("Error Running Transaction"),
>
> _______________________________________________
> Anaconda-devel-list mailing list
> Anaconda-devel-list@redhat.com
> https://www.redhat.com/mailman/listinfo/anaconda-devel-list

--
David Cantrell <dcantrell@redhat.com>
Red Hat / Honolulu, HI
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 11-11-2008, 07:13 PM
Seth Vidal
 
Default 470733 - yet more unicode errors

On Tue, 11 Nov 2008, David Cantrell wrote:



toUTF8() doesn't strike me as the best way. Can we not go with try/except and
catch UnicodeDecodeError rather than looking at the type of the str? End
result is the same, I guess, but when I see code looking at types of variables
like this, it reminds me of various FailCode from Java at GT.




from yum.misc import to_unicode, to_utf8, to_unicode_maybe, to_str

in theory, those should help things a good bit.

-sv

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 11-11-2008, 07:53 PM
Chris Lumens
 
Default 470733 - yet more unicode errors

> from yum.misc import to_unicode, to_utf8, to_unicode_maybe, to_str
>
> in theory, those should help things a good bit.

Even better, because that's less code we have to maintain.

- Chris


diff --git a/yuminstall.py b/yuminstall.py
index a962639..694bffe 100644
--- a/yuminstall.py
+++ b/yuminstall.py
@@ -39,6 +39,7 @@ import yum
import iniparse
from yum.constants import *
from yum.Errors import *
+from yum.misc import to_unicode
from yum.yumRepo import YumRepository
from backend import AnacondaBackend
from product import *
@@ -71,17 +72,21 @@ def size_string (size):
def number_format(s):
return locale.format("%s", s, 1)

+ retval = None
+
if size > 1024 * 1024:
size = size / (1024*1024)
- return _("%s MB") %(number_format(size),)
+ retval = _("%s MB") %(number_format(size),)
elif size > 1024:
size = size / 1024
- return _("%s KB") %(number_format(size),)
+ retval = _("%s KB") %(number_format(size),)
else:
if size == 1:
- return _("%s Byte") %(number_format(size),)
+ retval = _("%s Byte") %(number_format(size),)
else:
- return _("%s Bytes") %(number_format(size),)
+ retval = _("%s Bytes") %(number_format(size),)
+
+ return to_unicode(retval)

class AnacondaCallback:

@@ -155,14 +160,12 @@ class AnacondaCallback:
repo = self.repos.getRepo(po.repoid)

pkgStr = "%s-%s-%s.%s" % (po.name, po.version, po.release, po.arch)
- s = _("<b>Installing %s</b> (%s)
") %(pkgStr, size_string(hdr['size']))
- summary = gettext.ldgettext("redhat-dist", hdr['summary'] or "")
- if type(summary) != unicode:
- summary = unicode(summary, encoding='utf-8')
+ s = to_unicode(_("<b>Installing %s</b> (%s)
")) %(pkgStr, size_string(hdr['size']))
+ summary = to_unicode(gettext.ldgettext("redhat-dist", hdr['summary'] or ""))
s += summary.strip()
self.progress.set_label(s)

- self.instLog.write(self.modeText % pkgStr)
+ self.instLog.write(self.modeText % str(pkgStr))

self.instLog.flush()
self.openfile = None
@@ -645,9 +648,7 @@ class AnacondaYum(YumSorter):
else:
buttons = [_("Re_boot"), _("_Retry")]

- pkgFile = os.path.basename(package.returnSimple('relativepat h'))
- if type(pkgFile) != unicode:
- pkgFile = unicode(pkgFile, encoding='utf-8')
+ pkgFile = to_unicode(os.path.basename(package.returnSimple(' relativepath')))

rc = self.anaconda.intf.messageWindow(_("Error"),
_("The file %s cannot be opened. This is due to a missing "
@@ -839,11 +840,8 @@ class AnacondaYum(YumSorter):
msg = _("There was an error running your transaction for "
"the following reason(s): %s.
") % ', '.join(uniqueProbs.values())

- if type(spaceprob) != unicode:
- spaceprob = unicode(spaceprob, encoding='utf-8')
-
- if type(fileprob) != unicode:
- fileprob = unicode(fileprob, encoding='utf-8')
+ spaceprob = to_unicode(spaceprob)
+ fileprob = to_unicode(fileprob)

if len(self.anaconda.backend.getRequiredMedia()) > 1:
intf.detailedMessageWindow(_("Error Running Transaction"),

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 11-11-2008, 09:48 PM
David Cantrell
 
Default 470733 - yet more unicode errors

On Tue, Nov 11, 2008 at 03:53:01PM -0500, Chris Lumens wrote:
> > from yum.misc import to_unicode, to_utf8, to_unicode_maybe, to_str
> >
> > in theory, those should help things a good bit.
>
> Even better, because that's less code we have to maintain.

I like it more now.

>
> - Chris
>
>
> diff --git a/yuminstall.py b/yuminstall.py
> index a962639..694bffe 100644
> --- a/yuminstall.py
> +++ b/yuminstall.py
> @@ -39,6 +39,7 @@ import yum
> import iniparse
> from yum.constants import *
> from yum.Errors import *
> +from yum.misc import to_unicode
> from yum.yumRepo import YumRepository
> from backend import AnacondaBackend
> from product import *
> @@ -71,17 +72,21 @@ def size_string (size):
> def number_format(s):
> return locale.format("%s", s, 1)
>
> + retval = None
> +
> if size > 1024 * 1024:
> size = size / (1024*1024)
> - return _("%s MB") %(number_format(size),)
> + retval = _("%s MB") %(number_format(size),)
> elif size > 1024:
> size = size / 1024
> - return _("%s KB") %(number_format(size),)
> + retval = _("%s KB") %(number_format(size),)
> else:
> if size == 1:
> - return _("%s Byte") %(number_format(size),)
> + retval = _("%s Byte") %(number_format(size),)
> else:
> - return _("%s Bytes") %(number_format(size),)
> + retval = _("%s Bytes") %(number_format(size),)
> +
> + return to_unicode(retval)
>
> class AnacondaCallback:
>
> @@ -155,14 +160,12 @@ class AnacondaCallback:
> repo = self.repos.getRepo(po.repoid)
>
> pkgStr = "%s-%s-%s.%s" % (po.name, po.version, po.release, po.arch)
> - s = _("<b>Installing %s</b> (%s)
") %(pkgStr, size_string(hdr['size']))
> - summary = gettext.ldgettext("redhat-dist", hdr['summary'] or "")
> - if type(summary) != unicode:
> - summary = unicode(summary, encoding='utf-8')
> + s = to_unicode(_("<b>Installing %s</b> (%s)
")) %(pkgStr, size_string(hdr['size']))
> + summary = to_unicode(gettext.ldgettext("redhat-dist", hdr['summary'] or ""))
> s += summary.strip()
> self.progress.set_label(s)
>
> - self.instLog.write(self.modeText % pkgStr)
> + self.instLog.write(self.modeText % str(pkgStr))
>
> self.instLog.flush()
> self.openfile = None
> @@ -645,9 +648,7 @@ class AnacondaYum(YumSorter):
> else:
> buttons = [_("Re_boot"), _("_Retry")]
>
> - pkgFile = os.path.basename(package.returnSimple('relativepat h'))
> - if type(pkgFile) != unicode:
> - pkgFile = unicode(pkgFile, encoding='utf-8')
> + pkgFile = to_unicode(os.path.basename(package.returnSimple(' relativepath')))
>
> rc = self.anaconda.intf.messageWindow(_("Error"),
> _("The file %s cannot be opened. This is due to a missing "
> @@ -839,11 +840,8 @@ class AnacondaYum(YumSorter):
> msg = _("There was an error running your transaction for "
> "the following reason(s): %s.
") % ', '.join(uniqueProbs.values())
>
> - if type(spaceprob) != unicode:
> - spaceprob = unicode(spaceprob, encoding='utf-8')
> -
> - if type(fileprob) != unicode:
> - fileprob = unicode(fileprob, encoding='utf-8')
> + spaceprob = to_unicode(spaceprob)
> + fileprob = to_unicode(fileprob)
>
> if len(self.anaconda.backend.getRequiredMedia()) > 1:
> intf.detailedMessageWindow(_("Error Running Transaction"),
>
> _______________________________________________
> Anaconda-devel-list mailing list
> Anaconda-devel-list@redhat.com
> https://www.redhat.com/mailman/listinfo/anaconda-devel-list

--
David Cantrell <dcantrell@redhat.com>
Red Hat / Honolulu, HI
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 

Thread Tools




All times are GMT. The time now is 12:59 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org