当前位置: 首页>>代码示例>>Python>>正文


Python Iterators.IStreamIterator类代码示例

本文整理汇总了Python中ZPublisher.Iterators.IStreamIterator的典型用法代码示例。如果您正苦于以下问题:Python IStreamIterator类的具体用法?Python IStreamIterator怎么用?Python IStreamIterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IStreamIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: manage_FTPget

 def manage_FTPget(self, REQUEST=None, RESPONSE=None):
     """Return the body of the content item in an FTP or WebDAV response.
     
     This adapts self to IRawReadFile(), which is then returned as an
     iterator. The adapter should provide IStreamIterator.
     """
     reader = IRawReadFile(self, None)
     if reader is None:
         return ''
     
     request = REQUEST is not None and REQUEST or self.REQUEST
     response = RESPONSE is not None and RESPONSE or request.response
     
     mimeType = reader.mimeType
     encoding = reader.encoding
     
     if mimeType is not None:
         if encoding is not None:
             response.setHeader('Content-Type', '%s; charset="%s"' % (mimeType, encoding,))
         else:
             response.setHeader('Content-Type', mimeType)
     
     size = reader.size()
     if size is not None:
         response.setHeader('Content-Length', str(size))
     
     # if the reader is an iterator that the publisher can handle, return
     # it as-is. Otherwise, read the full contents
     
     if ((IInterface.providedBy(IStreamIterator) and IStreamIterator.providedBy(reader))
      or (not IInterface.providedBy(IStreamIterator) and IStreamIterator.isImplementedBy(reader))
     ):
         return reader
     else:
         return reader.read()
开发者ID:chaoflow,项目名称:plone.dexterity,代码行数:35,代码来源:filerepresentation.py

示例2: setBody

def setBody(self, body, *args, **kw):
    if IInterface.providedBy(IStreamIterator):  # is this zope 2.12?
        stream = IStreamIterator.providedBy(body)
    else:
        stream = IStreamIterator.isImplementedBy(body)
    if stream:
        body = ''.join(body)    # read from iterator
    return original_setBody(self, body, *args, **kw)
开发者ID:collective,项目名称:collective.testcaselayer,代码行数:8,代码来源:functional.py

示例3: test_my_avatar

    def test_my_avatar(self):
        self.login(self.profile1.username)
        my_avatar = MyAvatar(self.profile1, self.request)
        data = my_avatar()
        self.assertTrue(IStreamIterator.providedBy(data))

        profile_data = my_avatar.avatar_profile()
        self.assertTrue(IStreamIterator.providedBy(profile_data))

        no_avatar = MyAvatar(self.profile2, self.request)
        data = no_avatar()
        self.assertIsNone(data)
开发者ID:smcmahon,项目名称:ploneintranet,代码行数:12,代码来源:test_userprofile.py

示例4: test_my_avatar

    def test_my_avatar(self):
        self.login(self.profile1.username)
        my_avatar = MyAvatar(self.profile1, self.request)
        data = my_avatar()
        self.assertTrue(IStreamIterator.providedBy(data))

        profile_data = my_avatar.avatar_profile()
        self.assertTrue(IStreamIterator.providedBy(profile_data))

        avatar = MyAvatar(self.profile2, self.request)

        self.assertEqual(avatar(), self.default_avatar)
开发者ID:sudhan77,项目名称:ploneintranet,代码行数:12,代码来源:test_userprofile.py

示例5: setBody

    def setBody(self, body, title='', is_error=False, lock=None):
        # allow locking of the body in the same way as the status
        if self._locked_body:
            return

        if isinstance(body, IOBase):
            body.seek(0, 2)
            length = body.tell()
            body.seek(0)
            self.setHeader('Content-Length', '%d' % length)
            self.body = body
        elif IStreamIterator.providedBy(body):
            self.body = body
            super(WSGIResponse, self).setBody(b'', title, is_error)
        elif IUnboundStreamIterator.providedBy(body):
            self.body = body
            self._streaming = 1
            super(WSGIResponse, self).setBody(b'', title, is_error)
        else:
            super(WSGIResponse, self).setBody(body, title, is_error)

        # Have to apply the lock at the end in case the super class setBody
        # is called, which will observe the lock and do nothing
        if lock:
            self._locked_body = 1
