nodes: 0, module; 1, function_definition; 2, function_name:search; 3, parameters; 4, block; 5, identifier:self; 6, identifier:query; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, list_splat_pattern; 12, dictionary_splat_pattern; 13, expression_statement; 14, expression_statement; 15, if_statement; 16, if_statement; 17, if_statement; 18, if_statement; 19, if_statement; 20, expression_statement; 21, expression_statement; 22, while_statement; 23, identifier:subreddit; 24, None; 25, identifier:sort; 26, None; 27, identifier:syntax; 28, None; 29, identifier:period; 30, None; 31, identifier:args; 32, identifier:kwargs; 33, comment:"""Return a generator for submissions that match the search query.
  
          :param query: The query string to search for. If query is a URL only
              submissions which link to that URL will be returned.
          :param subreddit: Limit search results to the subreddit if provided.
          :param sort: The sort order of the results.
          :param syntax: The syntax of the search query.
          :param period: The time period of the results.
  
          The additional parameters are passed directly into
          :meth:`.get_content`. Note: the `url` parameter cannot be altered.
  
          See https://www.reddit.com/wiki/search for more information on how to
          build a search query.
  
          """; 34, assignment; 35, comparison_operator:'params' in kwargs; 36, block; 37, identifier:sort; 38, block; 39, identifier:syntax; 40, block; 41, identifier:period; 42, block; 43, identifier:subreddit; 44, block; 45, else_clause; 46, assignment; 47, assignment; 48, comparison_operator:depth > 0; 49, block; 50, identifier:params; 51, dictionary; 52, string; 53, identifier:kwargs; 54, expression_statement; 55, expression_statement; 56, expression_statement; 57, expression_statement; 58, expression_statement; 59, expression_statement; 60, expression_statement; 61, block; 62, identifier:url; 63, call; 64, identifier:depth; 65, integer:2; 66, identifier:depth; 67, integer:0; 68, expression_statement; 69, try_statement; 70, pair; 71, string_content:params; 72, call; 73, call; 74, assignment; 75, assignment; 76, assignment; 77, assignment; 78, assignment; 79, expression_statement; 80, attribute; 81, argument_list; 82, augmented_assignment; 83, block; 84, except_clause; 85, string; 86, identifier:query; 87, attribute; 88, argument_list; 89, attribute; 90, argument_list; 91, subscript; 92, identifier:sort; 93, subscript; 94, identifier:syntax; 95, subscript; 96, identifier:period; 97, subscript; 98, string; 99, identifier:subreddit; 100, call; 101, assignment; 102, subscript; 103, identifier:format; 104, keyword_argument; 105, identifier:depth; 106, integer:1; 107, for_statement; 108, break_statement; 109, as_pattern; 110, block; 111, string_content:q; 112, identifier:params; 113, identifier:update; 114, subscript; 115, identifier:kwargs; 116, identifier:pop; 117, string; 118, identifier:params; 119, string; 120, identifier:params; 121, string; 122, identifier:params; 123, string; 124, identifier:params; 125, string; 126, string_content:on; 127, attribute; 128, argument_list; 129, identifier:subreddit; 130, string; 131, attribute; 132, string; 133, identifier:subreddit; 134, identifier:subreddit; 135, identifier:item; 136, call; 137, block; 138, attribute; 139, as_pattern_target; 140, expression_statement; 141, expression_statement; 142, expression_statement; 143, comment:# Handle redirects from URL searches; 144, if_statement; 145, identifier:kwargs; 146, string; 147, string_content:params; 148, string_content:sort; 149, string_content:syntax; 150, string_content:t; 151, string_content:restrict_sr; 152, identifier:six; 153, identifier:text_type; 154, identifier:subreddit; 155, string_content:all; 156, identifier:self; 157, identifier:config; 158, string_content:search; 159, attribute; 160, argument_list; 161, expression_statement; 162, identifier:errors; 163, identifier:RedirectException; 164, identifier:exc; 165, assignment; 166, assignment; 167, assignment; 168, comparison_operator:'already_submitted' in params; 169, block; 170, string_content:params; 171, identifier:self; 172, identifier:get_content; 173, identifier:url; 174, keyword_argument; 175, list_splat; 176, dictionary_splat; 177, yield; 178, identifier:parsed; 179, call; 180, identifier:params; 181, call; 182, identifier:url; 183, call; 184, string; 185, identifier:params; 186, expression_statement; 187, break_statement; 188, identifier:params; 189, identifier:params; 190, identifier:args; 191, identifier:kwargs; 192, identifier:item; 193, identifier:urlparse; 194, argument_list; 195, identifier:dict; 196, generator_expression; 197, identifier:urlunparse; 198, argument_list; 199, string_content:already_submitted; 200, yield; 201, attribute; 202, tuple; 203, for_in_clause; 204, binary_operator:parsed[:3] + ("", "", ""); 205, call; 206, identifier:exc; 207, identifier:response_url; 208, identifier:k; 209, call; 210, pattern_list; 211, call; 212, subscript; 213, tuple; 214, attribute; 215, argument_list; 216, attribute; 217, argument_list; 218, identifier:k; 219, identifier:v; 220, attribute; 221, argument_list; 222, identifier:parsed; 223, slice; 224, string:""; 225, string:""; 226, string:""; 227, identifier:self; 228, identifier:get_submission; 229, identifier:url; 230, string:","; 231, identifier:join; 232, identifier:v; 233, call; 234, identifier:items; 235, integer:3; 236, identifier:parse_qs; 237, argument_list; 238, attribute; 239, identifier:parsed; 240, identifier:query
code: def search(self, query, subreddit=None, sort=None, syntax=None,
                 period=None, *args, **kwargs):
          """Return a generator for submissions that match the search query.
  
          :param query: The query string to search for. If query is a URL only
              submissions which link to that URL will be returned.
          :param subreddit: Limit search results to the subreddit if provided.
          :param sort: The sort order of the results.
          :param syntax: The syntax of the search query.
          :param period: The time period of the results.
  
          The additional parameters are passed directly into
          :meth:`.get_content`. Note: the `url` parameter cannot be altered.
  
          See https://www.reddit.com/wiki/search for more information on how to
          build a search query.
  
          """
          params = {'q': query}
          if 'params' in kwargs:
              params.update(kwargs['params'])
              kwargs.pop('params')
          if sort:
              params['sort'] = sort
          if syntax:
              params['syntax'] = syntax
          if period:
              params['t'] = period
          if subreddit:
              params['restrict_sr'] = 'on'
              subreddit = six.text_type(subreddit)
          else:
              subreddit = 'all'
          url = self.config['search'].format(subreddit=subreddit)
  
          depth = 2
          while depth > 0:
              depth -= 1
              try:
                  for item in self.get_content(url, params=params, *args,
                                               **kwargs):
                      yield item
                  break
              except errors.RedirectException as exc:
                  parsed = urlparse(exc.response_url)
                  params = dict((k, ",".join(v)) for k, v in
                                parse_qs(parsed.query).items())
                  url = urlunparse(parsed[:3] + ("", "", ""))
                  # Handle redirects from URL searches
                  if 'already_submitted' in params:
                      yield self.get_submission(url)
                      break