def _add_json_binary_field(b, serialized, field):
    ''' Set the given field to the given val (a bytearray) in the serialized
    dictionary.

    If the value isn't valid utf-8, we base64 encode it and use field+"64"
    as the field name.
    '''
    try:
        val = b.decode("utf-8")
        serialized[field] = val
    except UnicodeDecodeError:
        val = utils.raw_urlsafe_b64encode(b).decode('utf-8')
        serialized[field + '64'] = val
def _add_json_binary_field ( b , serialized , field ) : try : val = b . decode ( "utf-8" ) serialized [ field ] = val except UnicodeDecodeError : val = utils . raw_urlsafe_b64encode ( b ) . decode ( 'utf-8' ) serialized [ field + '64' ] = val
Set the given field to the given val (a bytearray) in the serialized
    dictionary.

    If the value isn't valid utf-8, we base64 encode it and use field+"64"
    as the field name.