# Path: datapackage_pipelines/utilities/resources.py
# PATH_PLACEHOLDER = '_'
# 
# def streaming(descriptor):
#     return descriptor.get(PROP_STREAMING)
# 
# Path: datapackage_pipelines/utilities/extended_json.py
# class json(object):
#     dumps = _dumps
#     loads = _loads
#     dumpl = _dumpl
#     loadl = _loadl
#     dump = _dump
#     load = _load
#     JSONDecodeError = _json.JSONDecodeError


import sys
import copy
import logging
import datapackage
from tableschema.exceptions import ValidationError, CastError
from tableschema import Schema
from ..utilities.resources import PATH_PLACEHOLDER, streaming
from ..utilities.extended_json import json




class ResourceIterator(object):

    def __init__(self, infile, spec, orig_spec,
                 validate=False, debug=False):
        self.spec = spec
        self.table_schema = Schema(orig_spec['schema'])
        self.field_names = [f['name'] for f in orig_spec['schema']['fields']]
        self.validate = validate
        self.infile = infile
        self.debug = debug
        self.stopped = False

    def __iter__(self):
        return self

    def __next__(self):
        if self.stopped:
            raise StopIteration()
        if self.debug:
            logging.error('WAITING')
        line = self.infile.readline().strip()
        if self.debug:
            logging.error('INGESTING: %r', line)
        if line == '':
            self.stopped = True
            raise StopIteration()

# Path: datapackage_pipelines/utilities/resources.py
# PATH_PLACEHOLDER = '_'
# 
# def streaming(descriptor):
#     return descriptor.get(PROP_STREAMING)
# 
# Path: datapackage_pipelines/utilities/extended_json.py
# class json(object):
#     dumps = _dumps
#     loads = _loads
#     dumpl = _dumpl
#     loadl = _loadl
#     dump = _dump
#     load = _load
#     JSONDecodeError = _json.JSONDecodeError


# Path: datapackage_pipelines/wrapper/input_processor.py
import sys
import copy
import logging
import datapackage
from tableschema.exceptions import ValidationError, CastError
from tableschema import Schema
from ..utilities.resources import PATH_PLACEHOLDER, streaming
from ..utilities.extended_json import json





class ResourceIterator(object):

    def __init__(self, infile, spec, orig_spec,
                 validate=False, debug=False):
        self.spec = spec
        self.table_schema = Schema(orig_spec['schema'])
        self.field_names = [f['name'] for f in orig_spec['schema']['fields']]
        self.validate = validate
        self.infile = infile
        self.debug = debug
        self.stopped = False

    def __iter__(self):
        return self

    def __next__(self):
        if self.stopped:
            raise StopIteration()
        if self.debug:
            logging.error('WAITING')
        line = self.infile.readline().strip()
        if self.debug:
            logging.error('INGESTING: %r', line)
        if line == '':
            self.stopped = True
            raise StopIteration()

        line = json.loadl(line)