Parse from a byte array (containing utf-8 encoded string with the Python literal expression in it)
2180
public Ast parse(byte[] serialized) throws ParseException
	{
		try {
			return parse(new String(serialized, "utf-8"));
		} catch (UnsupportedEncodingException e) {
			throw new ParseException(e.toString());
		}
	}
1264095
def deserialize_bytearray(attr):
        
        if isinstance(attr, ET.Element):
            attr = attr.text
        return bytearray(b64decode(attr))
602718
byte[] getBytesUTF8(String s) {
        if (isUTF8)
            return getBytes(s);
        if (utf8 == null)
            utf8 = new ZipCoder(StandardCharsets.UTF_8);
        return utf8.getBytes(s);
    }
142204
function (bytes) {
                var str = '';
                for (var i = 0, l = bytes.length; i < l; i += 2) {
                    str += String.fromCharCode((bytes[i] << 8) + bytes[i + 1]);
                }
                return str;
            }
1312884
public static UTF8String fromBytes(byte[] bytes, int offset, int numBytes) {
    if (bytes != null) {
      return new UTF8String(bytes, BYTE_ARRAY_OFFSET + offset, numBytes);
    } else {
      return null;
    }
  }
2890
def _decode_bytes(self, bytestring):
        
        if not bytestring:
            return u''
        try:
            return bytestring.decode('utf-8')
        except UnicodeDecodeError:
            self.close(1007)
            raise
801273
def decode(in_bytes):
    """"""
    out_bytes = []
    idx = 0

    if len(in_bytes) > 0:
        while True:
            length = ord(in_bytes[idx])
            if length == 0:
                raise DecodeError("zero byte found in input")
            idx += 1
            end = idx + length - 1
            copy_bytes = in_bytes[idx:end]
            if '\x00' in copy_bytes:
                raise DecodeError("zero byte found in input")
            out_bytes.append(copy_bytes)
            idx = end
            if idx > len(in_bytes):
                raise DecodeError("not enough input bytes for length code")
            if idx < len(in_bytes):
                if length < 0xFF:
                    out_bytes.append('\x00')
            else:
                break
    return ''.join(out_bytes)
660969
static ByteBuffer unescapeBytes(final CharSequence input)
    {
        int pos = 0, len = input.length();
        final byte[] result = new byte[len];
        ByteBuffer buffer = ByteBuffer.wrap(result);
        for (int i = 0; i < len; i++)
        {
            char c = input.charAt(i);
            if (c == '\\')
            {
                if (i + 1 < len)
                {
                    ++i;
                    c = input.charAt(i);
                    if (isOctal(c))
                    {
                        // Octal escape.
                        int code = digitValue(c);
                        if (i + 1 < len && isOctal(input.charAt(i + 1)))
                        {
                            ++i;
                            code = code * 8 + digitValue(input.charAt(i));
                        }
                        if (i + 1 < len && isOctal(input.charAt(i + 1)))
                        {
                            ++i;
                            code = code * 8 + digitValue(input.charAt(i));
                        }
                        result[pos++] = (byte) code;
                    }
                    else
                    {
                        switch (c)
                        {
                            case 'a':
                                result[pos++] = 0x07;
                                break;
                            case 'b':
                                result[pos++] = '\b';
                                break;
                            case 'f':
                                result[pos++] = '\f';
                                break;
                            case 'n':
                                result[pos++] = '\n';
                                break;
                            case 'r':
                                result[pos++] = '\r';
                                break;
                            case 't':
                                result[pos++] = '\t';
                                break;
                            case 'v':
                                result[pos++] = 0x0b;
                                break;
                            case '\\':
                                result[pos++] = '\\';
                                break;
                            case '\'':
                                result[pos++] = '\'';
                                break;
                            case '"':
                                result[pos++] = '\"';
                                break;

                            case 'x':
                                // hex escape
                                int code = 0;
                                if (i + 1 < len && isHex(input.charAt(i + 1)))
                                {
                                    ++i;
                                    code = digitValue(input.charAt(i));
                                }
                                else
                                {
                                    throw new InvalidEscapeSequenceException(
                                            "Invalid escape sequence: '\\x' with no digits");
                                }
                                if (i + 1 < len && isHex(input.charAt(i + 1)))
                                {
                                    ++i;
                                    code = code * 16 + digitValue(input.charAt(i));
                                }
                                result[pos++] = (byte) code;
                                break;

                            default:
                                throw new InvalidEscapeSequenceException(
                                        "Invalid escape sequence: '\\" + c + '\'');
                        }
                    }
                }
                else
                {
                    throw new InvalidEscapeSequenceException(
                            "Invalid escape sequence: '\\' at end of string.");
                }
            }
            else
            {
                result[pos++] = (byte) c;
            }
        }
        buffer.limit(pos);
        return buffer;
    }
