[yum-git] repoquery.py
Tim Lauridsen
timlau at linux.duke.edu
Mon Jun 2 11:55:30 UTC 2008
repoquery.py | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
New commits:
commit c49110c6819716526b1902075a2304bb34c9f40d
Author: Tim Lauridsen <tla at rasmil.dk>
Date: Mon Jun 2 13:45:34 2008 +0200
fixes unicode error when running as LANG=C
diff --git a/repoquery.py b/repoquery.py
index 817c624..19b93ec 100755
--- a/repoquery.py
+++ b/repoquery.py
@@ -841,15 +841,24 @@ def main(args):
repoq.logger.error( e)
sys.exit(1)
- # ick.. python assumes ascii encoding if stdout is not a tty, force
- # it to preferred locale
- if not sys.stdout.isatty():
- import codecs, locale
- sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
-
repoq.runQuery(regexs)
if __name__ == "__main__":
+ import locale
+ # This test needs to be before locale.getpreferredencoding() as that
+ # does setlocale(LC_CTYPE, "")
+ try:
+ locale.setlocale(locale.LC_ALL, '')
+ except locale.Error, e:
+ # default to C locale if we get a failure.
+ print >> sys.stderr, 'Failed to set locale, defaulting to C'
+ os.environ['LC_ALL'] = 'C'
+ locale.setlocale(locale.LC_ALL, 'C')
+
+ if True: # not sys.stdout.isatty():
+ import codecs
+ sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
+ sys.stdout.errors = 'replace'
main(sys.argv)
# vim:sw=4:sts=4:expandtab
More information about the Yum-cvs-commits
mailing list