OLD | NEW |
---|---|
(Empty) | |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 import logging | |
6 | |
7 from google.appengine.api import urlfetch | |
8 from memcache import MemcacheAdd, MemcacheGet | |
Aaron Boodman
2012/05/24 06:10:23
memcache will need to be dependency injected at so
| |
9 | |
10 class FetchException(Exception): | |
Aaron Boodman
2012/05/24 06:10:23
Prefix with _.
cduvall
2012/05/25 20:02:23
Done.
| |
11 """Thrown when status code is not 200. | |
12 """ | |
13 def __init__(self, url): | |
14 Exception.__init__(self, 'Fetch exception from ' + url) | |
15 | |
16 def fetch(url): | |
17 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.
| |
18 if result is not None: | |
19 return result | |
20 logging.info('Fetch cache miss: ' + url) | |
21 | |
22 result = urlfetch.fetch(url) | |
23 | |
24 if result.status_code != 200: | |
25 raise FetchException(url) | |
26 | |
27 MemcacheAdd(url, result, 'urls') | |
28 return result | |
OLD | NEW |