use preferred locale for default encoding

git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2878 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
calvin 2005-10-13 17:22:12 +00:00
parent 9873747d92
commit 50ea41b12d
5 changed files with 9 additions and 7 deletions

View file

@ -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 ():

View file

@ -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()

View file

@ -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):
"""

View file

@ -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):
"""

View file

@ -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'"))