zktraffic/base/util.py
def read_string(data, offset, maxlen=1024, default="unreadable"):
  """
  Note: even though strings are utf-8 decoded, we need to str()
        them since they can't be used by intern() otherwise.
  """
  data = to_bytes(data)
  old = offset
  length, offset = read_number(data, offset)

  if length > maxlen:
    raise StringTooLong("Length %d is greater than the maximum length (%d)" % (length, maxlen))

  if length < 0:
    return ("", old)

  try:
    s = data[offset:offset + length].decode("utf-8")
  except UnicodeDecodeError:
    s = default

  # back to str, so it can be consumed by intern()
  try:
    s = str(s)
  except UnicodeEncodeError:
    s = default

  return (s, offset + length)

  Note: even though strings are utf-8 decoded, we need to str()
        them since they can't be used by intern() otherwise.
  
even though strings are utf-8 decoded, we need to str()
them since they can't be used by intern() otherwise.
even though strings are utf - 8 decoded we need to str () them since they can ' t be used by intern () otherwise .
def read_string(data, offset, maxlen=1024, default="unreadable"):
  data = to_bytes(data)
  old = offset
  length, offset = read_number(data, offset)
  if length > maxlen:
    raise StringTooLong("Length %d is greater than the maximum length (%d)" % (length, maxlen))
  if length < 0:
    return ("", old)
  try:
    s = data[offset:offset + length].decode("utf-8")
  except UnicodeDecodeError:
    s = default
  try:
    s = str(s)
  except UnicodeEncodeError:
    s = default
  return (s, offset + length)
def read_string ( data , offset , maxlen = 1024 , default = "unreadable" ) : data = to_bytes ( data ) old = offset length , offset = read_number ( data , offset ) if length > maxlen : raise StringTooLong ( "Length %d is greater than the maximum length (%d)" % ( length , maxlen ) ) if length < 0 : return ( "" , old ) try : s = data [ offset : offset + length ] . decode ( "utf-8" ) except UnicodeDecodeError : s = default try : s = str ( s ) except UnicodeEncodeError : s = default return ( s , offset + length )
Note: even though strings are utf-8 decoded, we need to str()
them since they can't be used by intern() otherwise.
Note : even though strings are utf - 8 decoded we need to str () them since they can ' t be used by intern () otherwise .
"""
  Note: even though strings are utf-8 decoded, we need to str()
        them since they can't be used by intern() otherwise.
  """ # back to str, so it can be consumed by intern()
data
offset
maxlen
default