def serve_file(path, content_type=None, disposition=None, name=None, debug=False):
 response = cherrypy.serving.response
 if (not os.path.isabs(path)):
  msg = ("'%s' is not an absolute path." % path)
  if debug:
   cherrypy.log(msg, 'TOOLS.STATICFILE')
  raise ValueError(msg)
 try:
  st = os.stat(path)
 except (OSError, TypeError, ValueError):
  if debug:
   cherrypy.log(('os.stat(%r) failed' % path), 'TOOLS.STATIC')
  raise cherrypy.NotFound()
 if stat.S_ISDIR(st.st_mode):
  if debug:
   cherrypy.log(('%r is a directory' % path), 'TOOLS.STATIC')
  raise cherrypy.NotFound()
 response.headers['Last-Modified'] = httputil.HTTPDate(st.st_mtime)
 cptools.validate_since()
 if (content_type is None):
  ext = ''
  i = path.rfind('.')
  if (i != (-1)):
   ext = path[i:].lower()
  content_type = mimetypes.types_map.get(ext, None)
 if (content_type is not None):
  response.headers['Content-Type'] = content_type
 if debug:
  cherrypy.log(('Content-Type: %r' % content_type), 'TOOLS.STATIC')
 cd = None
 if (disposition is not None):
  if (name is None):
   name = os.path.basename(path)
  cd = ('%s; filename="%s"' % (disposition, name))
  response.headers['Content-Disposition'] = cd
 if debug:
  cherrypy.log(('Content-Disposition: %r' % cd), 'TOOLS.STATIC')
 content_length = st.st_size
 fileobj = open(path, 'rb')
 return _serve_fileobj(fileobj, content_type, content_length, debug=debug)

def serve_file ( path , content_type = None , disposition = None , name = None , debug = False ) : response = cherrypy . serving . response if ( not os . path . isabs ( path ) ) : msg = ( "'%s' is not an absolute path." % path ) if debug : cherrypy . log ( msg , 'TOOLS.STATICFILE' ) raise ValueError ( msg ) try : st = os . stat ( path ) except ( OSError , TypeError , ValueError ) : if debug : cherrypy . log ( ( 'os.stat(%r) failed' % path ) , 'TOOLS.STATIC' ) raise cherrypy . NotFound ( ) if stat . S_ISDIR ( st . st_mode ) : if debug : cherrypy . log ( ( '%r is a directory' % path ) , 'TOOLS.STATIC' ) raise cherrypy . NotFound ( ) response . headers [ 'Last-Modified' ] = httputil . HTTPDate ( st . st_mtime ) cptools . validate_since ( ) if ( content_type is None ) : ext = '' i = path . rfind ( '.' ) if ( i != ( - 1 ) ) : ext = path [ i : ] . lower ( ) content_type = mimetypes . types_map . get ( ext , None ) if ( content_type is not None ) : response . headers [ 'Content-Type' ] = content_type if debug : cherrypy . log ( ( 'Content-Type: %r' % content_type ) , 'TOOLS.STATIC' ) cd = None if ( disposition is not None ) : if ( name is None ) : name = os . path . basename ( path ) cd = ( '%s; filename="%s"' % ( disposition , name ) ) response . headers [ 'Content-Disposition' ] = cd if debug : cherrypy . log ( ( 'Content-Disposition: %r' % cd ) , 'TOOLS.STATIC' ) content_length = st . st_size fileobj = open ( path , 'rb' ) return _serve_fileobj ( fileobj , content_type , content_length , debug = debug )
return a chunk from a file based on the data received .