summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/server2/appengine_wrappers.py
diff options
context:
space:
mode:
authorcduvall@chromium.org <cduvall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-13 23:22:14 +0000
committercduvall@chromium.org <cduvall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-13 23:22:14 +0000
commitb1402a5ad552386dbeeef477dfa351cd453d5793 (patch)
treec9de22cfcf592f9ca2cde47dfa0a531b2e5db536 /chrome/common/extensions/docs/server2/appengine_wrappers.py
parent2d865fa21417e8466784cc5af721dac79c63f006 (diff)
downloadchromium_src-b1402a5ad552386dbeeef477dfa351cd453d5793.zip
chromium_src-b1402a5ad552386dbeeef477dfa351cd453d5793.tar.gz
chromium_src-b1402a5ad552386dbeeef477dfa351cd453d5793.tar.bz2
Extensions Docs Server: BranchUtility not fetching branch numbers correctly
BranchUtility was crashing when it tried to fetch the branch numbers for the dev, beta, and stable channels. There was also a problem using the branch number where the name should have been used. ServerInstances are no longer leaked. BUG=141909 Review URL: https://chromiumcodereview.appspot.com/10831269 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151386 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/docs/server2/appengine_wrappers.py')
-rw-r--r--chrome/common/extensions/docs/server2/appengine_wrappers.py75
1 files changed, 53 insertions, 22 deletions
diff --git a/chrome/common/extensions/docs/server2/appengine_wrappers.py b/chrome/common/extensions/docs/server2/appengine_wrappers.py
index b0b65df..9cbdbd4 100644
--- a/chrome/common/extensions/docs/server2/appengine_wrappers.py
+++ b/chrome/common/extensions/docs/server2/appengine_wrappers.py
@@ -13,6 +13,59 @@ try:
import google.appengine.api.memcache as memcache
import google.appengine.api.urlfetch as urlfetch
except ImportError:
+ import re
+
+ FAKE_URL_FETCHER_CONFIGURATION = None
+
+ def ConfigureFakeUrlFetch(configuration):
+ """|configuration| is a dictionary mapping strings to fake urlfetch classes.
+ A fake urlfetch class just needs to have a fetch method. The keys of the
+ dictionary are treated as regex, and they are matched with the URL to
+ determine which fake urlfetch is used.
+ """
+ global FAKE_URL_FETCHER_CONFIGURATION
+ FAKE_URL_FETCHER_CONFIGURATION = dict(
+ (re.compile(k), v) for k, v in configuration.iteritems())
+
+ def _GetConfiguration(key):
+ if not FAKE_URL_FETCHER_CONFIGURATION:
+ raise ValueError('No fake fetch paths have been configured. '
+ 'See ConfigureFakeUrlFetch in appengine_wrappers.py.')
+ for k, v in FAKE_URL_FETCHER_CONFIGURATION.iteritems():
+ if k.match(key):
+ return v
+ return None
+
+ class FakeUrlFetch(object):
+ """A fake urlfetch module that uses the current
+ |FAKE_URL_FETCHER_CONFIGURATION| to map urls to fake fetchers.
+ """
+ class _Response(object):
+ def __init__(self, content):
+ self.content = content
+ self.headers = { 'content-type': 'none' }
+ self.status_code = 200
+
+ class _RPC(object):
+ def __init__(self):
+ self.result = None
+
+ def wait(self):
+ pass
+
+ def get_result(self):
+ return self.result
+
+ def fetch(self, url):
+ return self._Response(_GetConfiguration(url).fetch(url))
+
+ def create_rpc(self):
+ return self._RPC()
+
+ def make_fetch_call(self, rpc, url):
+ rpc.result = self.fetch(url)
+ urlfetch = FakeUrlFetch()
+
class NotImplemented(object):
def __getattr__(self, attr):
raise NotImplementedError()
@@ -42,28 +95,6 @@ except ImportError:
self._cache[namespace].pop(key)
memcache = InMemoryMemcache()
- class FakeUrlfetch(object):
- class _RPC(object):
- def wait(self):
- pass
-
- def get_result(self):
- return FakeUrlfetch._Result()
-
- class _Result(object):
- def __init__(self):
- self.content = '{ "commit": { "tree": { "sha": 0 } } }'
-
- def fetch(self, url):
- return self._Result()
-
- def create_rpc(self):
- return self._RPC()
-
- def make_fetch_call(self, rpc, url):
- pass
- urlfetch = FakeUrlfetch()
-
# A fake webapp.RequestHandler class for Handler to extend.
class webapp(object):
class RequestHandler(object):