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


Python SimpleRequest.stream方法代码示例

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


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

示例1: test_Quota_DELETE

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
    def test_Quota_DELETE(self):
        """
        Quota change on DELETE
        """
        dst_uri = "/dst"

        def checkPUTResult(response):
            response = IResponse(response)

            if response.code != responsecode.CREATED:
                self.fail("Incorrect response code for PUT (%s != %s)"
                          % (response.code, responsecode.CREATED))

            def doDelete(_ignore):
                def checkDELETEResult(response):
                    response = IResponse(response)

                    if response.code != responsecode.NO_CONTENT:
                        self.fail("Incorrect response code for PUT (%s != %s)"
                                  % (response.code, responsecode.NO_CONTENT))

                    return self.checkQuota(0)

                request = SimpleRequest(self.site, "DELETE", dst_uri)
                return self.send(request, checkDELETEResult)

            d = self.checkQuota(100)
            d.addCallback(doDelete)
            return d

        request = SimpleRequest(self.site, "PUT", dst_uri)
        request.stream = FileStream(file(os.path.join(os.path.dirname(__file__), "data", "quota_100.txt"), "rb"))
        return self.send(request, checkPUTResult)
开发者ID:anemitz,项目名称:calendarserver,代码行数:35,代码来源:test_quota.py

示例2: test_Quota_Bad_Adjustment

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
    def test_Quota_Bad_Adjustment(self):
        """
        Quota adjustment too much
        """
        dst_uri = "/dst"

        def checkPUTResult(response):
            response = IResponse(response)

            if response.code != responsecode.CREATED:
                self.fail("Incorrect response code for PUT (%s != %s)"
                          % (response.code, responsecode.CREATED))

            def doBadAdjustment(_ignore):
                def checkAdjustmentResult(_ignore):
                    return self.checkQuota(100)

                d = self.site.resource.quotaSizeAdjust(None, -200)
                d.addCallback(checkAdjustmentResult)
                return d

            d = self.checkQuota(100)
            d.addCallback(doBadAdjustment)
            return d

        request = SimpleRequest(self.site, "PUT", dst_uri)
        request.stream = FileStream(file(os.path.join(os.path.dirname(__file__), "data", "quota_100.txt"), "rb"))
        return self.send(request, checkPUTResult)
开发者ID:anemitz,项目名称:calendarserver,代码行数:30,代码来源:test_quota.py

示例3: addEventsDir

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
def addEventsDir(testCase, eventsDir, uri):
    """
    Add events to a L{HomeTestCase} from a directory.

    @param testCase: The test case to add events to.
    @type testCase: L{HomeTestCase}

    @param eventsDir: A directory full of events.
    @type eventsDir: L{FilePath}

    @param uri: The URI-path of the calendar to insert events into.
    @type uri: C{str}

    @return: a L{Deferred} which fires with the number of added calendar object
        resources.
    """
    count = 0
    for child in eventsDir.children():
        count += 1
        if child.basename().split(".")[-1] != "ics":
            continue
        request = SimpleRequest(testCase.site, "PUT",
                                uri + "/" + child.basename())
        request.stream = MemoryStream(child.getContent())
        yield testCase.send(request)
    returnValue(count)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:28,代码来源:test_calendarquery.py

示例4: do_report

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
        def do_report(response):
            response = IResponse(response)

            if response.code != responsecode.CREATED:
                self.fail("MKCOL failed: %s" % (response.code,))

            # Add vCards to addressbook
            # We're cheating by simply copying the files in
            for filename in os.listdir(self.vcards_dir):
                if os.path.splitext(filename)[1] != ".vcf": continue
                path = os.path.join(self.vcards_dir, filename)
                shutil.copy(path, addressbook_path)

            # Delete the index because we cheated
            index_path = os.path.join(addressbook_path, db_basename)
            if os.path.isfile(index_path): os.remove(index_path)

            request = SimpleRequest(self.site, "REPORT", addressbook_uri)
            request.stream = MemoryStream(query.toxml())

            def do_test(response):
                response = IResponse(response)

                if response.code != responsecode.MULTI_STATUS:
                    self.fail("REPORT failed: %s" % (response.code,))

                return davXMLFromStream(response.stream).addCallback(got_xml)

            return self.send(request, do_test)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:31,代码来源:test_addressbookquery.py

