當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。