Returns a native value from a YAML serialized string representation.
        Since YAML is a superset of JSON, this is the inverse of to_string.)
547790
def from_string(self, serialized):
        
        self._warn_deprecated_outside_JSONField()
        value = yaml.safe_load(serialized)
        return self.enforce_type(value)
1156048
def string(value) -> str:
        
        return system_json.dumps(Json(value).safe_object(), ensure_ascii=False)
262074
def native(s, encoding='utf-8', fallback='iso-8859-1'):
    """"""

    if isinstance(s, str):
        return s

    if str is unicode:  # Python 3.x ->
        return unicodestr(s, encoding, fallback)

    return bytestring(s, encoding, fallback)
217828
def _from_string(cls, serialized):
        
        # Allow access to _from_string protected method
        library_key = LibraryLocator._from_string(serialized)  # pylint: disable=protected-access
        parsed_parts = LibraryLocator.parse_url(serialized)

        block_id = parsed_parts.get('block_id', None)
        if block_id is None:
            raise InvalidKeyError(cls, serialized)

        block_type = parsed_parts.get('block_type')
        if block_type is None:
            raise InvalidKeyError(cls, serialized)

        return cls(library_key, parsed_parts.get('block_type'), block_id)
67173
def _to_str(dumped_val, encoding='utf-8', ordered=True):
    
    _dict = OrderedDict if ordered else dict
    if isinstance(dumped_val, dict):
        return OrderedDict((k, _to_str(v, encoding)) for k,v in dumped_val.items())
    elif isinstance(dumped_val, (list, tuple)):
        return [_to_str(v, encoding) for v in dumped_val]
    elif isinstance(dumped_val, bytes):
        try:
            d = dumped_val.decode('utf-8')
        except Exception:
            d = repr(dumped_val)
        return d
    else:
        return dumped_val
1019975
def _fromstring(value):
    '''
    '''

    if not value:
        return None
    std_value = value.strip().lower()
    if std_value == 'true':
        return 'true'
    elif std_value == 'false':
        return 'false'
#     try:
#         return int(std_value)
#     except ValueError:
#         pass
#     try:
#         return float(std_value)
#     except ValueError:
#         pass
    return value
1345183
def native_string_to_bytes(s, encoding="ascii", errors="strict"):
    
    if not isinstance(s, str):
        raise TypeError("{} must be type str, not {}".format(s, type(s)))
    if str is bytes:
        # Python 2
        return s
    else:
        # Python 3
        return s.encode(encoding=encoding, errors=errors)
1098619
def native(self, value, context=None):
		""""""
		
		separator = self.separator.strip() if self.strip and hasattr(self.separator, 'strip') else self.separator
		value = super().native(value, context)
		
		if value is None:
			return self.cast()
		
		if hasattr(value, 'split'):
			value = value.split(separator)
		
		value = self._clean(value)
		
		try:
			return self.cast(value) if self.cast else value
		except Exception as e:
			raise Concern("{0} caught, failed to perform array transform: {1}", e.__class__.__name__, str(e))
884602
def native_string_to_unicode(s, encoding="ascii", errors="strict"):
    
    if not isinstance(s, str):
        raise TypeError("{} must be type str, not {}".format(s, type(s)))
    if str is unicode:
        # Python 3
        return s
    else:
        # Python 2
        return s.decode(encoding=encoding, errors=errors)
955070
def to_python(self, value):
        
        if isinstance(value, dict):
            return value

        if self.blank and not value:
            return None

        if isinstance(value, string_types):
            try:
                return json.loads(value)
            except Exception as e:
                raise ValidationError(str(e))

        return value
1004195
def yaml_parse(yamlstr):
    """"""
    try:
        # PyYAML doesn't support json as well as it should, so if the input
        # is actually just json it is better to parse it with the standard
        # json parser.
        return json.loads(yamlstr)
    except ValueError:
        yaml.SafeLoader.add_multi_constructor("!", intrinsics_multi_constructor)
        return yaml.safe_load(yamlstr)
