parameters: (self, url)
docstring: Use local file.
docstring_summary: Use local file.
docstring_tokens: Use local file .
function: def open_local_file(self, url):
          """Use local file."""
          import mimetypes, mimetools, email.utils
          try:
              from cStringIO import StringIO
          except ImportError:
              from StringIO import StringIO
          host, file = splithost(url)
          localname = url2pathname(file)
          try:
              stats = os.stat(localname)
          except OSError, e:
              raise IOError(e.errno, e.strerror, e.filename)
          size = stats.st_size
          modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
          mtype = mimetypes.guess_type(url)[0]
          headers = mimetools.Message(StringIO(
              'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %
              (mtype or 'text/plain', size, modified)))
          if not host:
              urlfile = file
              if file[:1] == '/':
                  urlfile = 'file://' + file
              elif file[:2] == './':
                  raise ValueError("local file url may start with / or file:. Unknown url of type: %s" % url)
              return addinfourl(open(localname, 'rb'),
                                headers, urlfile)
          host, port = splitport(host)
          if not port \
             and socket.gethostbyname(host) in (localhost(), thishost()):
              urlfile = file
              if file[:1] == '/':
                  urlfile = 'file://' + file
              return addinfourl(open(localname, 'rb'),
                                headers, urlfile)
          raise IOError, ('local file error', 'not on local host')
function_tokens: def open_local_file ( self , url ) : import mimetypes , mimetools , email . utils try : from cStringIO import StringIO except ImportError : from StringIO import StringIO host , file = splithost ( url ) localname = url2pathname ( file ) try : stats = os . stat ( localname ) except OSError , e : raise IOError ( e . errno , e . strerror , e . filename ) size = stats . st_size modified = email . utils . formatdate ( stats . st_mtime , usegmt = True ) mtype = mimetypes . guess_type ( url ) [ 0 ] headers = mimetools . Message ( StringIO ( 'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' % ( mtype or 'text/plain' , size , modified ) ) ) if not host : urlfile = file if file [ : 1 ] == '/' : urlfile = 'file://' + file elif file [ : 2 ] == './' : raise ValueError ( "local file url may start with / or file:. Unknown url of type: %s" % url ) return addinfourl ( open ( localname , 'rb' ) , headers , urlfile ) host , port = splitport ( host ) if not port and socket . gethostbyname ( host ) in ( localhost ( ) , thishost ( ) ) : urlfile = file if file [ : 1 ] == '/' : urlfile = 'file://' + file return addinfourl ( open ( localname , 'rb' ) , headers , urlfile ) raise IOError , ( 'local file error' , 'not on local host' )