Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Nov 2012 21:14:54 +0000 (UTC)
From:      Sofian Brabez <sbz@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r307031 - head/Tools/scripts
Message-ID:  <201211052114.qA5LEsRg087131@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sbz
Date: Mon Nov  5 21:14:54 2012
New Revision: 307031
URL: http://svnweb.freebsd.org/changeset/ports/307031

Log:
  - Fix runtime utf-8 problems using codec encoder and system locale
  
  PR:		ports/173195
  Submitted by:	rm
  Reviewed by:	sbz (myself)
  Feature safe:	yes

Modified:
  head/Tools/scripts/getpatch

Modified: head/Tools/scripts/getpatch
==============================================================================
--- head/Tools/scripts/getpatch	Mon Nov  5 20:10:03 2012	(r307030)
+++ head/Tools/scripts/getpatch	Mon Nov  5 21:14:54 2012	(r307031)
@@ -29,6 +29,8 @@
 # MAINTAINER=   sbz@FreeBSD.org
 
 import argparse
+import codecs
+import locale
 import re
 import sys
 if sys.version_info.major == 3:
@@ -49,6 +51,7 @@ class GetPatch(object):
         self.url = str()
         self.patch = str()
         self.output_stdout = False
+        self.default_locale = locale.getdefaultlocale()[1].lower()
 
     def fetch(self, *largs, **kwargs):
         raise NotImplementedError()
@@ -56,8 +59,8 @@ class GetPatch(object):
     def write(self, filename, data):
         if filename.endswith(('.patch', '.txt')):
             filename = filename[:filename.rindex('.')]+'.diff'
-        f=open(filename, 'w')
-        f.write(data.decode())
+        f=codecs.open(filename, encoding=self.default_locale, mode='w')
+        f.write(data.decode(self.default_locale))
         f.close()
         self.out("[+] %s created" % filename)
 
@@ -79,7 +82,7 @@ class GetPatch(object):
             data = urllib2.urlopen(url).read()
 
             if self.output_stdout:
-                sys.stdout.write(data.decode())
+                sys.stdout.write(data.decode(self.default_locale))
             else:
                 self.write(p, data)
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211052114.qA5LEsRg087131>