_fromstring

    Convert XML string value to None, boolean, int or float.
194540
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
742640
def string_to_element(element_as_string, include_namespaces=False):
    

    if element_as_string is None:
        return None
    elif isinstance(element_as_string, ElementTree):
        return element_as_string.getroot()
    elif isinstance(element_as_string, ElementType):
        return element_as_string
    else:
        element_as_string = _xml_content_to_string(element_as_string)

    if not isinstance(element_as_string, string_types):
        # Let cElementTree handle the error
        return fromstring(element_as_string)
    elif not strip_xml_declaration(element_as_string):
        # Same as ElementTree().getroot()
        return None
    elif include_namespaces:
        return fromstring(element_as_string)
    else:
        return fromstring(strip_namespaces(element_as_string))
482594
def to_python(cls, value, **kwargs):
        """"""
        if not value:
            return ''
        try:
            return str(value)
        except:
            pass
        try:
            return value.encode('utf-8')
        except:
            pass
        raise cls.exception("Cannot deserialize value {0} tostring".format(value))
1284416
def to_bool(value):
    '''
    
    '''
    if isinstance(value, bool):
        return value
    elif isinstance(value, basestring):
        return value.lower() == 'true' or value.lower() == 't'
    elif isinstance(value, int):
        return value > 0
    else:
        return False
1165606
def _from_python(self, value):
        
        if hasattr(value, 'strftime'):
            if hasattr(value, 'hour'):
                offset = value.utcoffset()
                if offset:
                    value = value - offset
                value = value.replace(tzinfo=None).isoformat() + 'Z'
            else:
                value = "%sT00:00:00Z" % value.isoformat()
        elif isinstance(value, bool):
            if value:
                value = 'true'
            else:
                value = 'false'
        else:
            if IS_PY3:
                # Python 3.X
                if isinstance(value, bytes):
                    value = str(value, errors='replace')  # NOQA: F821
            else:
                # Python 2.X
                if isinstance(value, str):
                    value = unicode(value, errors='replace')   # NOQA: F821

            value = "{0}".format(value)

        return clean_xml_string(value)
604283
def get_xml_root_from_str(xml_str):
    """"""
    try:
        xml_root = etree.fromstring(xml_str.encode("utf-8"), NO_BLANKS_PARSER)
    # pylint: disable=broad-except
    except Exception as err:
        raise Dump2PolarionException("Failed to parse XML string: {}".format(err))
    return xml_root
484407
def convert_none(key, val, attr_type, attr={}, cdata=False):
    """"""
    LOG.info('Inside convert_none(): key="%s"' % (unicode_me(key)))

    key, attr = make_valid_xml_name(key, attr)

    if attr_type:
        attr['type'] = get_xml_type(val)
    attrstring = make_attrstring(attr)
    return '<%s%s></%s>' % (key, attrstring, key)
816116
def parse_boolean(value):
    

    if value is None:
        return None

    if isinstance(value, bool):
        return value

    if isinstance(value, string_types):
        value = value.lower()
        if value == 'false':
            return False
        if value == 'true':
            return True

    raise ValueError("Could not convert value to boolean: {}".format(value))
648210
def fromstring(s):
  
  ps = PatchSet( StringIO(s) )
  if ps.errors == 0:
    return ps
  return False
548770
def _to_number(cls, string):
        """"""
        try:
            if float(string) - int(string) == 0:
                return int(string)
            return float(string)
        except ValueError:
            try:
                return float(string)
            except ValueError:
                return string
952523
def _convert_string_to_native(value):
    """"""
    result = None

    try:
        result = ast.literal_eval(str(value))
    except (SyntaxError, ValueError):
        # Likely a string
        result = value.split(',')
    return result
1023083
function fromString( $string )
    {
        $dataType = $this->dataType();
        if ( $dataType )
            return $dataType->fromString( $this, $string );
        else
            return false;
    }
1028331
def encode(cls, value):
        
        if value not in [True, False]:
            raise InvalidValue('not a boolean')

        return b'1' if value else b''
764463
def from_string(cls, jss, xml_string):
        
        root = ElementTree.fromstring(xml_string.encode('utf-8'))
        return cls(jss, root)
96253
def fromxml(node):
        """"""
        if not isinstance(node,ElementTree._Element): #pylint: disable=protected-access
            node = parsexmlstring(node)
        if node.tag.lower() != 'meta':
            raise Exception("Expected meta tag but got '" + node.tag + "' instead")

        key = node.attrib['id']
        if node.text:
            value = node.text
        else:
            value = None
        operator = 'set'
        if 'operator' in node.attrib:
            operator= node.attrib['operator']
        if operator == 'set':
            cls = SetMetaField
        elif operator == 'unset':
            cls = UnsetMetaField
        elif operator == 'copy':
            cls = CopyMetaField
        elif operator == 'parameter':
            cls = ParameterMetaField
        return cls(key, value)
1317692
def parse_value(val, parsebool=False):
    
    try:
        return int(val)
    except ValueError:
        pass
    try:
        return float(val)
    except:
        pass
    if parsebool:
        if re.match('yes|on', str(val), re.IGNORECASE):
            return True
        elif re.match('no|off', str(val), re.IGNORECASE):
            return False
    return val
506619
def _convert_to_closest_type(value):
    '''
    
    '''
    value = salt.utils.stringutils.to_bool(value.strip())

    if isinstance(value, bool):
        return value

    return salt.utils.stringutils.to_none(salt.utils.stringutils.to_num(value))