def serve_mogilefs_file(request, key=None):
 mimetype = (mimetypes.guess_type(key)[0] or 'application/x-octet-stream')
 client = mogilefs.Client(settings.MOGILEFS_DOMAIN, settings.MOGILEFS_TRACKERS)
 if (hasattr(settings, 'SERVE_WITH_PERLBAL') and settings.SERVE_WITH_PERLBAL):
  path = cache.get(key)
  if (not path):
   path = client.get_paths(key)
   cache.set(key, path, 60)
  if path:
   response = HttpResponse(content_type=mimetype)
   response['X-REPROXY-URL'] = path[0]
  else:
   response = HttpResponseNotFound()
 else:
  file_data = client[key]
  if file_data:
   response = HttpResponse(file_data, mimetype=mimetype)
  else:
   response = HttpResponseNotFound()
 return response

def serve_mogilefs_file ( request , key = None ) : mimetype = ( mimetypes . guess_type ( key ) [ 0 ] or 'application/x-octet-stream' ) client = mogilefs . Client ( settings . MOGILEFS_DOMAIN , settings . MOGILEFS_TRACKERS ) if ( hasattr ( settings , 'SERVE_WITH_PERLBAL' ) and settings . SERVE_WITH_PERLBAL ) : path = cache . get ( key ) if ( not path ) : path = client . get_paths ( key ) cache . set ( key , path , 60 ) if path : response = HttpResponse ( content_type = mimetype ) response [ 'X-REPROXY-URL' ] = path [ 0 ] else : response = HttpResponseNotFound ( ) else : file_data = client [ key ] if file_data : response = HttpResponse ( file_data , mimetype = mimetype ) else : response = HttpResponseNotFound ( ) return response
called when a user requests an image .