diff --git a/linkcheck/checker/__init__.py b/linkcheck/checker/__init__.py index cccaf1cf..ffe19d99 100644 --- a/linkcheck/checker/__init__.py +++ b/linkcheck/checker/__init__.py @@ -154,7 +154,7 @@ acap # application configuration access protocol ignored_schemes_re = re.compile(ignored_schemes, re.VERBOSE) -_encoding = locale.getpreferredencoding() +_encoding = linkcheck.i18n.default_encoding stderr = codecs.getwriter(_encoding)(sys.stderr, errors="ignore") def internal_error (): diff --git a/linkcheck/ftests/__init__.py b/linkcheck/ftests/__init__.py index 920609a5..73372678 100644 --- a/linkcheck/ftests/__init__.py +++ b/linkcheck/ftests/__init__.py @@ -143,7 +143,7 @@ class StandardTest (unittest.TestCase): """ resultfile = self.get_file(filename+".result") d = {'curdir': os.getcwd()} - f = codecs.open(resultfile, "r", "iso8859-1") + f = codecs.open(resultfile, "r", linkcheck.i18n.default_encoding) resultlines = [line.rstrip('\r\n') % d for line in f \ if line.strip() and not line.startswith(u'#')] f.close() diff --git a/linkcheck/i18n.py b/linkcheck/i18n.py index 1298f0d0..21e241e5 100644 --- a/linkcheck/i18n.py +++ b/linkcheck/i18n.py @@ -26,6 +26,7 @@ import gettext # more supported languages are added in init() supported_languages = ['en'] default_language = 'en' +default_encoding = locale.getpreferredencoding() def install_builtin (translator, do_unicode): """ diff --git a/linkcheck/logger/__init__.py b/linkcheck/logger/__init__.py index 0662343d..f180dceb 100644 --- a/linkcheck/logger/__init__.py +++ b/linkcheck/logger/__init__.py @@ -24,6 +24,7 @@ import os import datetime import linkcheck.strformat +import linkcheck.i18n _ = lambda x: x Fields = dict( @@ -69,8 +70,8 @@ class Logger (object): # number of encountered warningss self.warnings = 0 # encoding of output - preferred = locale.getpreferredencoding() - self.output_encoding = args.get("encoding", preferred) + default = linkcheck.i18n.default_encoding + self.output_encoding = args.get("encoding", default) def init_fileoutput (self, args): """ diff --git a/linkchecker b/linkchecker index a021145e..f8fa2af6 100755 --- a/linkchecker +++ b/linkchecker @@ -37,6 +37,7 @@ import linkcheck optparse._ = _ # now import the rest of the linkchecker gang import linkcheck.log +import linkcheck.i18n import linkcheck.checker import linkcheck.checker.cache import linkcheck.checker.consumer @@ -301,8 +302,7 @@ class LCOptionParser (optparse.OptionParser, object): s = u"%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s" % (self.format_help(), Examples, LoggerTypes, RegularExpressions, ProxySupport, Notes, Retval, Warnings) - encoding = locale.getpreferredencoding() - s = s.encode(encoding, "replace") + s = s.encode(linkcheck.i18n.default_encoding, "replace") if os.name != 'posix': linkcheck.strformat.paginate(s) else: @@ -541,7 +541,7 @@ if options.output: if "/" in options.output: logtype, encoding = options.output.split("/", 1) else: - logtype, encoding = options.output, "iso-8859-15" + logtype, encoding = options.output, linkcheck.i18n.default_encoding if not linkcheck.Loggers.has_key(logtype.lower()): print_usage(_("Unknown logger type %r in %r for option %s") % \ (logtype, options.output, "'-o, --output'"))