~ed.so/duplicity/lftp.ncftp.and.prefixes

« back to all changes in this revision

Viewing changes to duplicity/util.py

  • Committer: Michael Terry
  • Date: 2014-04-29 23:49:01 UTC
  • mto: This revision was merged to the branch mainline in revision 982.
  • Revision ID: michael.terry@canonical.com-20140429234901-v6pibw48msst0uot
Convert exceptions to unicode

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    lines = traceback.format_tb(tb, limit)
49
49
    lines.extend(traceback.format_exception_only(type, value))
50
50
 
51
 
    str = "Traceback (innermost last):\n"
52
 
    str = str + "%-20s %s" % (string.join(lines[:-1], ""),
53
 
                                lines[-1])
 
51
    msg = "Traceback (innermost last):\n"
 
52
    msg = msg + "%-20s %s" % (string.join(lines[:-1], ""), lines[-1])
54
53
 
55
 
    return str
 
54
    return uexc(msg)
56
55
 
57
56
def escape(string):
58
57
    "Convert a (bytes) filename to a format suitable for logging (quoted utf8)"
71
70
    else:
72
71
        return u'.'
73
72
 
 
73
def uexc(e):
 
74
    # Exceptions in duplicity often have path names in them, which if they are
 
75
    # non-ascii will cause a UnicodeDecodeError when implicitly decoding to
 
76
    # unicode.  So we decode manually, using the filesystem encoding.
 
77
    # 99.99% of the time, this will be a fine encoding to use.
 
78
    return ufn(str(e))
 
79
 
74
80
def maybe_ignore_errors(fn):
75
81
    """
76
82
    Execute fn. If the global configuration setting ignore_errors is
85
91
    except Exception as e:
86
92
        if globals.ignore_errors:
87
93
            log.Warn(_("IGNORED_ERROR: Warning: ignoring error as requested: %s: %s")
88
 
                     % (e.__class__.__name__, str(e)))
 
94
                     % (e.__class__.__name__, uexc(e)))
89
95
            return None
90
96
        else:
91
97
            raise