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


Python IStreamIterator.providedBy方法代码示例

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


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

示例1: test_my_avatar

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
    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,代码行数:14,代码来源:test_userprofile.py

示例2: test_my_avatar

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
    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,代码行数:14,代码来源:test_userprofile.py

示例3: setBody

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
    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,代码行数:27,代码来源:HTTPResponse.py

示例4: manage_FTPget

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
 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,代码行数:37,代码来源:filerepresentation.py

示例5: setBody

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
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,代码行数:10,代码来源:functional.py

示例6: setBody

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
 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,代码行数:11,代码来源:WSGIPublisher.py

示例7: setBody

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
 def setBody(self, body, title='', is_error=0, **kw):
     """ Accept either a stream iterator or a string as the body """
     if IStreamIterator.providedBy(body):
         assert('content-length' in self.headers)
         # 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:zopefoundation,项目名称:ZServer,代码行数:12,代码来源:HTTPResponse.py

示例8: test_avatars_view

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
    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,代码行数:17,代码来源:test_userprofile.py

示例9: getWSGIResponse

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
 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,代码行数:17,代码来源:response.py

示例10: test_avatars_view

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
    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,代码行数:18,代码来源:test_userprofile.py

示例11: setBody

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
 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,代码行数:19,代码来源:subresponse.py

示例12: applyTransformOnSuccess

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
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,代码行数:19,代码来源:zpublisher.py

示例13: applyTransformOnSuccess

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
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,代码行数:20,代码来源:zpublisher.py

示例14: manage_FTPget

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
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,代码行数:44,代码来源:WebDAVSupport.py

示例15: applyTransformOnSuccess

# 需要导入模块: from ZPublisher.Iterators import IStreamIterator [as 别名]
# 或者: from ZPublisher.Iterators.IStreamIterator import providedBy [as 别名]
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, six.string_types)\
            or isinstance(transformed, six.binary_type):
        response.setBody(transformed)
    # ... but not with iterables
    else:
        transformed = map(
            lambda it: it.decode('utf-8')
            if isinstance(it, six.binary_type)
            else it,
            transformed
        )
        response.setBody(''.join(transformed))
开发者ID:plone,项目名称:plone.transformchain,代码行数:26,代码来源:zpublisher.py


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