# Path: kibitzr/transformer/utils.py
# def wrap_dummy(transform_func):
#     def transform_factory(value, conf):
#         return transform_func
#     return transform_factory
# 
# def bake_parametrized(transform_func, pass_conf=False, **kwargs):
#     def transform_factory(value, conf):
#         if pass_conf:
#             return functools.partial(
#                 transform_func,
#                 value,
#                 conf=conf,
#                 **kwargs
#             )
#         else:
#             return functools.partial(
#                 transform_func,
#                 value,
#                 **kwargs
#             )
#     return transform_factory


import json
import logging
from .utils import wrap_dummy, bake_parametrized
    from kibitzr.compat import sh
        sort_keys=True,
        ensure_ascii=False,
        # encoding='utf-8',
    )
    return True, u'\n'.join([
        line.rstrip()
        for line in json_dump.splitlines()
    ])


def run_jq(query, text):
    jq = sh.Command("jq").bake('--monochrome-output', '--raw-output')
    logger.debug("Running jq query %s against %s", query, text)
    try:
        command = jq(query, _in=text)
        if not command.stderr:
            success, result = True, command.stdout.decode('utf-8')
        else:
            success, result = False, command.stderr.decode('utf-8')
    except sh.ErrorReturnCode as exc:
        logger.exception("jq failure")
        success, result = False, exc.stderr
    logger.debug("jq transform success: %r, content: %r",
                 success, result)
    return success, result


def register():
    return {
        'json': wrap_dummy(pretty_json),

# Path: kibitzr/transformer/utils.py
# def wrap_dummy(transform_func):
#     def transform_factory(value, conf):
#         return transform_func
#     return transform_factory
# 
# def bake_parametrized(transform_func, pass_conf=False, **kwargs):
#     def transform_factory(value, conf):
#         if pass_conf:
#             return functools.partial(
#                 transform_func,
#                 value,
#                 conf=conf,
#                 **kwargs
#             )
#         else:
#             return functools.partial(
#                 transform_func,
#                 value,
#                 **kwargs
#             )
#     return transform_factory


# Path: kibitzr/transformer/json_transforms.py
import json
import logging
from .utils import wrap_dummy, bake_parametrized
    from kibitzr.compat import sh

        sort_keys=True,
        ensure_ascii=False,
        # encoding='utf-8',
    )
    return True, u'\n'.join([
        line.rstrip()
        for line in json_dump.splitlines()
    ])


def run_jq(query, text):
    jq = sh.Command("jq").bake('--monochrome-output', '--raw-output')
    logger.debug("Running jq query %s against %s", query, text)
    try:
        command = jq(query, _in=text)
        if not command.stderr:
            success, result = True, command.stdout.decode('utf-8')
        else:
            success, result = False, command.stderr.decode('utf-8')
    except sh.ErrorReturnCode as exc:
        logger.exception("jq failure")
        success, result = False, exc.stderr
    logger.debug("jq transform success: %r, content: %r",
                 success, result)
    return success, result


def register():
    return {
        'json': wrap_dummy(pretty_json),

        'jq': bake_parametrized(run_jq),