Changeset 142:9fbd59aedd76

Show
Ignore:
Timestamp:
07/24/07 11:59:21 (16 months ago)
Author:
Tarek Ziad?? <tarek@…>
Message:

protecting calls

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cachers/cached_image.py

    r140 r142  
     1import os 
     2import logging 
    13import cached_url, thumbnail 
    24from urllib2 import urlopen 
    35from StringIO import StringIO 
     6 
     7logging.basicConfig(level=logging.DEBUG, 
     8                    format='%(asctime)s %(levelname)s %(message)s', 
     9                    filename='cached.log', 
     10                    filemode='w') 
     11 
     12console = logging.StreamHandler() 
     13console.setLevel(logging.DEBUG) 
     14formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') 
     15console.setFormatter(formatter) 
     16logging.getLogger('').addHandler(console) 
    417 
    518def get_content(url, width=None, height=None, scale=None, control=False): 
     
    821    content = cached_url.mc.get(key) 
    922    if content is not None: 
     23        logging.debug('%s cached' % key) 
    1024        return content 
    1125    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) 
    1432    return infos, content 
    1533