示例5: do_report

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
        def do_report(response):
            response = IResponse(response)

            if response.code != responsecode.CREATED:
                self.fail("MKCALENDAR failed: %s" % (response.code,))

            # Add holiday events to calendar
            # We're cheating by simply copying the files in
            for filename in os.listdir(self.holidays_dir):
                if os.path.splitext(filename)[1] != ".ics": continue
                path = os.path.join(self.holidays_dir, filename)
                shutil.copy(path, calendar_path)

            # Delete the index because we cheated
            index_path = os.path.join(calendar_path, db_basename)
            if os.path.isfile(index_path): os.remove(index_path)

            request = SimpleRequest(self.site, "REPORT", calendar_uri)
            request.stream = MemoryStream(query.toxml())

            def do_test(response):
                response = IResponse(response)

                if response.code != responsecode.OK:
                    self.fail("REPORT failed: %s" % (response.code,))

                return Component.fromIStream(response.stream).addCallback(got_calendar)

            return self.send(request, do_test, calendar_path)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:31,代码来源:test_freebusyquery.py

示例6: mkcalendar_cb

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
        def mkcalendar_cb(response):
            response = IResponse(response)

            if response.code != responsecode.CREATED:
                self.fail("MKCALENDAR failed: %s" % (response.code,))

            if not calPath.isdir():
                self.fail("MKCALENDAR did not create a collection")

            ds = []
            c = 0

            for stream, response_code in work:
                def put_cb(response, stream=stream, response_code=response_code):
                    response = IResponse(response)

                    if response.code != response_code:
                        self.fail("Incorrect response to %s: %s (!= %s)" % (what, response.code, response_code))

                dst_uri = "/".join([calendar_uri, "dst%d.ics" % (c,)])
                request = SimpleRequest(self.site, "PUT", dst_uri)
                request.headers.setHeader("if-none-match", "*")
                request.headers.setHeader("content-type", MimeType("text", "calendar"))
                request.stream = stream
                ds.append(self.send(request, put_cb))

                c += 1

            return DeferredList(ds)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:31,代码来源:test_collectioncontents.py

示例7: _simple_PROPPATCH

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
    def _simple_PROPPATCH(self, patch, prop, expected_code, what):
        def check_result(response):
            response = IResponse(response)

            if response.code != responsecode.MULTI_STATUS:
                self.fail("Incorrect response code for PROPPATCH (%s != %s)"
                          % (response.code, responsecode.MULTI_STATUS))

            return davXMLFromStream(response.stream).addCallback(check_xml)

        def check_xml(doc):
            response = doc.root_element.childOfType(davxml.Response)
            propstat = response.childOfType(davxml.PropertyStatus)

            self.failUnless(
                response.childOfType(davxml.HRef) == "/",
                "Incorrect response URI: %s != /" % (response.childOfType(davxml.HRef),)
            )

            self.failIf(
                propstat.childOfType(davxml.PropertyContainer).childOfType(prop) is None,
                "Not a %s in PROPPATCH property status: %s" % (prop.sname(), propstat.toxml())
            )

            self.failUnless(
                propstat.childOfType(davxml.Status).code == expected_code,
                "Incorrect status code for PROPPATCH %s: %s != %s"
                % (what, propstat.childOfType(davxml.Status).code, expected_code)
            )

        request = SimpleRequest(self.site, "PROPPATCH", "/")
        request.stream = MemoryStream(patch.toxml())
        return self.send(request, check_result)
开发者ID:jrossi,项目名称:twext,代码行数:35,代码来源:test_prop.py

