From 46d3ffb2e287217e2afb7977bf3e41e6521ddab1 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Tue, 12 Jan 2021 14:20:50 -0500 Subject: [PATCH] diff shrink --- src/allmydata/util/encodingutil.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/allmydata/util/encodingutil.py b/src/allmydata/util/encodingutil.py index 48d5cc7b4..6d4cd3a8f 100644 --- a/src/allmydata/util/encodingutil.py +++ b/src/allmydata/util/encodingutil.py @@ -96,6 +96,20 @@ def get_io_encoding(): """ return io_encoding +def argv_to_unicode(s): + """ + Perform the inverse of ``unicode_to_argv``. + """ + if isinstance(s, unicode): + return s + precondition(isinstance(s, bytes), s) + + try: + return unicode(s, io_encoding) + except UnicodeDecodeError: + raise usage.UsageError("Argument %s cannot be decoded as %s." % + (quote_output(s), io_encoding)) + def argv_to_abspath(s, **kwargs): """ Convenience function to decode an argv element to an absolute path, with ~ expanded. @@ -119,20 +133,6 @@ def unicode_to_argv(s, mangle=False): return ensure_str(s) -def argv_to_unicode(s): - """ - Perform the inverse of ``unicode_to_argv``. - """ - if isinstance(s, unicode): - return s - precondition(isinstance(s, bytes), s) - - try: - return unicode(s, io_encoding) - except UnicodeDecodeError: - raise usage.UsageError("Argument %s cannot be decoded as %s." % - (quote_output(s), io_encoding)) - def unicode_to_url(s): """ Encode an unicode object used in an URL to bytes.