title: Python: Using *args, **kwargs in wrapper functions
body: <p>I'm writing a wrapper function for Django's render_to_response() to add a CSRF processing.</p>
  
  <p>The logic is:</p>
  
  <pre><code>def some_view (request)
      dictionary = {'context_param': some_param}
      dictionary.update(csrf(request))
      # ... view code here
      return render_to_response("a_template.html", dictionary)
  </code></pre>
  
  <p>render_to_response() has the following signature:</p>
  
  <pre><code>def render_to_response(*args, **kwargs)
  </code></pre>
  
  <p>I want to write transparent wrapper - just add some functionality (mentioned before) and leave other things as they are. I guess I should write someting like this:</p>
  
  <pre><code>def csrf_response (request, *args, **kwargs):
  
      # Here I need to somehow extract dictionary from args or kwargs
  
      if dictionary is None:
          dictionary = {}
      dictionary.update(csrf(request))
  
      # And here I somehow need to pass dictionary into render_to_response() fot the furher processing
      return render_to_response(*args, **kwargs)
  </code></pre>
  
  <p>So question is - what is the best practice for extracting needed parameter from args/kwargs, (then changing it) and passing it further? </p>
  
  <p>BTW code of render_to_response() seemed me a bit strange. Here it is:</p>
  
  <pre><code>def render_to_response(*args, **kwargs):
      """
      Returns a HttpResponse whose content is filled with the result of calling
      django.template.loader.render_to_string() with the passed arguments.
      """
      httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}
      return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
  </code></pre>
  
  <p>What if someone call it with all positional arguments, so kwargs will be empty, but <code>mimetype</code> parameter will be specified as a last positional argument? Looks like in that case its behavior would be wrong.</p>