def __init__(self, client): """ Object constructor. @param (couch.Client) client """ self.type = Stream.TYPE_REQUEST self.httpVersion = "1.0" self.client = client # reset headers (for each "extends" operation, interesting..) self.headers = {} # set default headers self.headers["Host"] = "%s:%s" % (self.client.host, self.client.port) self.headers["Connection"] = "close" self.headers["Accept"] = "application/json" self.headers["Content-Type"] = "application/json" self.headers["User-Agent"] = "%s/v%s (+http://github.com/yay-couch/couch-py)" % \ (couch.Couch.NAME, couch.Couch.VERSION) # set basic authorization header if self.client.username and self.client.password: self.headers["Authorization"] = "Basic "+ \ util.base64Encode(self.client.username +":"+ self.client.password)
def readFile(self, encode = True): """ Read file contents, set attachment data, data length and content type. @param (bool) encode @return (None) @raises (Exception) """ if not self.file: raise Exception("Attachment file is empty!") # detect content type info = util.fileInfo(self.file) self.contentType = info["mime"] data = util.fileGetContents(self.file) self.data = data if encode: self.data = util.base64Encode(data) self.dataLength = len(data)
def readFile(self, encode=True): """ Read file contents, set attachment data, data length and content type. @param (bool) encode @return (None) @raises (Exception) """ if not self.file: raise Exception("Attachment file is empty!") # detect content type info = util.fileInfo(self.file) self.contentType = info["mime"] data = util.fileGetContents(self.file) self.data = data if encode: self.data = util.base64Encode(data) self.dataLength = len(data)