Exemplo n.º 1
0
    def _overwrite(self, name, instream, start=None, end=None, append=False):
        file = self._dir[name]
        if append:
            reader = IReadFile(file, None)
            data = reader.read() + instream.read()
        elif start is not None or end is not None:
            reader = IReadFile(file, None)
            data = reader.read()
            if start is not None:
                prefix = data[:start]
            else:
                prefix = ''
                start = 0

            if end is not None:
                l = end - start
                newdata = instream.read(l)
                data = prefix + newdata + data[start+len(newdata):]
            else:
                newdata = instream.read()
                data = prefix + newdata

        else:
            data = instream.read()

        f = IWriteFile(self._dir[name], None)
        f.write(data)
Exemplo n.º 2
0
    def readfile(self, name, outstream, start = 0, end = None):
        file = self._dir[name]
        file = IReadFile(file)
        data = file.read()
        if end is not None:
            data = data[:end]
        if start:
            data = data[start:]

        ## Some output streams don't support unicode data.
        if isinstance(data, unicode):
            data = data.encode('utf-8')

        outstream.write(data)
Exemplo n.º 3
0
    def __call__(self):
        context = self.context
        request = self.request
        response = request.response

        r = []
        url = zapi.absoluteURL(context, request)
        r.append('url:%s' % url)
        adapted = IReadFile(context)

        if hasattr(adapted, 'contentType'):
            # Although IReadFile declares contentType,
            # the default adapter for File doesn't seem
            # to provide it.
            r.append('content_type:%s' % adapted.contentType)

        # There's no such thing as a meta_type
        # in Zope3, so we try to get as far as we can
        # using IContentType, which is a marker interface

        # Had to use removeSecurityProxy because
        # I was getting unauthorized on __iro__
        meta_type = queryType(removeSecurityProxy(context), IContentType)
        if meta_type:
            r.append('meta_type:%s' % meta_type.__name__)

        auth = request._auth

        if auth is not None:
            if auth.endswith('\n'):
                auth = auth[:-1]
            r.append('auth:%s' % auth)

        r.append('cookie:%s' % request._environ.get('HTTP_COOKIE', ''))

        # TODO: Once we have lock, add the lock token here

        r.append('')

        response.setHeader('Pragma', 'no-cache')

        r.append(adapted.read())

        response.setHeader('Content-Type', 'application/x-zope-edit')
        return '\n'.join(r)