开发者ID:zopefoundation,项目名称:Zope,代码行数:25,代码来源:HTTPResponse.py

示例6: applyTransformOnSuccess

def applyTransformOnSuccess(event):
    """Apply the transform after a successful request
    """
    transformed = applyTransform(event.request)
    if transformed is not None:
        response = event.request.response

        # horrid check to deal with Plone 3/Zope 2.10, where this is still an old-style interface
        if ((IInterface.providedBy(IStreamIterator)     and IStreamIterator.providedBy(transformed))
         or (not IInterface.providedBy(IStreamIterator) and IStreamIterator.isImplementedBy(transformed))
        ):
            response.setBody(transformed)
        # setBody() can deal with byte and unicode strings (and will encode as necessary)...
        elif isinstance(transformed, basestring):
            response.setBody(transformed)
        # ... but not with iterables
        else:
            response.setBody(''.join(transformed))
开发者ID:rochecompaan,项目名称:plone.transformchain,代码行数:18,代码来源:zpublisher.py

示例7: setBody

 def setBody(self, body, title='', is_error=0):
     if isinstance(body, file) or IStreamIterator.providedBy(body):
         body.seek(0, 2)
         length = body.tell()
         body.seek(0)
         self.setHeader('Content-Length', '%d' % length)
         self.body = body
     else:
         HTTPResponse.setBody(self, body, title, is_error)
开发者ID:Andyvs,项目名称:TrackMonthlyExpenses,代码行数:9,代码来源:WSGIPublisher.py

示例8: setBody

 def setBody(self, body, title='', is_error=0, **kw):
     """ Accept either a stream iterator or a string as the body """
     if IStreamIterator.isImplementedBy(body):
         assert(self.headers.has_key('content-length'))
         # wrap the iterator up in a producer that medusa can understand
         self._bodyproducer = iterator_producer(body)
         HTTPResponse.setBody(self, '', title, is_error, **kw)
         return self
     else:
         HTTPResponse.setBody(self, body, title, is_error, **kw)
开发者ID:wpjunior,项目名称:proled,代码行数:10,代码来源:HTTPResponse.py

示例9: test_avatars_view

    def test_avatars_view(self):
        self.login(self.profile1.username)
        avatars_view = AvatarsView(self.portal, self.request)
        avatars_view.publishTraverse(self.request, self.profile1.username)

        data = avatars_view()
        self.assertTrue(IStreamIterator.providedBy(data))

        avatars_view.publishTraverse(self.request, self.profile2.username)
        data = avatars_view()
        self.assertIsNone(data)

        avatars_view.publishTraverse(self.request, "not-a-username")
        with self.assertRaises(NotFound):
            avatars_view()
开发者ID:smcmahon,项目名称:ploneintranet,代码行数:15,代码来源:test_userprofile.py

示例10: getWSGIResponse

 def getWSGIResponse(self):
     # This return a tuple (data_sent, data_to_send_to_WSGI)
     result = self.body
     if result is not None:
         # If we have an iterator, we say that data have been sent
         # in order not to commit the transaction finish consuming
         # the iterator.
         if IStreamIterator.providedBy(result):
             return (True, StreamIteratorIterator(result))
         elif IResult.providedBy(result):
             return (True, result)
         if not isinstance(result, str):
             log_invalid_response_data(result, self.__environ)
         return (self.__started, [result,])
     return (self.__started, [])
开发者ID:infrae,项目名称:infrae.wsgi,代码行数:15,代码来源:response.py

示例11: test_avatars_view

    def test_avatars_view(self):
        self.login(self.profile1.username)
        avatars_view = AvatarsView(self.portal, self.request)
        avatars_view.publishTraverse(self.request,
                                     self.profile1.username)

        data = avatars_view()
        self.assertTrue(IStreamIterator.providedBy(data))

        avatars_view.publishTraverse(self.request,
                                     self.profile2.username)
        self.assertEqual(avatars_view(), self.default_avatar)

        avatars_view.publishTraverse(self.request,
                                     'not-a-username')
        self.assertEqual(avatars_view(), self.default_avatar)
