コード例 #1
0
ファイル: controller.py プロジェクト: jab/radarpost
def create_mailbox(request):
    if request.method != 'GET':
        res = HttpResponse(status=405)
        res.allow = ['GET']
        return res
    return render_to_response('radar/create_mailbox.html', 
                              TemplateContext(request, {}))
コード例 #2
0
ファイル: controller.py プロジェクト: jab/radarpost
def subscriptions_opml(request, mailbox_slug):
    """
    handles managing feed subscriptions using an OPML 
    document.
    """
    ctx = request.context
    mb = ctx.get_mailbox(mailbox_slug)
    if mb is None:
        return HttpResponse(status=404)

    if request.method == 'GET':
        return HttpResponse(_get_opml(request, mb),
                            status=200,
                            content_type="text/x-opml")

    elif request.method == 'POST':
        return _post_opml(request, mb)

    elif request.method == 'PUT':
        return _put_opml(request, mb)

    else:
        res = HttpResponse(status=405)
        res.allow = ['GET', 'PUT', 'POST']
        return res
コード例 #3
0
ファイル: method.py プロジェクト: danbornside/wsgilite
 def method_not_allowed(self, req):
     """
     Called when an HTTP method is specified in a request for which there is
     no defined httpmethod.  By default, this responds with a 405 Not
     Allowed response.
     """
     resp = Response(status=405)
     resp.allow = self.methods
     return resp
コード例 #4
0
ファイル: controller.py プロジェクト: ltucker/radarpost
def create_mailbox(request):
    if request.method != 'GET':
        res = HttpResponse(status=405)
        res.allow = ['GET']
        return res
    
    ctx = request.context
    if not ctx.user.has_perm(PERM_CREATE_MAILBOX):
        return handle_unauth(request)
        
    return render_to_response('radar/create_mailbox.html', 
                              TemplateContext(request, {}))
コード例 #5
0
ファイル: controller.py プロジェクト: jab/radarpost
def mailbox_rest(request, mailbox_slug):
    if request.method == 'GET' or request.method == 'HEAD':
        return mailbox_exists(request, mailbox_slug)
    elif request.method == 'PUT':
        return create_mailbox(request, mailbox_slug)
    elif request.method == 'POST':
        return update_mailbox(request, mailbox_slug)
    elif request.method == 'DELETE': 
        return delete_mailbox(request, mailbox_slug)
    else: 
        # 405 Not Allowed
        res = HttpResponse(status=405)
        res.allow = ['GET', 'HEAD', 'POST', 'DELETE']
        return res
コード例 #6
0
ファイル: controller.py プロジェクト: jab/radarpost
def user_rest(request, userid):
    """
    REST dispatch for user methods
    """
    if request.method == 'HEAD': 
        return _user_exists(request, userid)
    if request.method == 'GET': 
        return _user_info(request, userid)
    if request.method == 'POST': 
        return _update_user(request, userid)
    if request.method == 'PUT': 
        return _create_user(request, userid)
    if request.method == 'DELETE':
        return _delete_user(request, userid)
    else: 
        res = HttpResponse(status=405)
        res.allow = ['HEAD', 'GET', 'POST', 'GET', 'PUT', 'DELETE']
        return res
