diff options
author | sbz <sbz@FreeBSD.org> | 2012-11-06 05:14:54 +0800 |
---|---|---|
committer | sbz <sbz@FreeBSD.org> | 2012-11-06 05:14:54 +0800 |
commit | e1f3a766ff724654dda429f5c7aaa06f2339fbf0 (patch) | |
tree | 8cf3c149c54b4c64bf56d739f8c705ec69b4a0ef /Tools | |
parent | dd8e494ba84052f74347c92dc7cb2fbcce5be560 (diff) | |
download | freebsd-ports-gnome-e1f3a766ff724654dda429f5c7aaa06f2339fbf0.tar.gz freebsd-ports-gnome-e1f3a766ff724654dda429f5c7aaa06f2339fbf0.tar.zst freebsd-ports-gnome-e1f3a766ff724654dda429f5c7aaa06f2339fbf0.zip |
- Fix runtime utf-8 problems using codec encoder and system locale
PR: ports/173195
Submitted by: rm
Reviewed by: sbz (myself)
Feature safe: yes
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/scripts/getpatch | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Tools/scripts/getpatch b/Tools/scripts/getpatch index 9c278ccd0086..baf762cd828b 100755 --- a/Tools/scripts/getpatch +++ b/Tools/scripts/getpatch @@ -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) |