
import os
import sys
import json
import yaml


def handle(data, **parms):
  def yaml2json(ydata):
    """
    Convert YAML to JSON (output: JSON)
    """
    try:
      d = yaml.load(ydata, Loader=yaml.BaseLoader)
    except Exception as e:
      d = {'error': '{}'.format(e)}

    return json.dumps(d)


  def json2yaml(jdata):
    """
    Convert JSON to YAML (output: YAML)
    """
    try:
      d = json.loads(jdata)
    except Exception as e:
      d = {'error': '{}'.format(e)}

    return yaml.dump(d, default_flow_style=False)


  if parms.get('reverse') == 'true':
    print(json2yaml(data))
  else:
    print(yaml2json(data))


import os
import sys
import json
import yaml


def yaml2json(data):
  """
  Convert YAML to JSON (output: JSON)
  """
  try:
    d = yaml.load(data, Loader=yaml.BaseLoader)
  except Exception as e:
    d = {'error': '{}'.format(e)}

  return json.dumps(d)


def json2yaml(data):
  """
  Convert JSON to YAML (output: YAML)
  """
  try:
    d = json.loads(data)
  except Exception as e:
    d = {'error': '{}'.format(e)}

  return yaml.dump(d, default_flow_style=False)


def handle(data, **parms):
  if parms.get('reverse') == 'true':
    print(json2yaml(data))
  else:
    print(yaml2json(data))

Make handle function to behave similar as main function
Make handle function to behave similar as main function

  
  import os
  import sys
  import json
  import yaml
  
  
- def handle(data, **parms):
-   def yaml2json(ydata):
+ def yaml2json(data):
-     """
+   """
-     Convert YAML to JSON (output: JSON)
+   Convert YAML to JSON (output: JSON)
-     """
+   """
-     try:
+   try:
-       d = yaml.load(ydata, Loader=yaml.BaseLoader)
+     d = yaml.load(data, Loader=yaml.BaseLoader)
-     except Exception as e:
+   except Exception as e:
-       d = {'error': '{}'.format(e)}
+     d = {'error': '{}'.format(e)}
  
-     return json.dumps(d)
+   return json.dumps(d)
  
  
-   def json2yaml(jdata):
+ def json2yaml(data):
-     """
+   """
-     Convert JSON to YAML (output: YAML)
+   Convert JSON to YAML (output: YAML)
-     """
+   """
-     try:
+   try:
-       d = json.loads(jdata)
+     d = json.loads(data)
-     except Exception as e:
+   except Exception as e:
-       d = {'error': '{}'.format(e)}
+     d = {'error': '{}'.format(e)}
  
-     return yaml.dump(d, default_flow_style=False)
+   return yaml.dump(d, default_flow_style=False)
  
  
+ def handle(data, **parms):
    if parms.get('reverse') == 'true':
      print(json2yaml(data))
    else:
      print(yaml2json(data))
  
Make handle function to behave similar as main function
## Code Before:

import os
import sys
import json
import yaml


def handle(data, **parms):
  def yaml2json(ydata):
    """
    Convert YAML to JSON (output: JSON)
    """
    try:
      d = yaml.load(ydata, Loader=yaml.BaseLoader)
    except Exception as e:
      d = {'error': '{}'.format(e)}

    return json.dumps(d)


  def json2yaml(jdata):
    """
    Convert JSON to YAML (output: YAML)
    """
    try:
      d = json.loads(jdata)
    except Exception as e:
      d = {'error': '{}'.format(e)}

    return yaml.dump(d, default_flow_style=False)


  if parms.get('reverse') == 'true':
    print(json2yaml(data))
  else:
    print(yaml2json(data))

## Instruction:
Make handle function to behave similar as main function
## Code After:

import os
import sys
import json
import yaml


def yaml2json(data):
  """
  Convert YAML to JSON (output: JSON)
  """
  try:
    d = yaml.load(data, Loader=yaml.BaseLoader)
  except Exception as e:
    d = {'error': '{}'.format(e)}

  return json.dumps(d)


def json2yaml(data):
  """
  Convert JSON to YAML (output: YAML)
  """
  try:
    d = json.loads(data)
  except Exception as e:
    d = {'error': '{}'.format(e)}

  return yaml.dump(d, default_flow_style=False)


def handle(data, **parms):
  if parms.get('reverse') == 'true':
    print(json2yaml(data))
  else:
    print(yaml2json(data))