コード例 #7
0
def application(req):
    if req.method == 'OPTIONS':
        resp = Response('', content_type='text/plain')
        resp.allow = 'GET,POST,OPTIONS'
        add_access_headers(resp)
        return resp
    script_path = None
    if req.path_info == '/graphs.html':
        # Must redirect
        raise exc.HTTPFound(location='/')
    py_name = None
    ## Rewrite rules:
    if re.match('/api/test/?$', req.path_info):
        req.path_info = '/server/api.cgi'
        req.GET['item'] = 'tests'
    elif re.match(r'/api/test/run/info/?$', req.path_info):
        req.path_info = '/server/api.cgi'
        req.GET['item'] = 'testrun'
    elif re.match(r'/api/test/runs/values/?$', req.path_info):
        req.path_info = '/server/api.cgi'
        req.GET['item'] = 'testrun'
        req.GET['attribute'] = 'values'
    elif re.match(r'/api/test/runs/revisions/?$', req.path_info):
        req.path_info = '/server/api.cgi'
        req.GET['item'] = 'testrun'
        req.GET['attribute'] = 'revisions'
    elif re.match(r'/api/test/runs/latest/?$', req.path_info):
        req.path_info = '/server/api.cgi'
        req.GET['item'] = 'testrun'
        req.GET['id'] = ''  # The RewriteRule doesn't make sense
        req.GET['attribute'] = 'latest'
    elif re.match(r'/api/test/runs?$', req.path_info):
        req.path_info = '/server/api.cgi'
        req.GET['item'] = 'testruns'
    else:
        match = re.match('/api/test/([0-9]+)/?$', req.path_info)
        if match:
            req.path_info = '/server/api.cgi'
            req.GET['item'] = 'test'
            req.GET['id'] = match.group(1)
    if req.path_info_peek() == 'server':
        req.path_info_pop()
        script_path = os.path.join(cgi_scripts, req.path_info.lstrip('/'))
        script_path = os.path.abspath(script_path)
        assert script_path.startswith(cgi_scripts + '/')
        if script_path.endswith('.cgi'):
            py_name = script_path[:-4]
            py_name = os.path.join(os.path.dirname(py_name),
                                   os.path.basename(py_name).replace('-', '_'))
            py_name += '_cgi.py'
            if not os.path.exists(py_name):
                py_name = None
        if (not os.path.isfile(script_path) and py_name is None):
            raise exc.HTTPNotFound('Does not point to a file: %r' %
                                   script_path)
    if script_path is None and py_name is None:
        raise exc.HTTPNotFound()
    if py_name:
        mod_name = os.path.basename(py_name)[:-3].replace('/', '.')
        __import__(mod_name)
        mod = sys.modules[mod_name]
        app = mod.application
    else:
        app = CGIApplication({}, script_path)
    resp = req.get_response(app)
    add_access_headers(resp)
    return resp
コード例 #8
0
ファイル: runner.py プロジェクト: jfsiii/graphs
def application(req):
    if req.method == 'OPTIONS':
        resp = Response('', content_type='text/plain')
        resp.allow = 'GET,POST,OPTIONS'
        add_access_headers(resp)
        return resp
    script_path = None
    if req.path_info == '/graphs.html':
        # Must redirect
        raise exc.HTTPFound(location='/')
    py_name = None
    ## Rewrite rules:
    if re.match('/api/test/?$', req.path_info):
        req.path_info = '/server/api.cgi'
        req.GET['item'] = 'tests'
    elif re.match(r'/api/test/run/info/?$', req.path_info):
        req.path_info = '/server/api.cgi'
        req.GET['item'] = 'testrun'
    elif re.match(r'/api/test/runs/values/?$', req.path_info):
        req.path_info = '/server/api.cgi'
        req.GET['item'] = 'testrun'
        req.GET['attribute'] = 'values'
    elif re.match(r'/api/test/runs/revisions/?$', req.path_info):
        req.path_info = '/server/api.cgi'
        req.GET['item'] = 'testrun'
        req.GET['attribute'] = 'revisions'
    elif re.match(r'/api/test/runs/latest/?$', req.path_info):
        req.path_info = '/server/api.cgi'
        req.GET['item'] = 'testrun'
        req.GET['id'] = ''  # The RewriteRule doesn't make sense
        req.GET['attribute'] = 'latest'
    elif re.match(r'/api/test/runs?$', req.path_info):
        req.path_info = '/server/api.cgi'
        req.GET['item'] = 'testruns'
    else:
        match = re.match('/api/test/([0-9]+)/?$', req.path_info)
        if match:
            req.path_info = '/server/api.cgi'
            req.GET['item'] = 'test'
            req.GET['id'] = match.group(1)
    if req.path_info_peek() == 'server':
        req.path_info_pop()
        script_path = os.path.join(cgi_scripts, req.path_info.lstrip('/'))
        script_path = os.path.abspath(script_path)
        assert script_path.startswith(cgi_scripts + '/')
        if script_path.endswith('.cgi'):
            py_name = script_path[:-4]
            py_name = os.path.join(os.path.dirname(py_name), os.path.basename(py_name).replace('-', '_'))
            py_name += '_cgi.py'
            if not os.path.exists(py_name):
                py_name = None
        if (not os.path.isfile(script_path)
            and py_name is None):
            raise exc.HTTPNotFound('Does not point to a file: %r' % script_path)
    if script_path is None and py_name is None:
        raise exc.HTTPNotFound()
    if py_name:
        mod_name = os.path.basename(py_name)[:-3].replace('/', '.')
        __import__(mod_name)
        mod = sys.modules[mod_name]
        app = mod.application
    else:
        app = CGIApplication({}, script_path)
    resp = req.get_response(app)
    add_access_headers(resp)
    return resp