# Path: datapackage_pipelines/wrapper/wrapper.py
# class ProcessorContext(ExitStack):
# 
#     def __init__(self, parameters, datapackage, resource_iterator):
#         super().__init__()
#         self.parameters = parameters
#         self.datapackage = datapackage
#         self.resource_iterator = resource_iterator
#         self.stats = {}
# 
#     def __iter__(self):
#         return iter((self.parameters, self.datapackage, self.resource_iterator))
# 
#     def __enter__(self):
#         super().__enter__()
#         self.enter_context(redirect_stdout(StdoutWriter()))
#         self.enter_context(redirect_stderr(StderrWriter()))
#         return self
# 
#     def __exit__(self, *args, **kw):
#         spew(self.datapackage, self.resource_iterator, stats=self.stats)
#         super().__exit__(*args, **kw)
# 
# Path: datapackage_pipelines/utilities/extended_json.py
# class LazyJsonLine(LazyDict):
# 
#     def __init__(self, args, kwargs):
#         super().__init__()
#         self.line = args[0]
#         self.args = args
#         self.kwargs = kwargs
# 
#     def _evaluate(self):
#         return json.loads(*self.args, **self.kwargs)
# 
#     def __str__(self):
#         if self.inner is not None:
#             return str(self.inner)
#         return self.line
# 
#     def __repr__(self):
#         if self.inner is not None:
#             return repr(self.inner)
#         return self.line


from dataflows import Flow, load, update_package
from dataflows.helpers.resource_matcher import ResourceMatcher
from datapackage_pipelines.wrapper import ProcessorContext
from datapackage_pipelines.utilities.extended_json import LazyJsonLine



def load_lazy_json(resources):

    def func(package):
        matcher = ResourceMatcher(resources, package.pkg)
        yield package.pkg
        for rows in package:
            if matcher.match(rows.res.name):
                yield (
                    row.inner

# Path: datapackage_pipelines/wrapper/wrapper.py
# class ProcessorContext(ExitStack):
# 
#     def __init__(self, parameters, datapackage, resource_iterator):
#         super().__init__()
#         self.parameters = parameters
#         self.datapackage = datapackage
#         self.resource_iterator = resource_iterator
#         self.stats = {}
# 
#     def __iter__(self):
#         return iter((self.parameters, self.datapackage, self.resource_iterator))
# 
#     def __enter__(self):
#         super().__enter__()
#         self.enter_context(redirect_stdout(StdoutWriter()))
#         self.enter_context(redirect_stderr(StderrWriter()))
#         return self
# 
#     def __exit__(self, *args, **kw):
#         spew(self.datapackage, self.resource_iterator, stats=self.stats)
#         super().__exit__(*args, **kw)
# 
# Path: datapackage_pipelines/utilities/extended_json.py
# class LazyJsonLine(LazyDict):
# 
#     def __init__(self, args, kwargs):
#         super().__init__()
#         self.line = args[0]
#         self.args = args
#         self.kwargs = kwargs
# 
#     def _evaluate(self):
#         return json.loads(*self.args, **self.kwargs)
# 
#     def __str__(self):
#         if self.inner is not None:
#             return str(self.inner)
#         return self.line
# 
#     def __repr__(self):
#         if self.inner is not None:
#             return repr(self.inner)
#         return self.line


# Path: datapackage_pipelines/utilities/flow_utils.py
from dataflows import Flow, load, update_package
from dataflows.helpers.resource_matcher import ResourceMatcher
from datapackage_pipelines.wrapper import ProcessorContext
from datapackage_pipelines.utilities.extended_json import LazyJsonLine




def load_lazy_json(resources):

    def func(package):
        matcher = ResourceMatcher(resources, package.pkg)
        yield package.pkg
        for rows in package:
            if matcher.match(rows.res.name):
                yield (
                    row.inner

                    if isinstance(row, LazyJsonLine)