Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
push by roge...@chromium.org - Add an endpoint to download the binary content of a patch. Review: ht... on 2012-05-10 20:25 GMT
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
rietv...@googlecode.com  
View profile  
 More options May 10 2012, 4:25 pm
From: rietv...@googlecode.com
Date: Thu, 10 May 2012 20:25:10 +0000
Local: Thurs, May 10 2012 4:25 pm
Subject: [rietveld] push by roge...@chromium.org - Add an endpoint to download the binary content of a patch. Review: ht... on 2012-05-10 20:25 GMT
Revision: d9f35f2ee678
Author:   Roger Tawa <roge...@chromium.org>
Date:     Thu May 10 13:24:19 2012
Log:      Add an endpoint to download the binary content of a patch.  
Review: http://codereview.appspot.com/6197071/
http://code.google.com/p/rietveld/source/detail?r=d9f35f2ee678

Modified:
  /codereview/urls.py
  /codereview/views.py
  /codereview/views_chromium.py

=======================================
--- /codereview/urls.py Fri Dec 16 08:31:56 2011
+++ /codereview/urls.py Thu May 10 13:24:19 2012
@@ -102,6 +102,7 @@
  urlpatterns += patterns(
      'codereview.views_chromium',
      (r'^(\d+)/edit_flags$', 'edit_flags'),
+    (r'^(\d+)/binary/(\d+)/(\d+)/(\d+)$', 'download_binary'),
      (r'^conversions$', 'conversions'),
      (r'^lint/issue(\d+)_(\d+)', 'lint'),
      (r'^lint_patch/issue(\d+)_(\d+)_(\d+)', 'lint_patch'),
=======================================
--- /codereview/views.py        Thu May 10 09:39:31 2012
+++ /codereview/views.py        Thu May 10 13:24:19 2012
@@ -2401,7 +2401,7 @@

  @image_required
  def image(request):
-  """/<issue>/content/<patchset>/<patch>/<content> - Return patch's  
content."""
+  """/<issue>/image/<patchset>/<patch>/<content> - Return patch's  
content."""
    response = HttpResponse(request.content.data,  
content_type=request.mime_type)
    filename = re.sub(
        r'[^\w\.]', '_', request.patch.filename.encode('ascii', 'replace'))
=======================================
--- /codereview/views_chromium.py       Thu Apr 26 12:37:05 2012
+++ /codereview/views_chromium.py       Thu May 10 13:24:19 2012
@@ -17,6 +17,7 @@
  import cgi
  import datetime
  import logging
+import mimetypes
  import os
  import re
  import sha
@@ -77,6 +78,32 @@
    return key_wrapper

+def binary_required(func):
+  """Decorator that processes the content argument.
+
+  Attributes set on the request:
+   content: a Content entity.
+  """
+
+  @patch_required
+  def binary_wrapper(request, content_type, *args, **kwds):
+    content = None
+    if content_type == "0":
+      content = request.patch.content
+    elif content_type == "1":
+      content = request.patch.patched_content
+    # Other values are erroneous so request.content won't be set.
+    if not content or not content.data:
+      return views.HttpTextResponse(
+          'Invalid content type: %s, expected 0 or 1' % content_type,
+          status=404)
+    request.mime_type = mimetypes.guess_type(request.patch.filename)[0]
+    request.content = content
+    return func(request, *args, **kwds)
+
+  return binary_wrapper
+
+
  def string_to_datetime(text):
    """Parses a string into datetime including microseconds.

@@ -478,6 +505,21 @@
    return HttpResponse('OK')

+@binary_required
+def download_binary(request):
+  """/<issue>/binary/<patchset>/<patch>/<content>
+
+  Return patch's binary content.  If the patch is not binary, an empty  
stream
+  is returned.  <content> may be 0 for the base content or 1 for the new
+  content.  All other values are invalid.
+  """
+  response = HttpResponse(request.content.data,  
content_type=request.mime_type)
+  filename = re.sub(
+      r'[^\w\.]', '_', request.patch.filename.encode('ascii', 'replace'))
+  response['Content-Disposition'] = 'attachment; filename="%s"' % filename
+  return response
+
+
  @views.json_response
  def get_pending_try_patchsets(request):
    limit = int(request.GET.get('limit', '10'))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »