def loads(s, _dict=dict):
implicitgroups = []<EOL>retval = _dict()<EOL>currentlevel = retval<EOL>if not isinstance(s, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if not isinstance(s, unicode):<EOL><INDENT>s = s.decode('<STR_LIT:utf8>')<EOL><DEDENT>sl = list(s)<EOL>openarr = <NUM_LIT:0><EOL>openstring = False<EOL>openstrchar = "<STR_LIT>"<EOL>multilinestr = False<EOL>arrayoftables = False<EOL>beginline = True<EOL>keygroup = False<EOL>keyname = <NUM_LIT:0><EOL>for i, item in enumerate(sl):<EOL><INDENT>if item == '<STR_LIT:\r>' and sl[i + <NUM_LIT:1>] == '<STR_LIT:\n>':<EOL><INDENT>sl[i] = '<STR_LIT:U+0020>'<EOL>continue<EOL><DEDENT>if keyname:<EOL><INDENT>if item == '<STR_LIT:\n>':<EOL><INDENT>raise TomlDecodeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if openstring:<EOL><INDENT>if item == openstrchar:<EOL><INDENT>keyname = <NUM_LIT:2><EOL>openstring = False<EOL>openstrchar = "<STR_LIT>"<EOL><DEDENT>continue<EOL><DEDENT>elif keyname == <NUM_LIT:1>:<EOL><INDENT>if item.isspace():<EOL><INDENT>keyname = <NUM_LIT:2><EOL>continue<EOL><DEDENT>elif item.isalnum() or item == '<STR_LIT:_>' or item == '<STR_LIT:->':<EOL><INDENT>continue<EOL><DEDENT><DEDENT>elif keyname == <NUM_LIT:2> and item.isspace():<EOL><INDENT>continue<EOL><DEDENT>if item == '<STR_LIT:=>':<EOL><INDENT>keyname = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>raise TomlDecodeError("<STR_LIT>" +<EOL>item + "<STR_LIT>")<EOL><DEDENT><DEDENT>if item == "<STR_LIT:'>" and openstrchar != '<STR_LIT:">':<EOL><INDENT>k = <NUM_LIT:1><EOL>try:<EOL><INDENT>while sl[i - k] == "<STR_LIT:'>":<EOL><INDENT>k += <NUM_LIT:1><EOL>if k == <NUM_LIT:3>:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>except IndexError:<EOL><INDENT>pass<EOL><DEDENT>if k == <NUM_LIT:3>:<EOL><INDENT>multilinestr = not multilinestr<EOL>openstring = multilinestr<EOL><DEDENT>else:<EOL><INDENT>openstring = not openstring<EOL><DEDENT>if openstring:<EOL><INDENT>openstrchar = "<STR_LIT:'>"<EOL><DEDENT>else:<EOL><INDENT>openstrchar = "<STR_LIT>"<EOL><DEDENT><DEDENT>if item == '<STR_LIT:">' and openstrchar != "<STR_LIT:'>":<EOL><INDENT>oddbackslash = False<EOL>k = <NUM_LIT:1><EOL>tripquote = False<EOL>try:<EOL><INDENT>while sl[i - k] == '<STR_LIT:">':<EOL><INDENT>k += <NUM_LIT:1><EOL>if k == <NUM_LIT:3>:<EOL><INDENT>tripquote = True<EOL>break<EOL><DEDENT><DEDENT>if k == <NUM_LIT:1> or (k == <NUM_LIT:3> and tripquote):<EOL><INDENT>while sl[i - k] == '<STR_LIT:\\>':<EOL><INDENT>oddbackslash = not oddbackslash<EOL>k += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>except IndexError:<EOL><INDENT>pass<EOL><DEDENT>if not oddbackslash:<EOL><INDENT>if tripquote:<EOL><INDENT>multilinestr = not multilinestr<EOL>openstring = multilinestr<EOL><DEDENT>else:<EOL><INDENT>openstring = not openstring<EOL><DEDENT><DEDENT>if openstring:<EOL><INDENT>openstrchar = '<STR_LIT:">'<EOL><DEDENT>else:<EOL><INDENT>openstrchar = "<STR_LIT>"<EOL><DEDENT><DEDENT>if item == '<STR_LIT:#>' and (not openstring and not keygroup and<EOL>not arrayoftables):<EOL><INDENT>j = i<EOL>try:<EOL><INDENT>while sl[j] != '<STR_LIT:\n>':<EOL><INDENT>sl[j] = '<STR_LIT:U+0020>'<EOL>j += <NUM_LIT:1><EOL><DEDENT><DEDENT>except IndexError:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if item == '<STR_LIT:[>' and (not openstring and not keygroup and<EOL>not arrayoftables):<EOL><INDENT>if beginline:<EOL><INDENT>if sl[i + <NUM_LIT:1>] == '<STR_LIT:[>':<EOL><INDENT>arrayoftables = True<EOL><DEDENT>else:<EOL><INDENT>keygroup = True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>openarr += <NUM_LIT:1><EOL><DEDENT><DEDENT>if item == '<STR_LIT:]>' and not openstring:<EOL><INDENT>if keygroup:<EOL><INDENT>keygroup = False<EOL><DEDENT>elif arrayoftables:<EOL><INDENT>if sl[i - <NUM_LIT:1>] == '<STR_LIT:]>':<EOL><INDENT>arrayoftables = False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>openarr -= <NUM_LIT:1><EOL><DEDENT><DEDENT>if item == '<STR_LIT:\n>':<EOL><INDENT>if openstring or multilinestr:<EOL><INDENT>if not multilinestr:<EOL><INDENT>raise TomlDecodeError("<STR_LIT>")<EOL><DEDENT>if ((sl[i - <NUM_LIT:1>] == "<STR_LIT:'>" or sl[i - <NUM_LIT:1>] == '<STR_LIT:">') and (<EOL>sl[i - <NUM_LIT:2>] == sl[i - <NUM_LIT:1>])):<EOL><INDENT>sl[i] = sl[i - <NUM_LIT:1>]<EOL>if sl[i - <NUM_LIT:3>] == sl[i - <NUM_LIT:1>]:<EOL><INDENT>sl[i - <NUM_LIT:3>] = '<STR_LIT:U+0020>'<EOL><DEDENT><DEDENT><DEDENT>elif openarr:<EOL><INDENT>sl[i] = '<STR_LIT:U+0020>'<EOL><DEDENT>else:<EOL><INDENT>beginline = True<EOL><DEDENT><DEDENT>elif beginline and sl[i] != '<STR_LIT:U+0020>' and sl[i] != '<STR_LIT:\t>':<EOL><INDENT>beginline = False<EOL>if not keygroup and not arrayoftables:<EOL><INDENT>if sl[i] == '<STR_LIT:=>':<EOL><INDENT>raise TomlDecodeError("<STR_LIT>")<EOL><DEDENT>keyname = <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>s = '<STR_LIT>'.join(sl)<EOL>s = s.split('<STR_LIT:\n>')<EOL>multikey = None<EOL>multilinestr = "<STR_LIT>"<EOL>multibackslash = False<EOL>for line in s:<EOL><INDENT>if not multilinestr or multibackslash or '<STR_LIT:\n>' not in multilinestr:<EOL><INDENT>line = line.strip()<EOL><DEDENT>if line == "<STR_LIT>" and (not multikey or multibackslash):<EOL><INDENT>continue<EOL><DEDENT>if multikey:<EOL><INDENT>if multibackslash:<EOL><INDENT>multilinestr += line<EOL><DEDENT>else:<EOL><INDENT>multilinestr += line<EOL><DEDENT>multibackslash = False<EOL>if len(line) > <NUM_LIT:2> and (line[-<NUM_LIT:1>] == multilinestr[<NUM_LIT:0>] and<EOL>line[-<NUM_LIT:2>] == multilinestr[<NUM_LIT:0>] and<EOL>line[-<NUM_LIT:3>] == multilinestr[<NUM_LIT:0>]):<EOL><INDENT>value, vtype = _load_value(multilinestr, _dict)<EOL>currentlevel[multikey] = value<EOL>multikey = None<EOL>multilinestr = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>k = len(multilinestr) - <NUM_LIT:1><EOL>while k > -<NUM_LIT:1> and multilinestr[k] == '<STR_LIT:\\>':<EOL><INDENT>multibackslash = not multibackslash<EOL>k -= <NUM_LIT:1><EOL><DEDENT>if multibackslash:<EOL><INDENT>multilinestr = multilinestr[:-<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>multilinestr += "<STR_LIT:\n>"<EOL><DEDENT><DEDENT>continue<EOL><DEDENT>if line[<NUM_LIT:0>] == '<STR_LIT:[>':<EOL><INDENT>arrayoftables = False<EOL>if line[<NUM_LIT:1>] == '<STR_LIT:[>':<EOL><INDENT>arrayoftables = True<EOL>line = line[<NUM_LIT:2>:].split('<STR_LIT>', <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>line = line[<NUM_LIT:1>:].split('<STR_LIT:]>', <NUM_LIT:1>)<EOL><DEDENT>if line[<NUM_LIT:1>].strip() != "<STR_LIT>":<EOL><INDENT>raise TomlDecodeError("<STR_LIT>")<EOL><DEDENT>groups = line[<NUM_LIT:0>].split('<STR_LIT:.>')<EOL>i = <NUM_LIT:0><EOL>while i < len(groups):<EOL><INDENT>groups[i] = groups[i].strip()<EOL>if groups[i][<NUM_LIT:0>] == '<STR_LIT:">' or groups[i][<NUM_LIT:0>] == "<STR_LIT:'>":<EOL><INDENT>groupstr = groups[i]<EOL>j = i + <NUM_LIT:1><EOL>while not groupstr[<NUM_LIT:0>] == groupstr[-<NUM_LIT:1>]:<EOL><INDENT>j += <NUM_LIT:1><EOL>groupstr = '<STR_LIT:.>'.join(groups[i:j])<EOL><DEDENT>groups[i] = groupstr[<NUM_LIT:1>:-<NUM_LIT:1>]<EOL>groups[i + <NUM_LIT:1>:j] = []<EOL><DEDENT>else:<EOL><INDENT>if not _groupname_re.match(groups[i]):<EOL><INDENT>raise TomlDecodeError("<STR_LIT>" +<EOL>groups[i] + "<STR_LIT>")<EOL><DEDENT><DEDENT>i += <NUM_LIT:1><EOL><DEDENT>currentlevel = retval<EOL>for i in _range(len(groups)):<EOL><INDENT>group = groups[i]<EOL>if group == "<STR_LIT>":<EOL><INDENT>raise TomlDecodeError("<STR_LIT>"<EOL>"<STR_LIT:name>")<EOL><DEDENT>try:<EOL><INDENT>currentlevel[group]<EOL>if i == len(groups) - <NUM_LIT:1>:<EOL><INDENT>if group in implicitgroups:<EOL><INDENT>implicitgroups.remove(group)<EOL>if arrayoftables:<EOL><INDENT>raise TomlDecodeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>elif arrayoftables:<EOL><INDENT>currentlevel[group].append(_dict())<EOL><DEDENT>else:<EOL><INDENT>raise TomlDecodeError("<STR_LIT>" + group +<EOL>"<STR_LIT>" +<EOL>str(currentlevel))<EOL><DEDENT><DEDENT><DEDENT>except TypeError:<EOL><INDENT>currentlevel = currentlevel[-<NUM_LIT:1>]<EOL>try:<EOL><INDENT>currentlevel[group]<EOL><DEDENT>except KeyError:<EOL><INDENT>currentlevel[group] = _dict()<EOL>if i == len(groups) - <NUM_LIT:1> and arrayoftables:<EOL><INDENT>currentlevel[group] = [_dict()]<EOL><DEDENT><DEDENT><DEDENT>except KeyError:<EOL><INDENT>if i != len(groups) - <NUM_LIT:1>:<EOL><INDENT>implicitgroups.append(group)<EOL><DEDENT>currentlevel[group] = _dict()<EOL>if i == len(groups) - <NUM_LIT:1> and arrayoftables:<EOL><INDENT>currentlevel[group] = [_dict()]<EOL><DEDENT><DEDENT>currentlevel = currentlevel[group]<EOL>if arrayoftables:<EOL><INDENT>try:<EOL><INDENT>currentlevel = currentlevel[-<NUM_LIT:1>]<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT><DEDENT>elif line[<NUM_LIT:0>] == "<STR_LIT:{>":<EOL><INDENT>if line[-<NUM_LIT:1>] != "<STR_LIT:}>":<EOL><INDENT>raise TomlDecodeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>_load_inline_object(line, currentlevel, _dict, multikey,<EOL>multibackslash)<EOL><DEDENT>elif "<STR_LIT:=>" in line:<EOL><INDENT>ret = _load_line(line, currentlevel, _dict, multikey,<EOL>multibackslash)<EOL>if ret is not None:<EOL><INDENT>multikey, multilinestr, multibackslash = ret<EOL><DEDENT><DEDENT><DEDENT>return retval<EOL>
Parses string as toml

    Args:
        s: String to be parsed
        _dict: (optional) Specifies the class of the returned toml dictionary

    Returns:
        Parsed toml file represented as a dictionary

    Raises:
        TypeError: When a non-string is passed
        TomlDecodeError: Error while decoding toml