开发者ID:sudhan77,项目名称:ploneintranet,代码行数:16,代码来源:test_userprofile.py

示例12: __init__

    def __init__(self, data):
        self.fname = tempfile.mktemp()
        out = open(self.fname, "w+b")
        if isinstance(data, str):
            out.write(data)
            out.flush()
            return
        from ZPublisher.Iterators import IStreamIterator

        if IStreamIterator.isImplementedBy(data):
            for block in data:
                out.write(block)
                block._p_deactivate()
            out.flush()
        else:
            raise ValueError("Don't know how to write data!")
开发者ID:naro,项目名称:zopyx.txng3.core,代码行数:16,代码来源:baseconverter.py

示例13: applyTransformOnSuccess

def applyTransformOnSuccess(event):
    """Apply the transform after a successful request
    """
    transformed = applyTransform(event.request)
    if transformed is None:
        return
    response = event.request.response

    if IStreamIterator.providedBy(transformed):
        response.setBody(transformed)
    # setBody() can deal with byte and unicode strings (and will encode as
    # necessary)...
    elif isinstance(transformed, basestring):
        response.setBody(transformed)
    # ... but not with iterables
    else:
        response.setBody(''.join(transformed))
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:17,代码来源:zpublisher.py

示例14: setBody

 def setBody(self, body, title='', is_error=0, **kw):
     """ Accept either a stream iterator or a string as the body """
     if not IStreamIterator.providedBy(body):
         return HTTPResponse.setBody(self, body, title, is_error, **kw)
     assert not self._wrote
     if isinstance(body, BlobStreamIterator):
         body = body.blob # A BlobFile
     if hasattr(body, 'seek') and hasattr(body, 'read') and hasattr(body, 'close'):
         self.stdout = body
         self._wrote = 1
         return
     try:
         while True:
             chunk = body.next()
             self.write(chunk)
     except StopIteration:
         pass
开发者ID:Vinsurya,项目名称:Plone,代码行数:17,代码来源:subresponse.py

示例15: manage_FTPget

def manage_FTPget(self, REQUEST=None, RESPONSE=None):
    """Get the raw content for this object (also used for the WebDAV source)
    """

    if REQUEST is None:
        REQUEST = self.REQUEST

    if RESPONSE is None:
        RESPONSE = REQUEST.RESPONSE

    if not self.Schema().hasLayer('marshall'):
        RESPONSE.setStatus(501)  # Not implemented
        return RESPONSE

    self.dav__init(REQUEST, RESPONSE)
    collection_check(self)

    marshaller = self.Schema().getLayerImpl('marshall')
    ddata = marshaller.marshall(self, REQUEST=REQUEST, RESPONSE=RESPONSE)
    if (shasattr(self, 'marshall_hook') and self.marshall_hook):
        ddata = self.marshall_hook(ddata)

    content_type, length, data = ddata

    RESPONSE.setHeader('Content-Type', content_type)
    # Only set Content-Length header length is not None. If we want to
    # support 'chunked' Transfer-Encoding we shouldn't set
    # this. However ExternalEditor *expects* it to be set if we return
    # a StreamIterator, so until that gets fixed we must set it.
    if length is not None:
        RESPONSE.setHeader('Content-Length', length)

    if type(data) is type(''):
        return data

    # We assume 'data' is a 'Pdata chain' as used by OFS.File and
    # return a StreamIterator.
    assert length is not None, 'Could not figure out length of Pdata chain'
    if (issubclass(IStreamIterator, Interface) and IStreamIterator.providedBy(data)
            or not issubclass(IStreamIterator, Interface) and IStreamIterator.IsImplementedBy(data)):
        return data
    return PdataStreamIterator(data, length)
开发者ID:seanupton,项目名称:Products.Archetypes,代码行数:42,代码来源:WebDAVSupport.py


注:本文中的ZPublisher.Iterators.IStreamIterator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。