client.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:ZServer 作者: zopefoundation 项目源码 文件源码
def put(self, file='', content_type='', content_enc='',
            isbin=re.compile(r'[\000-\006\177-\277]').search,
            **kw):
        headers = self.__get_headers(kw)
        filetype = type(file)
        if isinstance(filetype, str) and (isbin(file) is None) and \
           os.path.exists(file):
            ob = open(file, 'rb')
            body = ob.read()
            ob.close()
            c_type, c_enc = guess_type(file)
        elif filetype is FileType:
            body = file.read()
            c_type, c_enc = guess_type(file.name)
        elif isinstance(filetype, str):
            body = file
            c_type, c_enc = guess_type(self.url)
        else:
            raise ValueError('File must be a filename, file or string.')
        content_type = content_type or c_type
        content_enc = content_enc or c_enc
        if content_type:
            headers['Content-Type'] = content_type
        if content_enc:
            headers['Content-Encoding'] = content_enc
        headers['Content-Length'] = str(len(body))
        return self.__snd_request('PUT', self.uri, headers, body)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号