Merge branch 'main' into avm99963-monorail
Merged commit cd4b3b336f1f14afa02990fdc2eec5d9467a827e
GitOrigin-RevId: e67bbf185d5538e1472bb42e0abb2a141f88bac1
diff --git a/tracker/issueattachmenttext.py b/tracker/issueattachmenttext.py
index d3daaf9..40db170 100644
--- a/tracker/issueattachmenttext.py
+++ b/tracker/issueattachmenttext.py
@@ -14,15 +14,13 @@
import logging
-import webapp2
-
-from google.appengine.api import app_identity
-
-from third_party import cloudstorage
import ezt
+from google.appengine.api import app_identity
+from google.cloud import storage
from features import prettify
from framework import exceptions
+from framework import flaskservlet
from framework import filecontent
from framework import permissions
from framework import servlet
@@ -36,7 +34,7 @@
"""AttachmentText displays textual attachments much like source browsing."""
_PAGE_TEMPLATE = 'tracker/issue-attachment-text.ezt'
- _MAIN_TAB_MODE = servlet.Servlet.MAIN_TAB_ISSUES
+ _MAIN_TAB_MODE = flaskservlet.FlaskServlet.MAIN_TAB_ISSUES
def GatherPageData(self, mr):
"""Parse the attachment ID from the request and serve its content.
@@ -52,19 +50,27 @@
attachment, issue = tracker_helpers.GetAttachmentIfAllowed(
mr, self.services)
except exceptions.NoSuchIssueException:
- webapp2.abort(404, 'issue not found')
+ self.abort(404, 'issue not found')
except exceptions.NoSuchAttachmentException:
- webapp2.abort(404, 'attachment not found')
+ self.abort(404, 'attachment not found')
except exceptions.NoSuchCommentException:
- webapp2.abort(404, 'comment not found')
+ self.abort(404, 'comment not found')
- content = []
+ content = b''
if attachment.gcs_object_id:
bucket_name = app_identity.get_default_gcs_bucket_name()
full_path = '/' + bucket_name + attachment.gcs_object_id
logging.info("reading gcs: %s" % full_path)
- with cloudstorage.open(full_path, 'r') as f:
- content = f.read()
+
+ # Strip leading slash from object ID for backwards compatibility.
+ blob_name = attachment.gcs_object_id
+ if blob_name.startswith('/'):
+ blob_name = blob_name[1:]
+
+ client = storage.Client()
+ bucket = client.get_bucket(bucket_name)
+ blob = bucket.get_blob(blob_name)
+ content = blob.download_as_bytes()
filesize = len(content)
@@ -101,3 +107,6 @@
len(lines), attachment.filename))
return page_data
+
+ # def GetAttachmentText(self, **kwargs):
+ # return self.handler(**kwargs)