Exemplo n.º 1
0
    def testMultipleUpload(self):
        return self.doTest(
            'xyz', """--xyz\r
Content-Disposition: form-data; name="foo"\r
\r
Foo Bar\r
--xyz\r
Content-Disposition: form-data; name="foo"\r
\r
Baz\r
--xyz\r
Content-Disposition: form-data; name="file"; filename="filename"\r
Content-Type: text/html\r
\r
blah\r
--xyz\r
Content-Disposition: form-data; name="file"; filename="filename"\r
Content-Type: text/plain\r
\r
bleh\r
--xyz--\r
""", {'foo': ['Foo Bar', 'Baz']}, {
                'file': [('filename', MimeType('text', 'html'), "blah"),
                         ('filename', MimeType('text', 'plain'), "bleh")]
            })
Exemplo n.º 2
0
class XCAPAttribute(XCAPResource):

    content_type = MimeType.fromString("application/xcap-att+xml")

    def contentType(self):
        return self.content_type

    def http_GET(self, request):
        d = self.application.get_attribute(
            self.xcap_uri, lambda e: self.checkEtag(request, e))
        return d

    def http_DELETE(self, request):
        d = self.application.delete_attribute(
            self.xcap_uri, lambda e: self.checkEtag(request, e))
        return d

    def http_PUT(self, request):
        content_type = request.headers.getHeader('content-type')
        if not content_type or content_type != self.content_type:
            raise http.HTTPError(responsecode.UNSUPPORTED_MEDIA_TYPE)
        attribute = request.attachment
        d = self.application.put_attribute(
            self.xcap_uri, attribute, lambda e: self.checkEtag(request, e))
        return d
Exemplo n.º 3
0
    def __init__(self, code, error):
        """
        @param code: a response code.
        @param error: an L{davxml.WebDAVElement} identifying the error, or a
            tuple C{(namespace, name)} with which to create an empty element
            denoting the error.  (The latter is useful in the case of
            preconditions ans postconditions, not all of which have defined
            XML element classes.)
        """
        if type(error) is tuple:
            xml_namespace, xml_name = error

            class EmptyError(davxml.WebDAVEmptyElement):
                namespace = xml_namespace
                name = xml_name

            error = EmptyError()

        output = davxml.Error(error).toxml()

        Response.__init__(self, code=code, stream=output)

        self.headers.setHeader("content-type", MimeType("text", "xml"))

        self.error = error
Exemplo n.º 4
0
class XCAPNamespaceBinding(XCAPResource):

    content_type = MimeType.fromString("application/xcap-ns+xml")

    def contentType(self):
        return self.content_type

    def http_GET(self, request):
        d = self.application.get_ns_bindings(
            self.xcap_uri, lambda e: self.checkEtag(request, e))
        return d
Exemplo n.º 5
0
    def __init__(self, xml_responses):
        """
        @param xml_responses: an interable of davxml.Response objects.
        """
        multistatus = davxml.MultiStatus(*xml_responses)
        output = multistatus.toxml()

        Response.__init__(self,
                          code=responsecode.MULTI_STATUS,
                          stream=davxml.MultiStatus(*xml_responses).toxml())

        self.headers.setHeader("content-type", MimeType("text", "xml"))
Exemplo n.º 6
0
    def testEmptyFilename(self):
        return self.doTest(
            'curlPYafCMnsamUw9kSkJJkSen41sAV',
            """--curlPYafCMnsamUw9kSkJJkSen41sAV\r
cONTENT-tYPE: application/octet-stream\r
cONTENT-dISPOSITION: FORM-DATA; NAME="foo"; FILENAME=""\r
\r
qwertyuiop\r
--curlPYafCMnsamUw9kSkJJkSen41sAV--\r
""", {}, {
                'foo': [('', MimeType('application',
                                      'octet-stream'), "qwertyuiop")]
            })
Exemplo n.º 7
0
    def testStupidFilename(self):
        return self.doTest(
            '----------0xKhTmLbOuNdArY', """------------0xKhTmLbOuNdArY\r
Content-Disposition: form-data; name="file"; filename="foo"; name="foobar.txt"\r
Content-Type: text/plain\r
\r
Contents of a file
blah
blah\r
------------0xKhTmLbOuNdArY--\r
""", {}, {
                'file': [('foo"; name="foobar.txt', MimeType(
                    'text', 'plain'), "Contents of a file\nblah\nblah")]
            })
Exemplo n.º 8
0
    def testNormalUpload(self):
        return self.doTest(
            '---------------------------155781040421463194511908194298',
            """-----------------------------155781040421463194511908194298\r
Content-Disposition: form-data; name="foo"\r
\r
Foo Bar\r
-----------------------------155781040421463194511908194298\r
Content-Disposition: form-data; name="file"; filename="filename"\r
Content-Type: text/html\r
\r
Contents of a file
blah
blah\r
-----------------------------155781040421463194511908194298--\r
""", {'foo': ['Foo Bar']}, {
                'file': [('filename', MimeType(
                    'text', 'html'), "Contents of a file\nblah\nblah")]
            })
Exemplo n.º 9
0
    def update_from_factory (self, content, factory, ) :
        self.status = factory.status
        self.headers = factory.response_headers

        _mt = MimeType.fromString(self.headers.get("content-type", ["", ])[0], )
        if _mt :
            _mt = "/".join((_mt.mediaType, _mt.mediaSubtype, ), )

        if not _mt :
            _mt = _mimetypes.get_mimetype_from_filename(self.url, )

        if not _mt :
            _mt = "text/html"

        self.mimetype = _mt

        if content :
            _ce = self.headers.get("content-encoding")
            if _ce and "gzip" in self.headers.get("content-encoding") :
                with gzip.GzipFile(fileobj=StringIO.StringIO(content, ), ) as _gz :
                    content = _gz.read()

        self.content = content
Exemplo n.º 10
0
 def contentType(self):
     try:
         return MimeType.fromString(self.application.mime_type)
     except TypeError:
         return None
Exemplo n.º 11
0
 def contentType(self):
     try:
         return MimeType.fromString(self.application.mime_type)
     except TypeError:
         return None
Exemplo n.º 12
0
 def mimeType(self):
     return MimeType.fromString(str(self))