コード例 #1
0
    def fetch_raw(self, max_recv=1, **kw):
        """
        Fetch the records for this query. This is a single fetch that will
        return results max_recv number of iterations. A recv is defined as a
        result returned that has records in the batch (versus fetch update
        information). By default, the fetch will abort after the first set
        of results are returned. 
        
        This fetch should be used if you want to return only the result records
        returned from the query in raw dict format. Any other dict key/values
        from the raw query are ignored.
        
        :param int sock_timeout: event loop interval
        :param int max_recv: max number of socket receive calls before
            returning from this query. If you want to wait longer for
            results before returning, increase max_iterations (default: 1)
        :return: list of query results
        :rtype: list(dict)
        """
        iteration = 0
        with SMCSocketProtocol(self, **self.sockopt) as protocol:
            for result in protocol.receive():
                if 'records' in result and result['records'].get('added'):
                    yield result['records']['added']
                    iteration += 1

                if iteration == max_recv:
                    protocol.abort()
コード例 #2
0
 def execute(self):
     """
     Execute the query with optional timeout. The response to the execute
     query is the raw payload received from the websocket and will contain
     multiple dict keys and values. It is more common to call query.fetch_XXX
     which will filter the return result based on the method. Each result set
     will have a max batch size of 200 records. This method will also
     continuously return results until terminated. To make a single bounded
     fetch, call :meth:`.fetch_batch` or :meth:`.fetch_raw`.
     
     :param int sock_timeout: event loop interval
     :return: raw dict returned from query
     :rtype: dict(list)
     """
     with SMCSocketProtocol(self, **self.sockopt) as protocol:
         for result in protocol.receive():
             yield result
コード例 #3
0
 def fetch_raw(self, **kw):
     """
     Fetch the records for this query. This fetch type will return the
     results in raw dict format. It is possible to limit the number of
     receives on the socket that return results before exiting by providing
     max_recv.
     
     This fetch should be used if you want to return only the result records
     returned from the query in raw dict format. Any other dict key/values
     from the raw query are ignored.
     
     :param int max_recv: max number of socket receive calls before
         returning from this query. If you want to wait longer for
         results before returning, increase max_iterations (default: 0)
     :return: list of query results
     :rtype: list(dict)
     """
     self.sockopt.update(kw)
     with SMCSocketProtocol(self, **self.sockopt) as protocol:
         for result in protocol.receive():
             if 'records' in result and result['records'].get('added'):
                 yield result['records']['added']
コード例 #4
0
 def run_forever(self):
     with SMCSocketProtocol(self, **self.sockopt) as sock:
         for subscription in self.subscriptions:
             sock.send_message(subscription)
         for result in sock.receive():
             yield result