code: def encodeGsm7(plaintext, discardInvalid=False):
      
      result = bytearray()
      if PYTHON_VERSION >= 3: 
          plaintext = str(plaintext)
      for char in plaintext:
          idx = GSM7_BASIC.find(char)
          if idx != -1:
              result.append(idx)
          elif char in GSM7_EXTENDED:
              result.append(0x1B) # ESC - switch to extended table
              result.append(ord(GSM7_EXTENDED[char]))
          elif not discardInvalid:
              raise ValueError('Cannot encode char "{0}" using GSM-7 encoding'.format(char))
      return result
docs: GSM-7 text encoding algorithm
      
      Encodes the specified text string into GSM-7 octets (characters). This method does not pack
      the characters into septets.
      
      :param text: the text string to encode
      :param discardInvalid: if True, characters that cannot be encoded will be silently discarded 
      
      :raise ValueError: if the text string cannot be encoded using GSM-7 encoding (unless discardInvalid == True)
      
      :return: A bytearray containing the string encoded in GSM-7 encoding
      :rtype: bytearray