Permalink
Browse files

- Fix runtime utf-8 problems using codec encoder and system locale

PR:		ports/173195
Submitted by:	rm
Reviewed by:	sbz (myself)
Feature safe:	yes
  • Loading branch information...
1 parent dd8e494 commit e1f3a766ff724654dda429f5c7aaa06f2339fbf0 @sbz sbz committed Nov 5, 2012
Showing with 6 additions and 3 deletions.
  1. +6 −3 Tools/scripts/getpatch
View
@@ -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,15 +51,16 @@ 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()
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)

0 comments on commit e1f3a76

Please sign in to comment.