Changeset 3354
- Timestamp:
- 03/26/08 00:18:58 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/utils.py
r3321 r3354 112 112 return None 113 113 114 def getdefaultcharset() : 115 """Returns the default charset to use.""" 116 return sys.stdout.encoding or locale.getlocale()[1] or "ANSI_X3.4-1968" 117 114 118 def logerr(text) : 115 119 """Logs an unicode text to stderr.""" 116 sys.stderr.write(text.encode(sys.stdout.encoding \ 117 or locale.getlocale()[1] \ 118 or "ANSI_X3.4-1968", \ 119 "replace")) 120 sys.stderr.write(text.encode(getdefaultcharset(), "replace")) 120 121 sys.stderr.flush() 121 122 122 def loginvalidparam(opt, value, defaultvalue , additionalinfo=None) :123 def loginvalidparam(opt, value, defaultvalue=None, additionalinfo=None) : 123 124 """Logs an error when an invalid parameter to a command line option 124 125 is encountered. 125 126 """ 126 message = _("Invalid value '%(value)s' for the %(opt)s command line option , using default '%(defaultvalue)s' instead") \127 message = _("Invalid value '%(value)s' for the %(opt)s command line option") \ 127 128 % locals() 129 if defaultvalue is not None : 130 message += ", using default '%(defaultvalue)s' instead" % locals() 128 131 if additionalinfo : 129 132 logerr("%s (%s)\n" % (message, additionalinfo)) … … 135 138 import traceback 136 139 from pykota.version import __version__ 137 charset = sys.stdout.encoding or locale.getlocale()[1] or "ANSI_X3.4-1968"138 140 lines = [] 139 141 for line in traceback.format_exception(*sys.exc_info()) : 140 line = line.decode( charset, "replace")142 line = line.decode(getdefaultcharset(), "replace") 141 143 lines.extend([l for l in line.split("\n") if l]) 142 144 msg = "ERROR: ".join(["%s\n" % l for l in (["ERROR: PyKota v%s" % __version__, message] + lines)])