def cursor(self, function, return_pages=False, **params):
if not callable(function):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if not hasattr(function, '<STR_LIT>'):<EOL><INDENT>raise TwythonError('<STR_LIT>' % function.__name__)<EOL><DEDENT>while True:<EOL><INDENT>content = function(**params)<EOL>if not content:<EOL><INDENT>raise StopIteration<EOL><DEDENT>if hasattr(function, '<STR_LIT>'):<EOL><INDENT>results = content.get(function.iter_key)<EOL><DEDENT>else:<EOL><INDENT>results = content<EOL><DEDENT>if return_pages:<EOL><INDENT>yield results<EOL><DEDENT>else:<EOL><INDENT>for result in results:<EOL><INDENT>yield result<EOL><DEDENT><DEDENT>if function.iter_mode == '<STR_LIT>' andcontent['<STR_LIT>'] == '<STR_LIT:0>':<EOL><INDENT>raise StopIteration<EOL><DEDENT>try:<EOL><INDENT>if function.iter_mode == '<STR_LIT:id>':<EOL><INDENT>if hasattr(function, '<STR_LIT>'):<EOL><INDENT>metadata = content.get(function.iter_metadata)<EOL>if '<STR_LIT>' in metadata:<EOL><INDENT>next_results = urlsplit(metadata['<STR_LIT>'])<EOL>params = dict(parse_qsl(next_results.query))<EOL><DEDENT>else:<EOL><INDENT>raise StopIteration<EOL><DEDENT><DEDENT>else:<EOL><INDENT>params['<STR_LIT>'] = str(int(content[-<NUM_LIT:1>]['<STR_LIT>']) - <NUM_LIT:1>)<EOL><DEDENT><DEDENT>elif function.iter_mode == '<STR_LIT>':<EOL><INDENT>params['<STR_LIT>'] = content['<STR_LIT>']<EOL><DEDENT><DEDENT>except (TypeError, ValueError):  <EOL><INDENT>raise TwythonError('<STR_LIT>')<EOL><DEDENT>except (KeyError, AttributeError):  <EOL><INDENT>raise TwythonError('<STR_LIT>')<EOL><DEDENT><DEDENT>
Returns a generator for results that match a specified query.

        :param function: Instance of a Twython function
        (Twython.get_home_timeline, Twython.search)
        :param \*\*params: Extra parameters to send with your request
        (usually parameters accepted by the Twitter API endpoint)
        :rtype: generator

        Usage::

          >>> from twython import Twython
          >>> twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN,
          OAUTH_TOKEN_SECRET)

          >>> results = twitter.cursor(twitter.search, q='python')
          >>> for result in results:
          >>>   print result