コード例 #1
0
ファイル: application.py プロジェクト: sahwar/attachix
    def run(request):
        try:
            hostHeader = request.env['HTTP_HOST']
        except KeyError:
            request.setResponseCode(400)
            request.finish()
            return

        try:
            cut = hostHeader.index(':')
            hostHeader = hostHeader[:cut]
        except ValueError:
            pass

        host = "%s:%s:%s" % (hostHeader, request.env['SERVER_PORT'],
                             request.env['SERVER_NAME'])
        fallbackHost = "%s:%s:0.0.0.0" % (hostHeader,
                                          request.env['SERVER_PORT'])

        # define the default host
        vhost = Application.defaultHost[int(request.env['SERVER_PORT'])]
        hostToUse = None
        if Application.lookup.has_key(host):
            hostToUse = host
        elif Application.lookup.has_key(fallbackHost):
            hostToUse = fallbackHost

        if hostToUse:
            vhost = Application.lookup[hostToUse]

        resource = Resolver.getResourceForRequest(request, vhost.root)
        request.env['VHOST'] = {'root': vhost.root, 'host': hostToUse}
        resource.render(request)
        if request.getState() != 3:
            request.finish()
コード例 #2
0
ファイル: application.py プロジェクト: slaff/attachix
    def run(request):
        try:
            hostHeader = request.env['HTTP_HOST']
        except KeyError:
            request.setResponseCode(400)
            request.finish()
            return
            
        try:
            cut = hostHeader.index(':')
            hostHeader = hostHeader[:cut]
        except ValueError:
            pass
        
        host = "%s:%s:%s" % (hostHeader, request.env['SERVER_PORT'], request.env['SERVER_NAME'])
        fallbackHost = "%s:%s:0.0.0.0" % (hostHeader, request.env['SERVER_PORT'])

        # define the default host
        vhost = Application.defaultHost[int(request.env['SERVER_PORT'])]
        hostToUse = None
        if Application.lookup.has_key(host):
            hostToUse = host
        elif Application.lookup.has_key(fallbackHost):
            hostToUse = fallbackHost

        if hostToUse:
            vhost = Application.lookup[hostToUse]

        resource = Resolver.getResourceForRequest(request, vhost.root)
        request.env['VHOST'] = {
            'root': vhost.root,
            'host': hostToUse
        }
        resource.render(request)
        if request.getState()!=3:
            request.finish()
コード例 #3
0
ファイル: resource.py プロジェクト: slaff/attachix
    def testTokenResource(self):
        vhost = token.VHost(self.config)
        vhost.load()
        vhost.build()

        properties = {
            '{custom-namespace:}test': 'value'
        }

        # [Patch properties] #
        uri = "/"+self.cipher.encode(['PROPFIND','PROPPATCH'], 1, '/tmp', [], 0)
        data = """<?xml version="1.0"?>
<d:propertyupdate xmlns:d="DAV:">
  <d:set>
    <d:prop>"""
        for property, value in properties.items():
            nameSpace = "system:" # the default namespace
            if property[0] == '{':
                pos = property.find('}')
                nameSpace = property[1:pos]
                key = property[pos + 1:]
            else:
                key = property[0]
            
            data += "<%s xmlns=\"%s\">%s</%s>" % (key, nameSpace, value, key)

        data += """
        </d:prop>
    </d:set>
</d:propertyupdate>"""

        env = {
            'REQUEST_METHOD': 'PROPPATCH',
            'wsgi.input': StringIO.StringIO(data),
            'cache': {}
        }
        request = BaseRequest(uri, env)
        resource = Resolver.getResourceForRequest(request, vhost.root)
        resource.render(request)

        self.assertEquals(request._responseCode,207, request.getResponseBody())

        # [Find properties] #
        data = """<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:">
    <d:prop>"""
        for property, value in properties.items():
            nameSpace = "system:" # the default namespace
            if property[0] == '{':
                pos = property.find('}')
                nameSpace = property[1:pos]
                key = property[pos + 1:]
            else:
                key = property[0]

            data += "<%s xmlns=\"%s\" />" % (key, nameSpace)

        data += """</d:prop>
</d:propfind xmlns:d="DAV:">
        """
        
        env = {
            'REQUEST_METHOD': 'PROPFIND',
            'HTTP_DEPTH': '0',
            'wsgi.input': StringIO.StringIO(data),
            'cache': {}
        }

        request = BaseRequest(uri, env)
        resource = Resolver.getResourceForRequest(request, vhost.root)
        resource.render(request)

        self.assertEquals(request._responseCode,207, request.getResponseBody())
コード例 #4
0
    def testTokenResource(self):
        vhost = token.VHost(self.config)
        vhost.load()
        vhost.build()

        properties = {'{custom-namespace:}test': 'value'}

        # [Patch properties] #
        uri = "/" + self.cipher.encode(['PROPFIND', 'PROPPATCH'], 1, '/tmp',
                                       [], 0)
        data = """<?xml version="1.0"?>
<d:propertyupdate xmlns:d="DAV:">
  <d:set>
    <d:prop>"""
        for property, value in properties.items():
            nameSpace = "system:"  # the default namespace
            if property[0] == '{':
                pos = property.find('}')
                nameSpace = property[1:pos]
                key = property[pos + 1:]
            else:
                key = property[0]

            data += "<%s xmlns=\"%s\">%s</%s>" % (key, nameSpace, value, key)

        data += """
        </d:prop>
    </d:set>
</d:propertyupdate>"""

        env = {
            'REQUEST_METHOD': 'PROPPATCH',
            'wsgi.input': StringIO.StringIO(data),
            'cache': {}
        }
        request = BaseRequest(uri, env)
        resource = Resolver.getResourceForRequest(request, vhost.root)
        resource.render(request)

        self.assertEquals(request._responseCode, 207,
                          request.getResponseBody())

        # [Find properties] #
        data = """<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:">
    <d:prop>"""
        for property, value in properties.items():
            nameSpace = "system:"  # the default namespace
            if property[0] == '{':
                pos = property.find('}')
                nameSpace = property[1:pos]
                key = property[pos + 1:]
            else:
                key = property[0]

            data += "<%s xmlns=\"%s\" />" % (key, nameSpace)

        data += """</d:prop>
</d:propfind xmlns:d="DAV:">
        """

        env = {
            'REQUEST_METHOD': 'PROPFIND',
            'HTTP_DEPTH': '0',
            'wsgi.input': StringIO.StringIO(data),
            'cache': {}
        }

        request = BaseRequest(uri, env)
        resource = Resolver.getResourceForRequest(request, vhost.root)
        resource.render(request)

        self.assertEquals(request._responseCode, 207,
                          request.getResponseBody())