def _prep_binary_content(self):
'''
Sets delivery method of either payload or header
Favors Content-Location header if set
Args:
None
Returns:
None: sets attributes in self.binary and headers
'''
# nothing present
if not self.data and not self.location and 'Content-Location' not in self.resource.headers.keys():
raise Exception('creating/updating NonRDFSource requires content from self.binary.data, self.binary.location, or the Content-Location header')
elif 'Content-Location' in self.resource.headers.keys():
logger.debug('Content-Location header found, using')
self.delivery = 'header'
# if Content-Location is not set, look for self.data_location then self.data
elif 'Content-Location' not in self.resource.headers.keys():
# data_location set, trumps Content self.data
if self.location:
# set appropriate header
self.resource.headers['Content-Location'] = self.location
self.delivery = 'header'
# data attribute is plain text, binary, or file-like object
elif self.data:
# if file-like object, set flag for api.http_request
if isinstance(self.data, io.BufferedIOBase):
logger.debug('detected file-like object')
self.delivery = 'payload'
# else, just bytes
else:
logger.debug('detected bytes')
self.delivery = 'payload'
评论列表
文章目录