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

Side by Side Diff: chrome/common/extensions/docs/server2/appengine_url_fetcher.py

Issue 10828042: Extensions Docs Server: Integration testing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved logic into server instance Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698