code: def truncate(data, limit, whence=None, msg=None):
      msg = "..." if msg is None else msg
      msg = six.ensure_binary(msg)
      whence = Whence.End if whence is None else whence
      data = six.ensure_binary(data)
  
      if len(data) <= limit:
          return six.ensure_str(data)
      text_limit = limit - len(msg)
      assert text_limit >= 0
  
      if whence == Whence.Start:
          data = msg + data[-text_limit:]
      elif whence == Whence.End:
          data = data[:text_limit] + msg
      elif whence == Whence.Middle:
          headpos = limit // 2 - len(msg) // 2
          tailpos = len(data) - (text_limit - headpos)
          data = data[:headpos] + msg + data[tailpos:]
      else:
          raise AssertionError("Unknown whence: %s" % str(whence))
      return fix_utf8(data)
  
imports: import locale
  import logging
  import six
  import sys
  import codecs
  import library.python.func
label_desc: Use image node_id 14 for calling a global function with example usage: truncate(data, limit, whence, msg) and returns: fix_utf8, six