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

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

Issue 10704252: Extensions Docs Server: Internal file system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed up Created 8 years, 5 months 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
new file mode 100644
index 0000000000000000000000000000000000000000..e62ce89c40e28e83a860163dc3d97ea6877e1e39
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/appengine_url_fetcher.py
@@ -0,0 +1,35 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import logging
+from google.appengine.api import urlfetch
+
+from future import Future
+
+class _AsyncFetchDelegate(object):
+ def __init__(self, rpc):
+ self._rpc = rpc
+
+ def Get(self):
+ self._rpc.wait()
+ return self._rpc.get_result()
+
+class AppEngineUrlFetcher(object):
+ """A wrapper around the App Engine urlfetch module that allows for easy
+ async fetches.
+ """
+ def __init__(self, base_path):
+ self._base_path = base_path
+
+ def Fetch(self, url):
+ """Fetches a file synchronously.
+ """
+ return urlfetch.fetch(self._base_path + '/' + url)
+
+ def FetchAsync(self, url):
+ """Fetches a file asynchronously, and returns a Future with the result.
+ """
+ rpc = urlfetch.create_rpc()
+ urlfetch.make_fetch_call(rpc, self._base_path + '/' + url)
+ return Future(delegate=_AsyncFetchDelegate(rpc))
« no previous file with comments | « chrome/common/extensions/docs/server2/appengine_memcache.py ('k') | chrome/common/extensions/docs/server2/branch_utility.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698