示例8: mkcalendar_cb

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
        def mkcalendar_cb(response):
            response = IResponse(response)

            if response.code != responsecode.CREATED:
                self.fail("MKCALENDAR failed: %s" % (response.code,))

            def propfind_cb(response):
                response = IResponse(response)

                if response.code != responsecode.MULTI_STATUS:
                    self.fail("Incorrect response to PROPFIND: %s" % (response.code,))

                def got_xml(doc):
                    if not isinstance(doc.root_element, davxml.MultiStatus):
                        self.fail("PROPFIND response XML root element is not multistatus: %r" % (doc.root_element,))

                    response = doc.root_element.childOfType(davxml.Response)
                    href = response.childOfType(davxml.HRef)
                    self.failUnless(str(href) == calendar_uri)

                    container = response.childOfType(davxml.PropertyStatus).childOfType(davxml.PropertyContainer)

                    #
                    # Check CalDAV:supported-calendar-component-set
                    #

                    supported_components = container.childOfType(caldavxml.SupportedCalendarComponentSet)
                    if supported_components:
                        self.fail("CalDAV:supported-calendar-component-set element was returned; but should be hidden.")

                    #
                    # Check CalDAV:supported-calendar-data
                    #

                    supported_calendar = container.childOfType(caldavxml.SupportedCalendarData)
                    if supported_calendar:
                        self.fail("CalDAV:supported-calendar-data elementwas returned; but should be hidden.")

                    #
                    # Check DAV:supported-report-set
                    #

                    supported_reports = container.childOfType(davxml.SupportedReportSet)
                    if supported_reports:
                        self.fail("DAV:supported-report-set element was returned; but should be hidden..")

                return davXMLFromStream(response.stream).addCallback(got_xml)

            query = davxml.PropertyFind(
                davxml.AllProperties(),
            )

            request = SimpleRequest(
                self.site,
                "PROPFIND",
                calendar_uri,
                headers=http_headers.Headers({"Depth":"0"}),
            )
            request.stream = MemoryStream(query.toxml())
            return self.send(request, propfind_cb)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:62,代码来源:test_props.py

示例9: work

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
        def work():
            for code in (
                responsecode.CREATED,
                responsecode.PRECONDITION_FAILED,
                responsecode.NO_CONTENT,
                responsecode.PRECONDITION_FAILED,
                responsecode.NO_CONTENT,
                responsecode.CREATED,
            ):
                def checkResult(response, code=code):
                    response = IResponse(response)

                    if response.code != code:
                        self.fail("Incorrect response code for PUT (%s != %s)"
                                  % (response.code, code))

                def onError(f):
                    f.trap(HTTPError)
                    return checkResult(f.value.response)

                request = SimpleRequest(self.site, "PUT", dst_uri)
                request.stream = FileStream(file(__file__, "rb"))
    
                if code == responsecode.CREATED:
                    if os.path.isfile(dst_path):
                        os.remove(dst_path)
                    request.headers.setHeader("if-none-match", ("*",))
                elif code == responsecode.PRECONDITION_FAILED:
                    request.headers.setHeader("if-none-match", ("*",))
    
                yield (request, (checkResult, onError))
开发者ID:jrossi,项目名称:twext,代码行数:33,代码来源:test_put.py

示例10: mkcalendar_cb

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
        def mkcalendar_cb(response):
            response = IResponse(response)

            if response.code != responsecode.CREATED:
                self.fail("MKCALENDAR failed: %s" % (response.code,))

            def put_cb(response):
                response = IResponse(response)

                if response.code != responsecode.FORBIDDEN:
                    self.fail("Incorrect response to dot file PUT: %s" % (response.code,))

            stream = self.dataPath.child(
                "Holidays").child(
                "C318AA54-1ED0-11D9-A5E0-000A958A3252.ics"
            ).open()
            try: calendar = str(Component.fromStream(stream))
            finally: stream.close()

            event_uri = "/".join([calendar_uri, ".event.ics"])

            request = SimpleRequest(self.site, "PUT", event_uri)
            request.headers.setHeader("content-type", MimeType("text", "calendar"))
            request.stream = MemoryStream(calendar)
            return self.send(request, put_cb)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:27,代码来源:test_collectioncontents.py

