diff mbox series

rpc: fix str to bytes conversion

Message ID 20200318104031.289921-1-tigran.mkrtchyan@desy.de (mailing list archive)
State New, archived
Headers show
Series rpc: fix str to bytes conversion | expand

Commit Message

Mkrtchyan, Tigran March 18, 2020, 10:40 a.m. UTC
fix back channel ping from server
---
 rpc/rpc.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

J. Bruce Fields March 24, 2020, 9:18 p.m. UTC | #1
Applied.--b.

On Wed, Mar 18, 2020 at 11:40:31AM +0100, Tigran Mkrtchyan wrote:
> fix back channel ping from server
> ---
>  rpc/rpc.py | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/rpc/rpc.py b/rpc/rpc.py
> index c536384..d15cf06 100644
> --- a/rpc/rpc.py
> +++ b/rpc/rpc.py
> @@ -693,8 +693,11 @@ class ConnectionHandler(object):
>                  status, result, notify = tuple
>              if result is None:
>                  result = b''
> +            if isinstance(result, str):
> +                result = bytes(result, encoding='UTF-8')
> +
>              if not isinstance(result, bytes):
> -                raise TypeError("Expected string")
> +                raise TypeError("Expected bytes, got %s" % type(result))
>              # status, result = method(msg_data, call_info)
>              log_t.debug("Called method, got %r, %r" % (status, result))
>          except rpclib.RPCDrop:
> -- 
> 2.25.1
diff mbox series

Patch

diff --git a/rpc/rpc.py b/rpc/rpc.py
index c536384..d15cf06 100644
--- a/rpc/rpc.py
+++ b/rpc/rpc.py
@@ -693,8 +693,11 @@  class ConnectionHandler(object):
                 status, result, notify = tuple
             if result is None:
                 result = b''
+            if isinstance(result, str):
+                result = bytes(result, encoding='UTF-8')
+
             if not isinstance(result, bytes):
-                raise TypeError("Expected string")
+                raise TypeError("Expected bytes, got %s" % type(result))
             # status, result = method(msg_data, call_info)
             log_t.debug("Called method, got %r, %r" % (status, result))
         except rpclib.RPCDrop: