def __init__(self, data=None, fp=None, length=-1): assert bool(data is not None) ^ bool(fp) if length == -1: if data is not None: length = len(data) else: length = get_size(fp) # can be -1 # We allow writer reuse, but if we're working with a stream, we cannot # seek. Copy the data to a tempfile. if fp and not can_seek(fp): newfp = SpooledTemporaryFile(MAX_INMEMORY_SIZE) sendfile(newfp, fp) length = newfp.tell() newfp.seek(0) fp = newfp self.data = data self.fp = fp self.fpreads = 0 # keep track of fp usage self.length = length assert length >= 0 self.use_tempfile = length > MAX_INMEMORY_SIZE
def __init__(self, data=None, fp=None, enctype=None): """ Specify either file or data. """ assert bool(data) ^ bool(fp) assert enctype in ('none', 'gpg', 'sshrsa') if data: assert isinstance(data, str) # .. and not unicode content = data content_length = len(data) else: content = FileWrapper(fp) content_length = get_size(fp) assert content_length != -1 ctype = 'application/octet-stream' super(EncryptedResponse, self).__init__(content, content_type=ctype) self['Content-Length'] = content_length self['X-Encryption'] = enctype
def __init__(self, data=None, fp=None, length=-1, enctype="none"): assert bool(data is not None) ^ bool(fp) if length == -1: if data is not None: length = len(data) else: length = get_size(fp) # can be -1 # We accept that we can only read it once. # if fp and not can_seek(fp): dont_care() self.data = data self.fp = fp self.fpreads = 0 # keep track of fp usage self.length = fp assert enctype in ("none", "gpg", "sshrsa") self.enctype = enctype self.use_tempfile = length == -1 or length > MAX_INMEMORY_SIZE