1070828
function baseToString$1(value) {
  // Exit early for strings to avoid a performance hit in some environments.
  if (typeof value == 'string') {
    return value;
  }
  if (isArray$6(value)) {
    // Recursively convert values (susceptible to call stack limits).
    return arrayMap(value, baseToString$1) + '';
  }
  if (isSymbol$2(value)) {
    return symbolToString ? symbolToString.call(value) : '';
  }
  var result = value + '';
  return result == '0' && 1 / value == -INFINITY ? '-0' : result;
}
841510
def from_string(cls, string):
        

        # find enum value
        for attr in dir(cls):
            value = getattr(cls, attr)
            if value == string:
                return value

        # if not found, log warning and return the value passed in
        logger.warning("{} is not a valid enum value for {}.".format(string, cls.__name__))
        return string
686935
def yamlify_arg(arg):
    '''
    
    '''
    if not isinstance(arg, six.string_types):
        return arg

    if arg.strip() == '':
        # Because YAML loads empty (or all whitespace) strings as None, we
        # return the original string
        # >>> import yaml
        # >>> yaml.load('') is None
        # True
        # >>> yaml.load('      ') is None
        # True
        return arg

    elif '_' in arg and all([x in '0123456789_' for x in arg.strip()]):
        # When the stripped string includes just digits and underscores, the
        # underscores are ignored and the digits are combined together and
        # loaded as an int. We don't want that, so return the original value.
        return arg

    try:
        # Explicit late import to avoid circular import. DO NOT MOVE THIS.
        import salt.utils.yaml
        original_arg = arg
        if '#' in arg:
            # Only yamlify if it parses into a non-string type, to prevent
            # loss of content due to # as comment character
            parsed_arg = salt.utils.yaml.safe_load(arg)
            if isinstance(parsed_arg, six.string_types) or parsed_arg is None:
                return arg
            return parsed_arg
        if arg == 'None':
            arg = None
        else:
            arg = salt.utils.yaml.safe_load(arg)

        if isinstance(arg, dict):
            # dicts must be wrapped in curly braces
            if (isinstance(original_arg, six.string_types) and
                    not original_arg.startswith('{')):
                return original_arg
            else:
                return arg

        elif isinstance(arg, list):
            # lists must be wrapped in brackets
            if (isinstance(original_arg, six.string_types) and
                    not original_arg.startswith('[')):
                return original_arg
            else:
                return arg

        elif arg is None \
                or isinstance(arg, (list, float, six.integer_types, six.string_types)):
            # yaml.safe_load will load '|' as '', don't let it do that.
            if arg == '' and original_arg in ('|',):
                return original_arg
            # yaml.safe_load will treat '#' as a comment, so a value of '#'
            # will become None. Keep this value from being stomped as well.
            elif arg is None and original_arg.strip().startswith('#'):
                return original_arg
            else:
                return arg
        else:
            # we don't support this type
            return original_arg
    except Exception:
        # In case anything goes wrong...
        return original_arg
725990
def _convert(self, payload):
        
        if not isinstance(payload, six.string_types):
            payload = json.dumps(payload, cls=DefaultJSONEncoder, sort_keys=True)
        return str(payload)
369426
def to_string(self, value):
        
        self._warn_deprecated_outside_JSONField()
        value = json.dumps(
            self.to_json(value),
            indent=2,
            sort_keys=True,
            separators=(',', ': '),
        )
        return value
388945
def getserialized(self, key, decoder_func=None, **kwargs):
        

        value = self.get(key, cast_func=None, **kwargs)

        if isinstance(value, (dict, list, tuple)) or value is None:
            return value

        if decoder_func: return decoder_func(value)

        try:
            o = json.loads(value)
            return o
        except json.decoder.JSONDecodeError: pass

        try:
            o = yaml.load(value)
            return o
        except yaml.parser.ParserError: pass

        raise ValueError('Unable to parse {} setting using JSON or YAML.'.format(key))