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)
评论列表
文章目录