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

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

Issue 15009006: Docserver: refactor Servlet, ObjectStore, and ServerInstance architecture to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cduvall, redirect fix Created 7 years, 7 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 import base64 5 import base64
6 6
7 from appengine_wrappers import urlfetch 7 from appengine_wrappers import urlfetch
8 from future import Future 8 from future import Future
9 9
10 class _AsyncFetchDelegate(object): 10 class _AsyncFetchDelegate(object):
(...skipping 13 matching lines...) Expand all
24 class AppEngineUrlFetcher(object): 24 class AppEngineUrlFetcher(object):
25 """A wrapper around the App Engine urlfetch module that allows for easy 25 """A wrapper around the App Engine urlfetch module that allows for easy
26 async fetches. 26 async fetches.
27 """ 27 """
28 def __init__(self, base_path=None): 28 def __init__(self, base_path=None):
29 self._base_path = base_path 29 self._base_path = base_path
30 30
31 def Fetch(self, url, username=None, password=None): 31 def Fetch(self, url, username=None, password=None):
32 """Fetches a file synchronously. 32 """Fetches a file synchronously.
33 """ 33 """
34 headers = _MakeHeaders(username, password)
35 if self._base_path is not None: 34 if self._base_path is not None:
36 return urlfetch.fetch('%s/%s' % (self._base_path, url), headers=headers) 35 url = '%s/%s' % (self._base_path, url)
37 else: 36 return urlfetch.fetch(url, headers=_MakeHeaders(username, password))
38 return urlfetch.fetch(url, headers={ 'Cache-Control': 'max-age=0' })
39 37
40 def FetchAsync(self, url, username=None, password=None): 38 def FetchAsync(self, url, username=None, password=None):
41 """Fetches a file asynchronously, and returns a Future with the result. 39 """Fetches a file asynchronously, and returns a Future with the result.
42 """ 40 """
41 if self._base_path is not None:
42 url = '%s/%s' % (self._base_path, url)
43 rpc = urlfetch.create_rpc() 43 rpc = urlfetch.create_rpc()
44 headers = _MakeHeaders(username, password) 44 urlfetch.make_fetch_call(rpc, url, headers=_MakeHeaders(username, password))
45 if self._base_path is not None:
46 urlfetch.make_fetch_call(rpc,
47 '%s/%s' % (self._base_path, url),
48 headers=headers)
49 else:
50 urlfetch.make_fetch_call(rpc, url, headers=headers)
51 return Future(delegate=_AsyncFetchDelegate(rpc)) 45 return Future(delegate=_AsyncFetchDelegate(rpc))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698