Beispiel #1
0
    def __bool__(self):
        try:
            NEXT(self.iteritems())()
            return True
        except Exception:
            pass

        try:
            NEXT(self.__iter__())()
            return True
        except Exception:
            return False
    def __init__(self, json, query_path, expected_vars=NO_VARS):

        if hasattr(json, "read"):
            # ASSUME IT IS A STREAM
            temp = json

            def get_more():
                return temp.read(MIN_READ_SIZE)

            self.json = List_usingStream(get_more)
        elif hasattr(json, "__call__"):
            self.json = List_usingStream(json)
        elif isinstance(json, GeneratorType):
            self.json = List_usingStream(NEXT(json))
        else:
            Log.error(
                "Expecting json to be a stream, or a function that will return more bytes"
            )

        if is_data(query_path) and query_path.get("items"):
            self.path_list = split_field(query_path.get("items")) + [
                "$items"
            ]  # INSERT A MARKER SO THAT OBJECT IS STREAM DECODED
        else:
            self.path_list = split_field(query_path)

        self.expected_vars = expected_vars
        self.destination = [None] * len(expected_vars)
        self.done = [self.path_list + [None]]
Beispiel #3
0
    def _gen_ids(self):
        def output():
            while True:
                with self.db.transaction() as t:
                    top_id = first(
                        first(
                            t.query(SQL_SELECT + quote_column("next_id") +
                                    SQL_FROM +
                                    quote_column(ABOUT_TABLE)).data))
                    max_id = top_id + 1000
                    t.execute(SQL_UPDATE + quote_column(ABOUT_TABLE) +
                              SQL_SET + sql_eq(next_id=max_id))
                while top_id < max_id:
                    yield top_id
                    top_id += 1

        return NEXT(output())