
from .evaluator import Evaluator
from .parser import Parser


def parse(s, parser_opts=None, evaluator_opts=None):
    parser = Parser(**(parser_opts or {}))
    evaluator = Evaluator(**(evaluator_opts or {}))

    ast = parser.parse(s)
    return evaluator.evaluate(ast)


from json import dumps as json_dumps
from .evaluator import Evaluator
from .parser import Parser


def parse(s, json=True, parser_opts=None, evaluator_opts=None):
    parser = Parser(**(parser_opts or {}))
    evaluator = Evaluator(**(evaluator_opts or {}))

    ast = parser.parse(s)
    raw = evaluator.evaluate(ast)

    if json and raw is not None:
        return json_dumps(raw)
    else:
        return raw

Return JSON from pypuppetdbquery.parse() by default
Return JSON from pypuppetdbquery.parse() by default

This will be the most useful mode of operation when combined with
pypuppetdb, so make life easy for people.

  
+ from json import dumps as json_dumps
  from .evaluator import Evaluator
  from .parser import Parser
  
  
- def parse(s, parser_opts=None, evaluator_opts=None):
+ def parse(s, json=True, parser_opts=None, evaluator_opts=None):
      parser = Parser(**(parser_opts or {}))
      evaluator = Evaluator(**(evaluator_opts or {}))
  
      ast = parser.parse(s)
-     return evaluator.evaluate(ast)
+     raw = evaluator.evaluate(ast)
  
+     if json and raw is not None:
+         return json_dumps(raw)
+     else:
+         return raw
+ 
Return JSON from pypuppetdbquery.parse() by default
## Code Before:

from .evaluator import Evaluator
from .parser import Parser


def parse(s, parser_opts=None, evaluator_opts=None):
    parser = Parser(**(parser_opts or {}))
    evaluator = Evaluator(**(evaluator_opts or {}))

    ast = parser.parse(s)
    return evaluator.evaluate(ast)

## Instruction:
Return JSON from pypuppetdbquery.parse() by default
## Code After:

from json import dumps as json_dumps
from .evaluator import Evaluator
from .parser import Parser


def parse(s, json=True, parser_opts=None, evaluator_opts=None):
    parser = Parser(**(parser_opts or {}))
    evaluator = Evaluator(**(evaluator_opts or {}))

    ast = parser.parse(s)
    raw = evaluator.evaluate(ast)

    if json and raw is not None:
        return json_dumps(raw)
    else:
        return raw
