Changeset 142:9fbd59aedd76
- Timestamp:
- 07/24/07 11:59:21 (16 months ago)
- Author:
- Tarek Ziad?? <tarek@…>
- Message:
-
protecting calls
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r140
|
r142
|
|
| | 1 | import os |
| | 2 | import logging |
| 1 | 3 | import cached_url, thumbnail |
| 2 | 4 | from urllib2 import urlopen |
| 3 | 5 | from StringIO import StringIO |
| | 6 | |
| | 7 | logging.basicConfig(level=logging.DEBUG, |
| | 8 | format='%(asctime)s %(levelname)s %(message)s', |
| | 9 | filename='cached.log', |
| | 10 | filemode='w') |
| | 11 | |
| | 12 | console = logging.StreamHandler() |
| | 13 | console.setLevel(logging.DEBUG) |
| | 14 | formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') |
| | 15 | console.setFormatter(formatter) |
| | 16 | logging.getLogger('').addHandler(console) |
| 4 | 17 | |
| 5 | 18 | def get_content(url, width=None, height=None, scale=None, control=False): |
| … |
… |
|
| 8 | 21 | content = cached_url.mc.get(key) |
| 9 | 22 | if content is not None: |
| | 23 | logging.debug('%s cached' % key) |
| 10 | 24 | return content |
| 11 | 25 | infos, content = cached_url.get_content(url, control) |
| 12 | | content = thumbnail.generate(StringIO(content), width, height, scale) |
| 13 | | cached_url.mc.set(key, (infos, content)) |
| | 26 | try: |
| | 27 | content = thumbnail.generate(StringIO(content), width, height, scale) |
| | 28 | except IOError: |
| | 29 | content = None |
| | 30 | cached_url.mc.set(key, (infos, content)) |
| | 31 | logging.debug('%s caching' % key) |
| 14 | 32 | return infos, content |
| 15 | 33 | |