Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import logging | |
| 6 from google.appengine.api import urlfetch | |
| 7 | |
| 8 from future import Future | |
| 9 | |
| 10 class AppEngineUrlFetcher(object): | |
| 11 """A wrapper around the App Engine urlfetch module that allows for easy | |
| 12 async fetches. | |
| 13 """ | |
| 14 def __init__(self, base_path): | |
| 15 self._base_path = base_path | |
| 16 | |
| 17 def Fetch(self, url): | |
| 18 """Fetches a file synchronously. | |
| 19 """ | |
| 20 return urlfetch.fetch(self._base_path + '/' + url) | |
| 21 | |
| 22 def FetchAsync(self, url): | |
| 23 """Fetches a file asynchronously, and returns a Future with the result. | |
| 24 """ | |
| 25 rpc = urlfetch.create_rpc() | |
| 26 urlfetch.make_fetch_call(rpc, self._base_path + '/' + url) | |
| 27 return Future(delegate=self._AsyncFetchDelegate(rpc)) | |
| 28 | |
| 29 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.
| |
| 30 def __init__(self, rpc): | |
| 31 self._rpc = rpc | |
| 32 | |
| 33 def Get(self): | |
| 34 self._rpc.wait() | |
| 35 return self._rpc.get_result() | |
| OLD | NEW |