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