Ejemplo n.º 1
0
 def initRequestData(self):
     if self.displayname or self.description or self.timezone:
         # Write XML info to a string
         os = StringIO()
         self.generateXML(os)
         self.request_data = RequestDataString(os.getvalue(),
                                               "text/xml;charset=utf-8")
Ejemplo n.º 2
0
    def updateAttachment(self, rurl, managed_id, filename, data, contentType,
                         return_representation):

        assert (isinstance(rurl, URL))

        # Create WebDAV POST
        rurl.extended = "?action=attachment-update&managed-id=%s" % (
            managed_id, )
        request = Post(self, rurl.relativeURL())
        request.setRequestHeader("Content-Disposition",
                                 "attachment;filename=%s" % (filename, ))
        if return_representation:
            request.setRequestHeader("Prefer", "return-representation")
        dout = RequestDataString(data, contentType)
        request.setData(dout, None)

        # Process it
        self.runSession(request)

        # Check response status
        if request.getStatusCode() not in (
                statuscodes.OK,
                statuscodes.Created,
                statuscodes.NoContent,
        ):
            self.handleHTTPError(request)
Ejemplo n.º 3
0
    def test_Content(self):

        server = Session("www.example.com")
        request = RequestResponse(server, methods.GET, "/")
        rawdata = "Here is some data\r\non multiple lines."
        data = RequestDataString(rawdata, "text/plain")
        request.setData(data, None)
        self.assertEqual(
            request.generateRequestHeader(), """GET / HTTP/1.1
Host: www.example.com
User-Agent: Secret-Agent
Content-Length: %d
Content-Type: text/plain

""".replace("\n", "\r\n") % (len(rawdata), ))
Ejemplo n.º 4
0
    def importData(self, rurl, data, contentType):

        assert (isinstance(rurl, URL))

        # Create WebDAV POST
        request = Post(self, rurl.relativeURL())
        dout = RequestDataString(data, contentType)
        request.setData(dout, None)

        # Process it
        self.runSession(request)

        # Check response status
        if request.getStatusCode() not in (
                statuscodes.OK,
                statuscodes.MultiStatus,
                statuscodes.NoContent,
        ):
            self.handleHTTPError(request)
Ejemplo n.º 5
0
    def writeData(self, rurl, data, contentType, etag=None, method="PUT"):

        assert (isinstance(rurl, URL))

        # Create WebDAV PUT
        if method == "PUT":
            request = Put(self, rurl.relativeURL())
        elif method == "POST":
            request = Post(self, rurl.relativeURL())
        elif method == "OPTIONS":
            request = Options(self, rurl.relativeURL())

        dout = ResponseDataString()

        if data is not None:
            din = RequestDataString(data, contentType)
            if method == "PUT":
                request.setData(din, dout, etag=etag)
            elif method == "POST":
                request.setData(din, dout)
        else:
            request.setData(None, dout)

        # Process it
        self.runSession(request)

        # Check response status
        if request.getStatusCode() not in (
                statuscodes.OK,
                statuscodes.Created,
                statuscodes.NoContent,
        ):
            self.handleHTTPError(request)

        # Return data as a string
        return dout.getData()
Ejemplo n.º 6
0
 def initRequestData(self):
     # Write XML info to a string
     os = StringIO()
     self.generateXML(os)
     self.request_data = RequestDataString(os.getvalue(),
                                           "text/xml;charset=utf-8")