vici: Explicitly set the Python encoding type
When using vici over RPyC and its (awesome) splitbrain, encoding and decoding strings fails in vici, most likely because of the Monkey-Patch magic splitbrain uses. When specifying the implicit UTF-8 as encoding scheme explicitly, Python uses the correct method to encode/decode the string, making vici useable in splitbrain contexts.
This commit is contained in:
@@ -62,7 +62,7 @@ class Packet(object):
|
||||
|
||||
@classmethod
|
||||
def _named_request(cls, request_type, request, message=None):
|
||||
request = request.encode()
|
||||
requestdata = request.encode("UTF-8")
|
||||
payload = struct.pack("!BB", request_type, len(request)) + request
|
||||
if message is not None:
|
||||
return payload + message
|
||||
@@ -105,12 +105,12 @@ class Message(object):
|
||||
@classmethod
|
||||
def serialize(cls, message):
|
||||
def encode_named_type(marker, name):
|
||||
name = name.encode()
|
||||
name = name.encode("UTF-8")
|
||||
return struct.pack("!BB", marker, len(name)) + name
|
||||
|
||||
def encode_blob(value):
|
||||
if not isinstance(value, bytes):
|
||||
value = str(value).encode()
|
||||
value = str(value).encode("UTF-8")
|
||||
return struct.pack("!H", len(value)) + value
|
||||
|
||||
def serialize_list(lst):
|
||||
@@ -147,7 +147,7 @@ class Message(object):
|
||||
def deserialize(cls, stream):
|
||||
def decode_named_type(stream):
|
||||
length, = struct.unpack("!B", stream.read(1))
|
||||
return stream.read(length).decode()
|
||||
return stream.read(length).decode("UTF-8")
|
||||
|
||||
def decode_blob(stream):
|
||||
length, = struct.unpack("!H", stream.read(2))
|
||||
|
||||
Reference in New Issue
Block a user