當前位置: 首頁>>代碼示例>>Python>>正文


Python SimpleHTTPRequestHandler.send_head方法代碼示例

本文整理匯總了Python中http.server.SimpleHTTPRequestHandler.send_head方法的典型用法代碼示例。如果您正苦於以下問題:Python SimpleHTTPRequestHandler.send_head方法的具體用法?Python SimpleHTTPRequestHandler.send_head怎麽用?Python SimpleHTTPRequestHandler.send_head使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在http.server.SimpleHTTPRequestHandler的用法示例。


在下文中一共展示了SimpleHTTPRequestHandler.send_head方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: send_head

# 需要導入模塊: from http.server import SimpleHTTPRequestHandler [as 別名]
# 或者: from http.server.SimpleHTTPRequestHandler import send_head [as 別名]
 def send_head(self):
     if not self.path.startswith(baseurl):
         self.send_error(404, 'File not found')
         return None
     self.path = self.path[len(baseurl):]
     if not self.path.startswith('/'):
         self.path = '/' + self.path
     return SimpleHTTPRequestHandler.send_head(self)
開發者ID:Bob131,項目名稱:obraz,代碼行數:10,代碼來源:obraz.py

示例2: send_head

# 需要導入模塊: from http.server import SimpleHTTPRequestHandler [as 別名]
# 或者: from http.server.SimpleHTTPRequestHandler import send_head [as 別名]
    def send_head(self):
        if 'Range' not in self.headers:
            self.range = None
            return SimpleHTTPRequestHandler.send_head(self)
        try:
            self.range = parse_byte_range(self.headers['Range'])
        except ValueError as e:
            self.send_error(400, 'Invalid byte range')
            return None
        first, last = self.range

        # Mirroring SimpleHTTPServer.py here
        path = self.translate_path(self.path)
        f = None
        ctype = self.guess_type(path)
        try:
            f = open(path, 'rb')
        except IOError:
            self.send_error(404, 'File not found')
            return None

        fs = os.fstat(f.fileno())
        file_len = fs[6]
        if first >= file_len:
            self.send_error(416, 'Requested Range Not Satisfiable')
            return None

        self.send_response(206)
        self.send_header('Content-type', ctype)
        self.send_header('Accept-Ranges', 'bytes')

        if last is None or last >= file_len:
            last = file_len - 1
        response_length = last - first + 1

        self.send_header('Content-Range',
                         'bytes %s-%s/%s' % (first, last, file_len))
        self.send_header('Content-Length', str(response_length))
        self.send_header('Last-Modified', self.date_time_string(fs.st_mtime))
        self.end_headers()
        return f
開發者ID:berdario,項目名稱:RangeHTTPServer,代碼行數:43,代碼來源:RangeHTTPServer.py


注:本文中的http.server.SimpleHTTPRequestHandler.send_head方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。