Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2593)

Unified Diff: chrome/common/extensions/docs/server2/appengine_url_fetcher.py

Issue 68873003: Docserver: Serve docs out of src/ not src/chrome/common/extensions. This allows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/appengine_url_fetcher.py
diff --git a/chrome/common/extensions/docs/server2/appengine_url_fetcher.py b/chrome/common/extensions/docs/server2/appengine_url_fetcher.py
index e9c9991a0f56dff10c8cf95f397fa6ae85453f05..37997eb09a2e237b7134e8b3f16498d9615027c4 100644
--- a/chrome/common/extensions/docs/server2/appengine_url_fetcher.py
+++ b/chrome/common/extensions/docs/server2/appengine_url_fetcher.py
@@ -3,10 +3,12 @@
# found in the LICENSE file.
import base64
+import posixpath
from appengine_wrappers import urlfetch
from future import Future
+
class _AsyncFetchDelegate(object):
def __init__(self, rpc):
self._rpc = rpc
@@ -14,6 +16,7 @@ class _AsyncFetchDelegate(object):
def Get(self):
return self._rpc.get_result()
+
def _MakeHeaders(username, password):
headers = { 'Cache-Control': 'max-age=0' }
if username is not None and password is not None:
@@ -21,25 +24,31 @@ def _MakeHeaders(username, password):
'%s:%s' % (username, password))
return headers
+
class AppEngineUrlFetcher(object):
"""A wrapper around the App Engine urlfetch module that allows for easy
async fetches.
"""
def __init__(self, base_path=None):
+ assert base_path is None or not base_path.endswith('/')
self._base_path = base_path
def Fetch(self, url, username=None, password=None):
"""Fetches a file synchronously.
"""
- if self._base_path is not None:
- url = '%s/%s' % (self._base_path, url)
- return urlfetch.fetch(url, headers=_MakeHeaders(username, password))
+ return urlfetch.fetch(self._FromBasePath(url),
+ headers=_MakeHeaders(username, password))
def FetchAsync(self, url, username=None, password=None):
"""Fetches a file asynchronously, and returns a Future with the result.
"""
- if self._base_path is not None:
- url = '%s/%s' % (self._base_path, url)
rpc = urlfetch.create_rpc()
- urlfetch.make_fetch_call(rpc, url, headers=_MakeHeaders(username, password))
+ urlfetch.make_fetch_call(rpc,
+ self._FromBasePath(url),
+ headers=_MakeHeaders(username, password))
return Future(delegate=_AsyncFetchDelegate(rpc))
+
+ def _FromBasePath(self, url):
+ if self._base_path is not None:
+ url = posixpath.join(self._base_path, url) if url else self._base_path
+ return url

Powered by Google App Engine
This is Rietveld 408576698