示例11: work

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
        def work():
            for method in ("GET", "REPORT"):
                if method == "GET":
                    ok = responsecode.OK
                elif method == "REPORT":
                    ok = responsecode.MULTI_STATUS
                else:
                    raise AssertionError("We shouldn't be here.  (method = %r)" % (method,))

                for name, code in (
                    ("none"       , responsecode.FORBIDDEN),
                    ("read"       , ok),
                    ("read-write" , ok),
                    ("unlock"     , responsecode.FORBIDDEN),
                    ("all"        , ok),
                ):
                    path = os.path.join(self.docroot, name)

                    request = SimpleRequest(self.site, method, "/" + name)
                    if method == "REPORT":
                        request.stream = MemoryStream(element.PrincipalPropertySearch().toxml())

                    _add_auth_header(request)

                    def test(response, code=code, path=path):
                        if response.code != code:
                            return self.oops(request, response, code, method, name)

                    yield (request, test)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:31,代码来源:test_acl.py

示例12: _doPOST

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
    def _doPOST(self, body, resultcode = responsecode.OK):
        request = SimpleRequest(self.site, "POST", "/calendar/")
        request.headers.setHeader("content-type", MimeType("text", "xml"))
        request.stream = MemoryStream(body)

        response = (yield self.send(request, None))
        self.assertEqual(response.code, resultcode)
        returnValue(response)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:10,代码来源:test_sharing.py

示例13: work

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
        def work():
            for which in (davxml.AllProperties(), davxml.PropertyName()):
                query = davxml.PropertyFind(which)

                request = SimpleRequest(self.site, "PROPFIND", "/")
                request.headers.setHeader("depth", "0")
                request.stream = MemoryStream(query.toxml())

                yield (request, check_result(which))
开发者ID:jrossi,项目名称:twext,代码行数:11,代码来源:test_prop.py

示例14: test_free_busy_set_prop

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
    def test_free_busy_set_prop(self):
        """
        Test for PROPFIND on Inbox with missing calendar-free-busy-set property.
        """

        inbox_uri = "/inbox/"

        def propfind_cb(response):
            response = IResponse(response)

            if response.code != responsecode.MULTI_STATUS:
                self.fail("Incorrect response to PROPFIND: %s" % (response.code,))

            def got_xml(doc):
                if not isinstance(doc.root_element, davxml.MultiStatus):
                    self.fail("PROPFIND response XML root element is not multistatus: %r" % (doc.root_element,))

                response = doc.root_element.childOfType(davxml.Response)
                href = response.childOfType(davxml.HRef)
                self.failUnless(str(href) == inbox_uri)

                for propstat in response.childrenOfType(davxml.PropertyStatus):
                    status = propstat.childOfType(davxml.Status)
                    if status.code != responsecode.OK:
                        self.fail("Unable to read requested properties (%s): %r"
                                  % (status, propstat.childOfType(davxml.PropertyContainer).toxml()))

                container = propstat.childOfType(davxml.PropertyContainer)

                #
                # Check CalDAV:calendar-free-busy-set
                #

                free_busy_set = container.childOfType(caldavxml.CalendarFreeBusySet)
                if not free_busy_set:
                    self.fail("Expected CalDAV:calendar-free-busy-set element; but got none.")

                if not free_busy_set.children:
                    self.fail("Expected non-empty CalDAV:calendar-free-busy-set element.")

            return davXMLFromStream(response.stream).addCallback(got_xml)

        query = davxml.PropertyFind(
                    davxml.PropertyContainer(
                        caldavxml.CalendarFreeBusySet(),
                    ),
                )

        request = SimpleRequest(
            self.site,
            "PROPFIND",
            inbox_uri,
            headers=http_headers.Headers({"Depth": "0"}),
        )
        request.stream = MemoryStream(query.toxml())
        return self.send(request, propfind_cb)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:58,代码来源:test_resource.py

示例15: test_REPORT_no_body

# 需要导入模块: from twext.web2.test.test_server import SimpleRequest [as 别名]
# 或者: from twext.web2.test.test_server.SimpleRequest import stream [as 别名]
    def test_REPORT_no_body(self):
        """
        REPORT request with no body
        """
        def do_test(response):
            response = IResponse(response)

            if response.code != responsecode.BAD_REQUEST:
                self.fail("Unexpected response code for REPORT with no body: %s"
                          % (response.code,))

        request = SimpleRequest(self.site, "REPORT", "/")
        request.stream = MemoryStream("")

        return self.send(request, do_test)
开发者ID:jrossi,项目名称:twext,代码行数:17,代码来源:test_report.py


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