original_docstring: Convert HOCON input into a HOCON output
  
      :return: HOCON string representation
      :type return: basestring
      
docstring: Convert HOCON input into a HOCON output
docstring_tokens: Convert HOCON input into a HOCON output
code: def to_hocon(config, compact=False, indent=2, level=0):
      """Convert HOCON input into a HOCON output
  
      :return: HOCON string representation
      :type return: basestring
      """
      lines = ""
      if isinstance(config, ConfigTree):
          if len(config) == 0:
              lines += "{}"
          else:
              if level > 0:  # don't display { at root level
                  lines += "{\n"
              bet_lines = []
  
              for key, item in config.items():
                  if compact:
                      full_key = key
                      while isinstance(item, ConfigTree) and len(item) == 1:
                          key, item = next(iter(item.items()))
                          full_key += "." + key
                  else:
                      full_key = key
  
                  if not re.match(r"^[a-zA-Z0-9._\- /]+$", full_key):
                      full_key = json.dumps(full_key, ensure_ascii=False)
                  bet_lines.append(
                      "{indent}{key}{assign_sign} {value}".format(
                          indent="".rjust(level * indent, " "),
                          key=full_key,
                          assign_sign="" if isinstance(item, dict) else " =",
                          value=to_hocon(item, compact, indent, level + 1),
                      )
                  )
              lines += "\n".join(bet_lines)
  
              if level > 0:  # don't display { at root level
                  lines += "\n{indent}}}".format(
                      indent="".rjust((level - 1) * indent, " ")
                  )
      elif isinstance(config, list):
          if len(config) == 0:
              lines += "[]"
          else:
              simple = True
              for item in config:
                  if not isinstance(item, (basestring, int, float, bool)):
                      simple = False
                      break
              if simple:
                  cur_line = "["
                  items = [to_hocon(item, compact, 0, level + 1) for item in config]
                  cur_line += ", ".join(items)
                  cur_line += "]".format(indent="".rjust((level - 1) * indent, " "))
                  if indent + len(cur_line) > 80:
                      simple = False
                  else:
                      lines += cur_line
              if not simple:
                  lines += "[\n"
                  bet_lines = []
                  for item in config:
                      bet_lines.append(
                          "{indent}{value}".format(
                              indent="".rjust(level * indent, " "),
                              value=to_hocon(item, compact, indent, level + 1),
                          )
                      )
                  lines += "\n".join(bet_lines)
                  lines += "\n{indent}]".format(
                      indent="".rjust((level - 1) * indent, " ")
                  )
      elif isinstance(config, basestring):
          if "\n" in config:
              lines = '"""{value}"""'.format(value=config.replace('"""', '\\"""'))  # multilines
          else:
              lines = json.dumps(config, ensure_ascii=False)
      elif isinstance(config, ConfigValues):
          lines = "".join(to_hocon(o, compact, indent, level) for o in config.tokens)
      elif isinstance(config, ConfigSubstitution):
          lines = "${"
          if config.optional:
              lines += "?"
          lines += config.variable + "}" + config.ws
      elif isinstance(config, ConfigQuotedString):
          if "\n" in config.value:
              lines = '"""{value}"""'.format(value=config.value)  # multilines
          else:
              lines = '"{value}"'.format(
                  value=config.value.replace("\n", "\\n").replace('"', '\\"')
              )
      elif config is None or isinstance(config, NoneValue):
          lines = "null"
      elif config is True:
          lines = "true"
      elif config is False:
          lines = "false"
      else:
          lines = str(config)
      return lines
code_tokens: def to_hocon ( config , compact = False , indent = 2 , level = 0 ) : lines = "" if isinstance ( config , ConfigTree ) : if len ( config ) == 0 : lines += "{}" else : if level > 0 : lines += "{\n" bet_lines = [ ] for key , item in config . items ( ) : if compact : full_key = key while isinstance ( item , ConfigTree ) and len ( item ) == 1 : key , item = next ( iter ( item . items ( ) ) ) full_key += "." + key else : full_key = key if not re . match ( r"^[a-zA-Z0-9._\- /]+$" , full_key ) : full_key = json . dumps ( full_key , ensure_ascii = False ) bet_lines . append ( "{indent}{key}{assign_sign} {value}" . format ( indent = "" . rjust ( level * indent , " " ) , key = full_key , assign_sign = "" if isinstance ( item , dict ) else " =" , value = to_hocon ( item , compact , indent , level + 1 ) , ) ) lines += "\n" . join ( bet_lines ) if level > 0 : lines += "\n{indent}}}" . format ( indent = "" . rjust ( ( level - 1 ) * indent , " " ) ) elif isinstance ( config , list ) : if len ( config ) == 0 : lines += "[]" else : simple = True for item in config : if not isinstance ( item , ( basestring , int , float , bool ) ) : simple = False break if simple : cur_line = "[" items = [ to_hocon ( item , compact , 0 , level + 1 ) for item in config ] cur_line += ", " . join ( items ) cur_line += "]" . format ( indent = "" . rjust ( ( level - 1 ) * indent , " " ) ) if indent + len ( cur_line ) > 80 : simple = False else : lines += cur_line if not simple : lines += "[\n" bet_lines = [ ] for item in config : bet_lines . append ( "{indent}{value}" . format ( indent = "" . rjust ( level * indent , " " ) , value = to_hocon ( item , compact , indent , level + 1 ) , ) ) lines += "\n" . join ( bet_lines ) lines += "\n{indent}]" . format ( indent = "" . rjust ( ( level - 1 ) * indent , " " ) ) elif isinstance ( config , basestring ) : if "\n" in config : lines = '"""{value}"""' . format ( value = config . replace ( '"""' , '\\"""' ) ) else : lines = json . dumps ( config , ensure_ascii = False ) elif isinstance ( config , ConfigValues ) : lines = "" . join ( to_hocon ( o , compact , indent , level ) for o in config . tokens ) elif isinstance ( config , ConfigSubstitution ) : lines = "${" if config . optional : lines += "?" lines += config . variable + "}" + config . ws elif isinstance ( config , ConfigQuotedString ) : if "\n" in config . value : lines = '"""{value}"""' . format ( value = config . value ) else : lines = '"{value}"' . format ( value = config . value . replace ( "\n" , "\\n" ) . replace ( '"' , '\\"' ) ) elif config is None or isinstance ( config , NoneValue ) : lines = "null" elif config is True : lines = "true" elif config is False : lines = "false" else : lines = str ( config ) return lines
short_docstring: Convert HOCON input into a HOCON output
short_docstring_tokens: Convert HOCON input into a HOCON output
comment: """Convert HOCON input into a HOCON output
  
      :return: HOCON string representation
      :type return: basestring
      """$SEP$# don't display { at root level$SEP$# don't display { at root level$SEP$# multilines$SEP$# multilines