Chromium Code Reviews| 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() |