1254205
function tryParseBase64ToBytes(b64Str) {
    let decodedStr;

    try {
      decodedStr = atob(b64Str);
    } catch (e) {
      return null;
    }

    return Uint8Array.from(decodedStr, c => c.charCodeAt(0));
  }
789814
def parse(self, data, mimetype):
        
        encoding = mimetype.params.get('charset') or 'utf-8'

        return json.loads(data.decode(encoding))
949796
def utf8(value):
    
    if isinstance(value, _UTF8_TYPES):
        return value
    if not isinstance(value, unicode_type):
        raise TypeError(
            "Expected bytes, unicode, or None; got %r" % type(value)
        )
    return value.encode("utf-8")
1046665
def decode_modified_utf8(s: bytes) -> str:
    
    s = bytearray(s)
    buff = []
    buffer_append = buff.append
    ix = 0
    while ix < len(s):
        x = s[ix]
        ix += 1

        if x >> 7 == 0:
            # Just an ASCII character, nothing else to do.
            pass
        elif x >> 6 == 6:
            y = s[ix]
            ix += 1
            x = ((x & 0x1F) << 6) + (y & 0x3F)
        elif x >> 4 == 14:
            y, z = s[ix:ix+2]
            ix += 2
            x = ((x & 0xF) << 12) + ((y & 0x3F) << 6) + (z & 0x3F)
        elif x == 0xED:
            v, w, x, y, z = s[ix:ix+6]
            ix += 5
            x = 0x10000 + (
                ((v & 0x0F) << 16) +
                ((w & 0x3F) << 10) +
                ((y & 0x0F) << 6) +
                (z & 0x3F)
            )
        elif x == 0xC0 and s[ix] == 0x80:
            ix += 1
            x = 0
        buffer_append(x)
    return u''.join(chr(b) for b in buff)
688665
def _bytes_to_str(lines):
    
    if len(lines) >= 1 and hasattr(lines[0], 'decode'):
        return [line.decode('utf-8') for line in lines]
    else:
        return lines
976422
def detect_encoding(string):
    
    assert isinstance(string, bytes)
    try:
        detected = chardet.detect(string)
        if detected:
            return detected.get('encoding') or 'utf-8'
    except Exception as e:
        pass
    return 'utf-8'
782438
def data_from_bytes(self, byte_representation):
        
        text = byte_representation.decode(self.encoding)
        return self.data_from_string(text)
406771
def utf8(value):
    
    """
    try:
        if isinstance(value, bytes):
            return value.decode('utf-8')
        else:
            return value
    except Exception:
        raise ValueError('Not UTF-8: %r' % value)
994066
def parse(self, string, strict=True):
        '''
        '''
        if isinstance(string, bytes):
            errors = 'strict' if strict else 'replace'
            string = string.decode(self.encoding, errors=errors)

        if not self.raw:
            self.raw = string
        else:
            self.raw += string

        lines = unfold_lines(string).splitlines()
        for line in lines:
            if line:
                if ':' not in line:
                    if strict:
                        raise ValueError('Field missing colon.')
                    else:
                        continue

                name, value = line.split(':', 1)
                name = name.strip()
                value = value.strip()
                self.add(name, value)