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

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: memcache fix 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..4e6d0bce4d4f405439f17c80654b6f4433c99cfd
--- /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 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=self._AsyncFetchDelegate(rpc))
+
+ class _AsyncFetchDelegate(object):
not at google - send to devlin 2012/07/19 03:55:19 nit: at top, outside the class scope
cduvall 2012/07/19 17:18:28 Done.
+ def __init__(self, rpc):
+ self._rpc = rpc
+
+ def Get(self):
+ self._rpc.wait()
+ return self._rpc.get_result()

Powered by Google App Engine
This is Rietveld 408576698