Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 351256 - app-portage/gentoolkit-0.3.0_rc11-r3: Can't cope with empty string for locale.getpreferredencoding()
Summary: app-portage/gentoolkit-0.3.0_rc11-r3: Can't cope with empty string for locale...
Status: RESOLVED NEEDINFO
Alias: None
Product: Gentoo/Alt
Classification: Unclassified
Component: Prefix Support (show other bugs)
Hardware: All OS X
: High normal (vote)
Assignee: Gentoo Prefix
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-09 23:38 UTC by Charles Davis
Modified: 2011-02-21 06:31 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Charles Davis 2011-01-09 23:38:55 UTC
Certain uses of the equery script result in this backtrace (or something similar; this is from running equery belongs):

Traceback (most recent call last):
  File "/Users/chip/Gentoo/usr/bin/equery", line 38, in <module>
    equery.main()
  File "/Users/chip/Gentoo/usr/lib/python2.7/site-packages/gentoolkit/equery/__init__.py", line 349, in main
    loaded_module.main(module_args)
  File "/Users/chip/Gentoo/usr/lib/python2.7/site-packages/gentoolkit/equery/belongs.py", line 144, in main
    pp.regexpquery(",".join(queries)))
  File "/Users/chip/Gentoo/usr/lib/python2.7/site-packages/gentoolkit/pprinter.py", line 180, in uprint
    sep = sep.encode(encoding, 'replace')
LookupError: unknown encoding: 

According to the exception message, the encoding is blank! Looking at the pprinter module from gentoolkit shows that the encoding is set like so:

import locale
...
encoding = locale.getpreferredencoding()

Trying this in a python interpreter indeed results in a blank string:

Python 2.7.1 (r271:86832, Jan  8 2011, 12:20:29) 
[GCC 4.2.1 (Gentoo 4.2.1_p5664, Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getpreferredencoding()
''

Oddly enough, though, passing 'False' returns an actual encoding:

>>> locale.getpreferredencoding(False)
'US-ASCII'

I suspect that on other platforms, though, we don't want to pass False because that will cause it to fail. Looks like a Darwin-specific patch file is in order (for now). This might actually be an upstream issue in Python 2.7; I'll take a look.

Reproducible: Always

Steps to Reproduce:
1. Run equery with the belongs, changes, check, hasuse, list, meta, size, uses, or which verbs.

Actual Results:  
Got a traceback that ends at the 'uprint' method in gentoolkit's pprinter module.

Expected Results:  
All equery verbs should work as documented.

Portage 2.2.01.17583-prefix (prefix/darwin/macos/10.6/x86, gcc-4.2.1, unavailable, 10.6.0 i386)
=================================================================
                        System Settings
=================================================================
System uname: Darwin-10.6.0-i386-32bit
Timestamp of tree: Sun, 09 Jan 2011 04:13:02 +0000
distcc 3.1-toolwhip.1 i386-apple-darwin10.0 [disabled]
app-shells/bash:     4.1_p7
dev-lang/python:     2.6.5-r2, 2.7.1-r00.1
dev-util/cmake:      2.8.3
sys-devel/autoconf:  2.68
sys-devel/automake:  1.9.6-r3, 1.11.1
sys-devel/gcc-config: 1.4.1-r00.2
sys-devel/libtool:   2.4
sys-devel/make:      3.82
Repositories: gentoo_prefix
ACCEPT_KEYWORDS="~x86-macos"
ACCEPT_LICENSE="* -@EULA"
CBUILD="i686-apple-darwin10"
CFLAGS="-O2 -pipe -march=core2"
CHOST="i686-apple-darwin10"
CONFIG_PROTECT="/etc"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/portage /etc/revdep-rebuild /etc/terminfo"
CXXFLAGS="-O2 -pipe -march=core2"
DISTDIR="/Users/chip/Gentoo/usr/portage/distfiles"
FEATURES="assume-digests binpkg-logs collision-protect distlocks fixlafiles fixpackages news nostrip parallel-fetch preserve-libs protect-owned sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LDFLAGS="-Wl,-dead_strip_dylibs"
MAKEOPTS="-j4"
PKGDIR="/Users/chip/Gentoo/usr/portage/packages"
PORTAGE_CONFIGROOT="/Users/chip/Gentoo/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/Users/chip/Gentoo/var/tmp"
PORTDIR="/Users/chip/Gentoo/usr/portage"
PORTDIR_OVERLAY=""
SYNC="rsync://rsync.prefix.freens.org/gentoo-portage-prefix"
USE="aqua bash-completion berkdb bzip2 coreaudio cracklib crypt curl cxx dbus exceptions expat extensions gdbm gmp gnutls gpg gzip iconv icu ipv6 jbig jpeg libssh2 lzma lzo mmx mmxext mng modules mysql ncurses nls objc objc++ pch perl png prefix python qt3support readline ruby sql sqlite3 sse sse2 ssl subversion tcl threads tiff tk truetype unicode vim-syntax x86-macos xml zlib" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="Darwin" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="keyboard mouse" KERNEL="Darwin" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" PHP_TARGETS="php5-3" RUBY_TARGETS="ruby18" USERLAND="GNU" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account" 
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LANG, LC_ALL, LINGUAS, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS

=================================================================
                        Package Settings
=================================================================

app-portage/gentoolkit-0.3.0_rc11-r3 was built with the following:
USE="(prefix)"

[ebuild   R   ] app-portage/gentoolkit-0.3.0_rc11-r3
Comment 1 Fabian Groffen gentoo-dev 2011-01-10 07:41:02 UTC
Maybe this "helps":

% python2.7 
Python 2.7.1 (r271:86832, Jan  8 2011, 15:13:43) 
[GCC 4.2.1 (Gentoo 4.2.1_p5664, Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getpreferredencoding()
'UTF-8'
>>> 
% python2.6
Python 2.6.5 (release26-maint, Oct 24 2010, 23:38:28) 
[GCC 4.2.1 (Gentoo 4.2.1_p5664, Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getpreferredencoding()
'mac-roman'
>>> 
Comment 2 Charles Davis 2011-01-14 03:53:40 UTC
It does.

What does 'locale' say for you? Here's what it says for me:

LANG=
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

For some reason, setting LANG, LC_CTYPE, or LC_ALL to anything--anything at all, even a non-existent locale--causes locale.getpreferredencoding(True) to succeed, and return a nonzero-length string. I wonder why that is.
Comment 3 Fabian Groffen gentoo-dev 2011-01-14 08:08:47 UTC
I set my locale to en_gb.UTF-8, I knew that upfront :)  Python-2.7 now actually listens to the environment iso hardcoding this stupid macroman.
Comment 4 Jeremy Olexa (darkside) (RETIRED) archtester gentoo-dev Security 2011-02-21 06:31:43 UTC
I guess there is no more issue here?