code: def require_captcha(function, *args, **kwargs):
      
      raise_captcha_exception = kwargs.pop('raise_captcha_exception', False)
      captcha_id = None
  
      # Get a handle to the reddit session
      if hasattr(args[0], 'reddit_session'):
          reddit_session = args[0].reddit_session
      else:
          reddit_session = args[0]
  
      while True:
          try:
              if captcha_id:
                  captcha_answer = _get_captcha(reddit_session, captcha_id)
  
                  # When the method is being decorated, all of its default
                  # parameters become part of this *args tuple. This means that
                  # *args currently contains a None where the captcha answer
                  # needs to go. If we put the captcha in the **kwargs,
                  # we get a TypeError for having two values of the same param.
                  func_args = _make_func_args(function)
                  if 'captcha' in func_args:
                      captcha_index = func_args.index('captcha')
                      args = list(args)
                      args[captcha_index] = captcha_answer
                  else:
                      kwargs['captcha'] = captcha_answer
              return function(*args, **kwargs)
          except errors.InvalidCaptcha as exception:
              if raise_captcha_exception or \
                      not hasattr(sys.stdin, 'closed') or sys.stdin.closed:
                  raise
              captcha_id = exception.response['captcha']
docs: Return a decorator for methods that require captchas.