codelength() now also accepts ASCII strings
This commit is contained in:
parent
475dc0a902
commit
1ae60f2a6c
|
@ -6,7 +6,14 @@ import socket, os
|
|||
|
||||
|
||||
def codelength(s):
|
||||
""" returns the given bytearray, prepended with the 7-bit-encoded length """
|
||||
""" returns the given string/bytes as bytes, prepended with the 7-bit-encoded length """
|
||||
# We want bytes
|
||||
if not isinstance(s, bytes):
|
||||
# Not bytes. Let's try to convert to bytes, but only plain ASCII
|
||||
try:
|
||||
s = str.encode(s,"ascii")
|
||||
except:
|
||||
s = b''
|
||||
l = len(s)
|
||||
if l == 0:
|
||||
return b'\x00'
|
||||
|
|
Loading…
Reference in New Issue