Encode the string using modified UTF-7.

    Args:
        data: The input string to encode.
499972
def modutf7_encode(data: str) -> bytes:
    
    ret = bytearray()
    is_usascii = True
    encode_start = None
    for i, symbol in enumerate(data):
        charpoint = ord(symbol)
        if is_usascii:
            if charpoint == 0x26:
                ret.extend(b'&-')
            elif 0x20 <= charpoint <= 0x7e:
                ret.append(charpoint)
            else:
                encode_start = i
                is_usascii = False
        else:
            if 0x20 <= charpoint <= 0x7e:
                to_encode = data[encode_start:i]
                encoded = _modified_b64encode(to_encode)
                ret.append(0x26)
                ret.extend(encoded)
                ret.extend((0x2d, charpoint))
                is_usascii = True
    if not is_usascii:
        to_encode = data[encode_start:]
        encoded = _modified_b64encode(to_encode)
        ret.append(0x26)
        ret.extend(encoded)
        ret.append(0x2d)
    return bytes(ret)
480347
def encode(self, data):
        ''''''
        if isinstance(data, str):
            data = bytearray(data, "latin-1")
        chunk_size = self.nsize - self.nsym
        enc = bytearray()
        for i in xrange(0, len(data), chunk_size):
            chunk = data[i:i+chunk_size]
            enc.extend(rs_encode_msg(chunk, self.nsym, fcr=self.fcr, generator=self.generator))
        return enc
466026
def ensure_bytes(data: Union[str, bytes]) -> bytes:
    
    if isinstance(data, str):
        return bytes(data, 'utf-8')

    return data
602384
def standardize_input_data(data):
    
    if type(data) == bytes:
        data = data.decode('utf-8')
    if type(data) == list:
        data = [
            el.decode('utf-8') if type(data) == bytes else el
            for el in data
        ]
    return data
802413
def astext(data):
    
    if isinstance(data, str):
        return data
    elif isinstance(data, text_type):
        return data.encode("utf-8", "ignore")
    elif isinstance(data, binary_type):
        return data.decode("utf-8", "ignore")
    raise TypeError('{!r} not a string'.format(data))
365487
public static String hexEncode(final String data) {
        try {
            val result = Hex.encodeHex(data.getBytes(StandardCharsets.UTF_8));
            return new String(result);
        } catch (final Exception e) {
            return null;
        }
    }
713746
def data_to_unicode(self, data):
        
        if isinstance(data, dict):
            return {self.to_unicode(k): self.to_unicode(v) for k, v in data.iteritems()}
        if isinstance(data, list):
            return [self.to_unicode(l) for l in data]
        else:
            return self.to_unicode(data)
120629
@FindbugsSuppressWarnings("DM_DEFAULT_ENCODING")
  public static String encodeBase64(String data) {
    final byte[] encodedBytes = Base64.encodeBase64(data.getBytes());

    return new String(encodedBytes);
  }
52331
def encode_and_quote(data):
    """"""
    if data is None:
        return None

    if isinstance(data, unicode):
        data = data.encode("utf-8")
    return urllib.quote_plus(data)
640465
def encode(data):
    
    res = ""
    for i in range(0,len(data), 3):
        if (i+2==len(data)):
            res += _encode3bytes(ord(data[i]), ord(data[i+1]), 0)
        elif (i+1==len(data)):
            res += _encode3bytes(ord(data[i]), 0, 0)
        else:
            res += _encode3bytes(ord(data[i]), ord(data[i+1]), ord(data[i+2]))
    return res
1131456
function encode(data) {
  $.checkArgument(data instanceof Array, 'Must be Array');
  var base32 = '';
  for (var i=0; i<data.length; i++) {
    var value = data[i];
    $.checkArgument(0 <= value && value < 32, 'Non-base32, value ' + value);
    base32 += CHARSET[value];
  }
  return base32;
}
411978
public static String encodeBase64(final String data) {
        return Base64.encodeBase64String(data.getBytes(StandardCharsets.UTF_8));
    }
1035198
def keys_to_string(data):
    
    if isinstance(data, dict):
        for key in list(data.keys()):
            if isinstance(key, six.string_types):
                value = data[key]
                val = keys_to_string(value)
                del data[key]
                data[key.encode("utf8", "ignore")] = val
    return data
522677
def encode(value, encoding='utf-8', encoding_errors='strict'):
    
    if isinstance(value, bytes):
        return value
    if not isinstance(value, basestring):
        value = str(value)
    if isinstance(value, unicode):
        value = value.encode(encoding, encoding_errors)
    return value
547449
public static String encode(byte[] data)
  {
	  StringBuffer result = new StringBuffer();

    for (int i = 0; i < data.length; i++) {
	    result.append(trans[(data[i] >> 4) & 0xf]);
	    result.append(trans[data[i] & 0xf]);
	  }

    return result.toString();
  }
556429
def string(self, *args):
        
        data = self.bytes(*args)
        if data is not None:
            return data.rstrip(b"\x00").decode('utf-8')
7622
def _to_unicode(self, data, encoding, errors='strict'):
    ''''''

    # strip Byte Order Mark (if present)
    if (len(data) >= 4) and (data[:2] == '\xfe\xff') and (data[2:4] != '\x00\x00'):
        encoding = 'utf-16be'
        data = data[2:]
    elif (len(data) >= 4) and (data[:2] == '\xff\xfe') and (data[2:4] != '\x00\x00'):
        encoding = 'utf-16le'
        data = data[2:]
    elif data[:3] == '\xef\xbb\xbf':
        encoding = 'utf-8'
        data = data[3:]
    elif data[:4] == '\x00\x00\xfe\xff':
        encoding = 'utf-32be'
        data = data[4:]
    elif data[:4] == '\xff\xfe\x00\x00':
        encoding = 'utf-32le'
        data = data[4:]
    newdata = unicode(data, encoding, errors)
    return newdata