nodes: 0, module; 1, function_definition; 2, function_name:to_list; 3, parameters; 4, block; 5, identifier:self; 6, identifier:length; 7, expression_statement; 8, if_statement; 9, if_statement; 10, expression_statement; 11, if_statement; 12, return_statement; 13, comment:"""Get a list of documents.
  
          .. testsetup:: to_list
  
            MongoClient().test.test_collection.delete_many({})
            MongoClient().test.test_collection.insert_many([{'_id': i} for i in range(4)])
  
            from tornado import ioloop
  
          .. doctest:: to_list
  
            >>> from motor.motor_tornado import MotorClient
            >>> collection = MotorClient().test.test_collection
            >>>
            >>> @gen.coroutine
            ... def f():
            ...     cursor = collection.find().sort([('_id', 1)])
            ...     docs = yield cursor.to_list(length=2)
            ...     while docs:
            ...         print(docs)
            ...         docs = yield cursor.to_list(length=2)
            ...
            ...     print('done')
            ...
            >>> ioloop.IOLoop.current().run_sync(f)
            [{'_id': 0}, {'_id': 1}]
            [{'_id': 2}, {'_id': 3}]
            done
  
          :Parameters:
           - `length`: maximum number of documents to return for this call, or
             None
  
           Returns a Future.
  
          .. versionchanged:: 2.0
             No longer accepts a callback argument.
  
          .. versionchanged:: 0.2
             `callback` must be passed as a keyword argument, like
             ``to_list(10, callback=callback)``, and the
             `length` parameter is no longer optional.
          """; 14, comparison_operator:length is not None; 15, block; 16, binary_operator:self._query_flags() & _QUERY_OPTIONS['tailable_cursor']; 17, block; 18, assignment; 19, not_operator; 20, block; 21, else_clause; 22, identifier:future; 23, identifier:length; 24, None; 25, if_statement; 26, call; 27, subscript; 28, raise_statement; 29, identifier:future; 30, call; 31, attribute; 32, expression_statement; 33, block; 34, not_operator; 35, block; 36, elif_clause; 37, attribute; 38, argument_list; 39, identifier:_QUERY_OPTIONS; 40, string; 41, call; 42, attribute; 43, argument_list; 44, identifier:self; 45, identifier:alive; 46, call; 47, expression_statement; 48, expression_statement; 49, call; 50, raise_statement; 51, comparison_operator:length < 0; 52, block; 53, identifier:self; 54, identifier:_query_flags; 55, string_content:tailable_cursor; 56, attribute; 57, argument_list; 58, attribute; 59, identifier:get_future; 60, call; 61, attribute; 62, argument_list; 63, assignment; 64, call; 65, identifier:isinstance; 66, argument_list; 67, call; 68, identifier:length; 69, integer:0; 70, raise_statement; 71, attribute; 72, identifier:InvalidOperation; 73, string:"Can't call to_list on tailable cursor"; 74, identifier:self; 75, identifier:_framework; 76, attribute; 77, argument_list; 78, identifier:future; 79, identifier:set_result; 80, list; 81, identifier:the_list; 82, list; 83, attribute; 84, argument_list; 85, identifier:length; 86, identifier:int; 87, identifier:TypeError; 88, argument_list; 89, call; 90, identifier:pymongo; 91, identifier:errors; 92, identifier:self; 93, identifier:get_io_loop; 94, attribute; 95, identifier:add_future; 96, call; 97, call; 98, attribute; 99, identifier:length; 100, identifier:the_list; 101, identifier:future; 102, binary_operator:'length must be an int, not %r' % length; 103, identifier:ValueError; 104, argument_list; 105, identifier:self; 106, identifier:_framework; 107, attribute; 108, argument_list; 109, attribute; 110, argument_list; 111, identifier:self; 112, identifier:_to_list; 113, string; 114, identifier:length; 115, string; 116, identifier:self; 117, identifier:get_io_loop; 118, identifier:self; 119, identifier:_get_more; 120, string_content:length must be an int, not %r; 121, string_content:length must be non-negative
code: def to_list(self, length):
          """Get a list of documents.
  
          .. testsetup:: to_list
  
            MongoClient().test.test_collection.delete_many({})
            MongoClient().test.test_collection.insert_many([{'_id': i} for i in range(4)])
  
            from tornado import ioloop
  
          .. doctest:: to_list
  
            >>> from motor.motor_tornado import MotorClient
            >>> collection = MotorClient().test.test_collection
            >>>
            >>> @gen.coroutine
            ... def f():
            ...     cursor = collection.find().sort([('_id', 1)])
            ...     docs = yield cursor.to_list(length=2)
            ...     while docs:
            ...         print(docs)
            ...         docs = yield cursor.to_list(length=2)
            ...
            ...     print('done')
            ...
            >>> ioloop.IOLoop.current().run_sync(f)
            [{'_id': 0}, {'_id': 1}]
            [{'_id': 2}, {'_id': 3}]
            done
  
          :Parameters:
           - `length`: maximum number of documents to return for this call, or
             None
  
           Returns a Future.
  
          .. versionchanged:: 2.0
             No longer accepts a callback argument.
  
          .. versionchanged:: 0.2
             `callback` must be passed as a keyword argument, like
             ``to_list(10, callback=callback)``, and the
             `length` parameter is no longer optional.
          """
          if length is not None:
              if not isinstance(length, int):
                  raise TypeError('length must be an int, not %r' % length)
              elif length < 0:
                  raise ValueError('length must be non-negative')
  
          if self._query_flags() & _QUERY_OPTIONS['tailable_cursor']:
              raise pymongo.errors.InvalidOperation(
                  "Can't call to_list on tailable cursor")
  
          future = self._framework.get_future(self.get_io_loop())
  
          if not self.alive:
              future.set_result([])
          else:
              the_list = []
              self._framework.add_future(
                  self.get_io_loop(),
                  self._get_more(),
                  self._to_list, length, the_list, future)
  
          return future