@memoize('media.fetch_size', time=3600)
def _fetch_image_size(url, referer):
 request = _initialize_request(url, referer)
 if (not request):
  return None
 parser = ImageFile.Parser()
 response = None
 try:
  response = urllib2.urlopen(request)
  while True:
   chunk = response.read(1024)
   if (not chunk):
    break
   parser.feed(chunk)
   if parser.image:
    return parser.image.size
 except urllib2.URLError:
  return None
 finally:
  if response:
   response.close()

@ memoize ( 'media.fetch_size' , time = 3600 ) def _fetch_image_size ( url , referer ) : request = _initialize_request ( url , referer ) if ( not request ) : return None parser = ImageFile . Parser ( ) response = None try : response = urllib2 . urlopen ( request ) while True : chunk = response . read ( 1024 ) if ( not chunk ) : break parser . feed ( chunk ) if parser . image : return parser . image . size except urllib2 . URLError : return None finally : if response : response . close ( )
return the size of an image by url downloading as little as possible .