Index: chrome/common/extensions/docs/server2/urlfetch.py |
diff --git a/chrome/common/extensions/docs/server2/urlfetch.py b/chrome/common/extensions/docs/server2/urlfetch.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d1754a5d8e6581b0cd79107945f965e05773b97b |
--- /dev/null |
+++ b/chrome/common/extensions/docs/server2/urlfetch.py |
@@ -0,0 +1,28 @@ |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import logging |
+ |
+from google.appengine.api import urlfetch |
+from memcache import MemcacheAdd, MemcacheGet |
Aaron Boodman
2012/05/24 06:10:23
memcache will need to be dependency injected at so
|
+ |
+class FetchException(Exception): |
Aaron Boodman
2012/05/24 06:10:23
Prefix with _.
cduvall
2012/05/25 20:02:23
Done.
|
+ """Thrown when status code is not 200. |
+ """ |
+ def __init__(self, url): |
+ Exception.__init__(self, 'Fetch exception from ' + url) |
+ |
+def fetch(url): |
+ result = MemcacheGet(url, 'urls') |
Aaron Boodman
2012/05/24 06:10:23
Is there a way in python to get introspect a modul
cduvall
2012/05/25 20:02:23
Done.
|
+ if result is not None: |
+ return result |
+ logging.info('Fetch cache miss: ' + url) |
+ |
+ result = urlfetch.fetch(url) |
+ |
+ if result.status_code != 200: |
+ raise FetchException(url) |
+ |
+ MemcacheAdd(url, result, 'urls') |
+ return result |