code: def loads(s, _dict=dict, decoder=None):
      """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
      """
  
      implicitgroups = []
      if decoder is None:
          decoder = TomlDecoder(_dict)
      retval = decoder.get_empty_table()
      currentlevel = retval
      if not isinstance(s, basestring):
          raise TypeError("Expecting something like a string")
  
      if not isinstance(s, unicode):
          s = s.decode("utf8")
  
      original = s
      sl = list(s)
      openarr = 0
      openstring = False
      openstrchar = ""
      multilinestr = False
      arrayoftables = False
      beginline = True
      keygroup = False
      dottedkey = False
      keyname = 0
      key = ""
      prev_key = ""
      line_no = 1
  
      for i, item in enumerate(sl):
          if item == "\r" and sl[i + 1] == "\n":
              sl[i] = " "
              continue
          if keyname:
              key += item
              if item == "\n":
                  raise TomlDecodeError(
                      "Key name found without value."
                      " Reached end of line.",
                      original,
                      i,
                  )
              if openstring:
                  if item == openstrchar:
                      oddbackslash = False
                      k = 1
                      while i >= k and sl[i - k] == "\\":
                          oddbackslash = not oddbackslash
                          k += 1
                      if not oddbackslash:
                          keyname = 2
                          openstring = False
                          openstrchar = ""
                  continue
              elif keyname == 1:
                  if item.isspace():
                      keyname = 2
                      continue
                  elif item == ".":
                      dottedkey = True
                      continue
                  elif item.isalnum() or item == "_" or item == "-":
                      continue
                  elif (
                      dottedkey
                      and sl[i - 1] == "."
                      and (item == '"' or item == "'")
                  ):
                      openstring = True
                      openstrchar = item
                      continue
              elif keyname == 2:
                  if item.isspace():
                      if dottedkey:
                          nextitem = sl[i + 1]
                          if not nextitem.isspace() and nextitem != ".":
                              keyname = 1
                      continue
                  if item == ".":
                      dottedkey = True
                      nextitem = sl[i + 1]
                      if not nextitem.isspace() and nextitem != ".":
                          keyname = 1
                      continue
              if item == "=":
                  keyname = 0
                  prev_key = key[:-1].rstrip()
                  key = ""
                  dottedkey = False
              else:
                  raise TomlDecodeError(
                      "Found invalid character in key name: '"
                      + item
                      + "'. Try quoting the key name.",
                      original,
                      i,
                  )
          if item == "'" and openstrchar != '"':
              k = 1
              try:
                  while sl[i - k] == "'":
                      k += 1
                      if k == 3:
                          break
              except IndexError:
                  pass
              if k == 3:
                  multilinestr = not multilinestr
                  openstring = multilinestr
              else:
                  openstring = not openstring
              if openstring:
                  openstrchar = "'"
              else:
                  openstrchar = ""
          if item == '"' and openstrchar != "'":
              oddbackslash = False
              k = 1
              tripquote = False
              try:
                  while sl[i - k] == '"':
                      k += 1
                      if k == 3:
                          tripquote = True
                          break
                  if k == 1 or (k == 3 and tripquote):
                      while sl[i - k] == "\\":
                          oddbackslash = not oddbackslash
                          k += 1
              except IndexError:
                  pass
              if not oddbackslash:
                  if tripquote:
                      multilinestr = not multilinestr
                      openstring = multilinestr
                  else:
                      openstring = not openstring
              if openstring:
                  openstrchar = '"'
              else:
                  openstrchar = ""
          if item == "#" and (
              not openstring and not keygroup and not arrayoftables
          ):
              j = i
              comment = ""
              try:
                  while sl[j] != "\n":
                      comment += s[j]
                      sl[j] = " "
                      j += 1
              except IndexError:
                  break
              if not openarr:
                  decoder.preserve_comment(
                      line_no, prev_key, comment, beginline
                  )
          if item == "[" and (
              not openstring and not keygroup and not arrayoftables
          ):
              if beginline:
                  if len(sl) > i + 1 and sl[i + 1] == "[":
                      arrayoftables = True
                  else:
                      keygroup = True
              else:
                  openarr += 1
          if item == "]" and not openstring:
              if keygroup:
                  keygroup = False
              elif arrayoftables:
                  if sl[i - 1] == "]":
                      arrayoftables = False
              else:
                  openarr -= 1
          if item == "\n":
              if openstring or multilinestr:
                  if not multilinestr:
                      raise TomlDecodeError(
                          "Unbalanced quotes", original, i
                      )
                  if (sl[i - 1] == "'" or sl[i - 1] == '"') and (
                      sl[i - 2] == sl[i - 1]
                  ):
                      sl[i] = sl[i - 1]
                      if sl[i - 3] == sl[i - 1]:
                          sl[i - 3] = " "
              elif openarr:
                  sl[i] = " "
              else:
                  beginline = True
              line_no += 1
          elif beginline and sl[i] != " " and sl[i] != "\t":
              beginline = False
              if not keygroup and not arrayoftables:
                  if sl[i] == "=":
                      raise TomlDecodeError(
                          "Found empty keyname. ", original, i
                      )
                  keyname = 1
                  key += item
      if keyname:
          raise TomlDecodeError(
              "Key name found without value." " Reached end of file.",
              original,
              len(s),
          )
      if openstring:  # reached EOF and have an unterminated string
          raise TomlDecodeError(
              "Unterminated string found." " Reached end of file.",
              original,
              len(s),
          )
      s = "".join(sl)
      s = s.split("\n")
      multikey = None
      multilinestr = ""
      multibackslash = False
      pos = 0
      for idx, line in enumerate(s):
          if idx > 0:
              pos += len(s[idx - 1]) + 1
  
          decoder.embed_comments(idx, currentlevel)
  
          if (
              not multilinestr
              or multibackslash
              or "\n" not in multilinestr
          ):
              line = line.strip()
          if line == "" and (not multikey or multibackslash):
              continue
          if multikey:
              if multibackslash:
                  multilinestr += line
              else:
                  multilinestr += line
              multibackslash = False
              closed = False
              if multilinestr[0] == "[":
                  closed = line[-1] == "]"
              elif len(line) > 2:
                  closed = (
                      line[-1] == multilinestr[0]
                      and line[-2] == multilinestr[0]
                      and line[-3] == multilinestr[0]
                  )
              if closed:
                  try:
                      value, vtype = decoder.load_value(multilinestr)
                  except ValueError as err:
                      raise TomlDecodeError(str(err), original, pos)
                  currentlevel[multikey] = value
                  multikey = None
                  multilinestr = ""
              else:
                  k = len(multilinestr) - 1
                  while k > -1 and multilinestr[k] == "\\":
                      multibackslash = not multibackslash
                      k -= 1
                  if multibackslash:
                      multilinestr = multilinestr[:-1]
                  else:
                      multilinestr += "\n"
              continue
          if line[0] == "[":
              arrayoftables = False
              if len(line) == 1:
                  raise TomlDecodeError(
                      "Opening key group bracket on line by " "itself.",
                      original,
                      pos,
                  )
              if line[1] == "[":
                  arrayoftables = True
                  line = line[2:]
                  splitstr = "]]"
              else:
                  line = line[1:]
                  splitstr = "]"
              i = 1
              quotesplits = decoder._get_split_on_quotes(line)
              quoted = False
              for quotesplit in quotesplits:
                  if not quoted and splitstr in quotesplit:
                      break
                  i += quotesplit.count(splitstr)
                  quoted = not quoted
              line = line.split(splitstr, i)
              if len(line) < i + 1 or line[-1].strip() != "":
                  raise TomlDecodeError(
                      "Key group not on a line by itself.",
                      original,
                      pos,
                  )
              groups = splitstr.join(line[:-1]).split(".")
              i = 0
              while i < len(groups):
                  groups[i] = groups[i].strip()
                  if len(groups[i]) > 0 and (
                      groups[i][0] == '"' or groups[i][0] == "'"
                  ):
                      groupstr = groups[i]
                      j = i + 1
                      while (not groupstr[0] == groupstr[-1]) or len(
                          groupstr
                      ) == 1:
                          j += 1
                          if j > len(groups) + 2:
                              raise TomlDecodeError(
                                  "Invalid group name '"
                                  + groupstr
                                  + "' Something "
                                  + "went wrong.",
                                  original,
                                  pos,
                              )
                          groupstr = ".".join(groups[i:j]).strip()
                      groups[i] = groupstr[1:-1]
                      groups[i + 1 : j] = []
                  else:
                      if not _groupname_re.match(groups[i]):
                          raise TomlDecodeError(
                              "Invalid group name '"
                              + groups[i]
                              + "'. Try quoting it.",
                              original,
                              pos,
                          )
                  i += 1
              currentlevel = retval
              for i in _range(len(groups)):
                  group = groups[i]
                  if group == "":
                      raise TomlDecodeError(
                          "Can't have a keygroup with an empty " "name",
                          original,
                          pos,
                      )
                  try:
                      currentlevel[group]
                      if i == len(groups) - 1:
                          if group in implicitgroups:
                              implicitgroups.remove(group)
                              if arrayoftables:
                                  raise TomlDecodeError(
                                      "An implicitly defined "
                                      "table can't be an array",
                                      original,
                                      pos,
                                  )
                          elif arrayoftables:
                              currentlevel[group].append(
                                  decoder.get_empty_table()
                              )
                          else:
                              raise TomlDecodeError(
                                  "What? "
                                  + group
                                  + " already exists?"
                                  + str(currentlevel),
                                  original,
                                  pos,
                              )
                  except TypeError:
                      currentlevel = currentlevel[-1]
                      if group not in currentlevel:
                          currentlevel[
                              group
                          ] = decoder.get_empty_table()
                          if i == len(groups) - 1 and arrayoftables:
                              currentlevel[group] = [
                                  decoder.get_empty_table()
                              ]
                  except KeyError:
                      if i != len(groups) - 1:
                          implicitgroups.append(group)
                      currentlevel[group] = decoder.get_empty_table()
                      if i == len(groups) - 1 and arrayoftables:
                          currentlevel[group] = [
                              decoder.get_empty_table()
                          ]
                  currentlevel = currentlevel[group]
                  if arrayoftables:
                      try:
                          currentlevel = currentlevel[-1]
                      except KeyError:
                          pass
          elif line[0] == "{":
              if line[-1] != "}":
                  raise TomlDecodeError(
                      "Line breaks are not allowed in inline" "objects",
                      original,
                      pos,
                  )
              try:
                  decoder.load_inline_object(
                      line, currentlevel, multikey, multibackslash
                  )
              except ValueError as err:
                  raise TomlDecodeError(str(err), original, pos)
          elif "=" in line:
              try:
                  ret = decoder.load_line(
                      line, currentlevel, multikey, multibackslash
                  )
              except ValueError as err:
                  raise TomlDecodeError(str(err), original, pos)
              if ret is not None:
                  multikey, multilinestr, multibackslash = ret
      return retval
  
imports: import datetime
  import io
  from os import linesep
  import re
  import sys
  from toml.tz import TomlTz
label_desc: Use image node_id 6 for calling a global function with example usage: loads(s, _dict, decoder) and returns: retval