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

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

Issue 149513014: Docserver: Add FileSystem.Exists method and start sanity checking path format (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 import posixpath 6 import posixpath
7 7
8 from appengine_wrappers import GetAppVersion, urlfetch 8 from appengine_wrappers import GetAppVersion, urlfetch
9 from future import Future 9 from future import Future
10 10
(...skipping 15 matching lines...) Expand all
26 headers['Authorization'] = 'Basic %s' % base64.b64encode( 26 headers['Authorization'] = 'Basic %s' % base64.b64encode(
27 '%s:%s' % (username, password)) 27 '%s:%s' % (username, password))
28 return headers 28 return headers
29 29
30 30
31 class AppEngineUrlFetcher(object): 31 class AppEngineUrlFetcher(object):
32 """A wrapper around the App Engine urlfetch module that allows for easy 32 """A wrapper around the App Engine urlfetch module that allows for easy
33 async fetches. 33 async fetches.
34 """ 34 """
35 def __init__(self, base_path=None): 35 def __init__(self, base_path=None):
36 assert base_path is None or not base_path.endswith('/') 36 assert base_path is None or not base_path.endswith('/'), base_path
37 self._base_path = base_path 37 self._base_path = base_path
38 38
39 def Fetch(self, url, username=None, password=None): 39 def Fetch(self, url, username=None, password=None):
40 """Fetches a file synchronously. 40 """Fetches a file synchronously.
41 """ 41 """
42 return urlfetch.fetch(self._FromBasePath(url), 42 return urlfetch.fetch(self._FromBasePath(url),
43 headers=_MakeHeaders(username, password)) 43 headers=_MakeHeaders(username, password))
44 44
45 def FetchAsync(self, url, username=None, password=None): 45 def FetchAsync(self, url, username=None, password=None):
46 """Fetches a file asynchronously, and returns a Future with the result. 46 """Fetches a file asynchronously, and returns a Future with the result.
47 """ 47 """
48 rpc = urlfetch.create_rpc() 48 rpc = urlfetch.create_rpc()
49 urlfetch.make_fetch_call(rpc, 49 urlfetch.make_fetch_call(rpc,
50 self._FromBasePath(url), 50 self._FromBasePath(url),
51 headers=_MakeHeaders(username, password)) 51 headers=_MakeHeaders(username, password))
52 return Future(delegate=_AsyncFetchDelegate(rpc)) 52 return Future(delegate=_AsyncFetchDelegate(rpc))
53 53
54 def _FromBasePath(self, url): 54 def _FromBasePath(self, url):
55 assert not url.startswith('/') 55 assert not url.startswith('/'), url
56 if self._base_path is not None: 56 if self._base_path is not None:
57 url = posixpath.join(self._base_path, url) if url else self._base_path 57 url = posixpath.join(self._base_path, url) if url else self._base_path
58 return url 58 return url
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698