Exemple #1
0
 def _str_POST(self):
     env = self.environ
     if self.method not in ('POST', 'PUT'):
         return NoVars('Not a form request')
     if 'webob._parsed_post_vars' in env:
         vars, body_file = env['webob._parsed_post_vars']
         if body_file is self.body_file_raw:
             return vars
     content_type = self.content_type
     if ((self.method == 'PUT' and not content_type) or content_type
             not in ('', 'application/x-www-form-urlencoded',
                     'multipart/form-data')):
         # Not an HTML form submission
         return NoVars('Not an HTML form submission (Content-Type: %s)' %
                       content_type)
     if self.is_body_seekable:
         self.body_file.seek(0)
     fs_environ = env.copy()
     # FieldStorage assumes a missing CONTENT_LENGTH, but a
     # default of 0 is better:
     fs_environ.setdefault('CONTENT_LENGTH', '0')
     fs_environ['QUERY_STRING'] = ''
     fs = cgi.FieldStorage(fp=self.body_file_raw,
                           environ=fs_environ,
                           keep_blank_values=True)
     vars = MultiDict.from_fieldstorage(fs)
     #ctype = self.content_type or 'application/x-www-form-urlencoded'
     ctype = env.get('CONTENT_TYPE', 'application/x-www-form-urlencoded')
     self.body_file = FakeCGIBody(vars, ctype)
     env['webob._parsed_post_vars'] = (vars, self.body_file_raw)
     return vars
Exemple #2
0
    def DELETE(self):
        if self.method != 'DELETE':
            return NoVars('Not a DELETE request')

        content_type = self.content_type
        if content_type not in ('', 'application/x-www-form-urlencoded',
                                'multipart/form-data'):
            # Not an HTML form submission
            return NoVars('Not an HTML delete submission (Content-Type: %s)' %
                          content_type)

        self._check_charset()
        if self.is_body_seekable:
            self.body_file_raw.seek(0)
        fs_environ = self.environ.copy()

        # FieldStorage assumes a missing CONTENT_LENGTH, but a
        # default of 0 is better:
        fs_environ.setdefault('CONTENT_LENGTH', '0')
        fs_environ['QUERY_STRING'] = ''

        fs = FieldStorage(fp=self.body_file,
                          environ=fs_environ,
                          keep_blank_values=True)
        delete_values = MultiDict.from_fieldstorage(fs)

        ctype = self._content_type_raw or 'application/x-www-form-urlencoded'
        f = FakeCGIBody(delete_values, ctype)
        self.body_file = BufferedReader(f)
        return delete_values
def test_application_site_new_get(users, dummy_request):
    from aarau.views.console.site.form import build_new_application_site_form
    from aarau.views.console.site.action import site_new

    user = users['oswald']
    dummy_request.subdomain = 'console'
    dummy_request.user = user
    dummy_request.params = dummy_request.GET = NestedMultiDict({
        'type':
        'application',
    })
    dummy_request.POST = NoVars()
    project = user.projects[0]
    dummy_request.matchdict = {
        'namespace': project.namespace,
    }

    res = site_new(dummy_request)
    form = build_new_application_site_form(dummy_request)

    assert isinstance(res, Mapping)
    assert ('form', 'project', 'site') == tuple(sorted(res.keys()))
    assert isinstance(res['form'], form.__class__)
    assert project == res['project']
    assert isinstance(res['site'], Site)
Exemple #4
0
def new(request):
    form = NewBlogEntryForm(request.POST or NoVars())
    if request.method == "POST":
        new_pkey = new_entry(form.title.data, form.text.data)
        next_url = request.route_url('detail', pkey=new_pkey)
        return HTTPFound(location=next_url)
    return {'form': form}
Exemple #5
0
    def POST(self):
        """
        A MultiDict containing all the variables from a form
        request. An empty dict-like object for non-form
        requests.

        Form requests are typically POST requests, however PUT requests
        with an appropriate Content-Type are also supported.

        All keys and values are unicode.
        """
        env = self.environ
        if self.method not in ('POST', 'PUT'):
            return NoVars('Not a form request')
        if 'webob._parsed_post_vars' in env:
            vars, body_file = env['webob._parsed_post_vars']
            if body_file is self.body_file_raw:
                return vars
        content_type = self.content_type
        if ((self.method == 'PUT' and not content_type) or content_type
                not in ('', 'application/x-www-form-urlencoded',
                        'multipart/form-data')):
            # Not an HTML form submission
            return NoVars('Not an HTML form submission (Content-Type: %s)' %
                          content_type)
        if self.is_body_seekable:
            self.body_file_raw.seek(0)
        fs_environ = env.copy()
        # FieldStorage assumes a missing CONTENT_LENGTH, but a
        # default of 0 is better:
        fs_environ.setdefault('CONTENT_LENGTH', '0')
        fs_environ['QUERY_STRING'] = ''
        fs = cgi.FieldStorage(fp=self.body_file,
                              environ=fs_environ,
                              keep_blank_values=True)
        vars = MultiDict.from_fieldstorage(fs)
        #ctype = self.content_type or 'application/x-www-form-urlencoded'
        ctype = env.get('CONTENT_TYPE', 'application/x-www-form-urlencoded')
        self.body_file = io.BufferedReader(FakeCGIBody(vars, ctype))
        vars = UnicodeMultiDict(vars,
                                encoding=self.charset,
                                errors=self.unicode_errors)
        env['webob._parsed_post_vars'] = (vars, self.body_file_raw)
        return vars
Exemple #6
0
    def str_POST(self):
        """
        Return a MultiDict containing all the variables from a form
        request. Returns an empty dict-like object for non-form
        requests.

        Form requests are typically POST requests, however PUT requests
        with an appropriate Content-Type are also supported.
        """
        env = self.environ
        if self.method not in ('POST', 'PUT'):
            return NoVars('Not a form request')
        if 'webob._parsed_post_vars' in env:
            vars, body_file = env['webob._parsed_post_vars']
            if body_file is self.body_file:
                return vars
        # Paste compatibility:
        if 'paste.parsed_formvars' in env:
            # from paste.request.parse_formvars
            vars, body_file = env['paste.parsed_formvars']
            if body_file is self.body_file:
                # FIXME: is it okay that this isn't *our* MultiDict?
                return vars
        content_type = self.content_type
        if ';' in content_type:
            content_type = content_type.split(';', 1)[0]
        if (self.method == 'PUT' and not content_type) or \
                content_type not in ('', 'application/x-www-form-urlencoded',
                                     'multipart/form-data'):
            # Not an HTML form submission
            return NoVars('Not an HTML form submission (Content-Type: %s)'
                          % content_type)
        fs_environ = env.copy()
        # FieldStorage assumes a default CONTENT_LENGTH of -1, but a
        # default of 0 is better:
        fs_environ.setdefault('CONTENT_LENGTH', '0')
        fs_environ['QUERY_STRING'] = ''
        fs = cgi.FieldStorage(fp=self.body_file,
                              environ=fs_environ,
                              keep_blank_values=True)
        vars = MultiDict.from_fieldstorage(fs)
        FakeCGIBody.update_environ(env, vars)
        env['webob._parsed_post_vars'] = (vars, self.body_file)
        return vars
Exemple #7
0
    def POST(self):
        if self.method not in ('POST', 'PUT', 'PATCH'):
            return NoVars('Not a form request')

        # Webob puts uploaded files into the POST dictionary, so here we
        # combine the Django POST data and uploaded FILES data into a single
        # dict.
        return NestedMultiDict(
            querydict_to_multidict(self._request.POST),
            querydict_to_multidict(self._request.FILES, wrap=DjangoUploadedFile),
        )
Exemple #8
0
    def test_gets_user(self, db_request):
        email = EmailFactory.create(primary=True)
        user = UserFactory.create(emails=[email])
        project = ProjectFactory.create()
        roles = sorted([RoleFactory(project=project, user=user, role_name="Owner")])
        db_request.matchdict["user_id"] = str(user.id)
        db_request.POST = NoVars()
        result = views.user_detail(db_request)

        assert result["user"] == user
        assert result["roles"] == roles
        assert result["form"].emails[0].primary.data
Exemple #9
0
def test_project_new_get(users, dummy_request):
    from aarau.views.console.project.form import build_new_project_form
    from aarau.views.console.project.action import project_new

    user = users['oswald']
    dummy_request.subdomain = 'console'
    dummy_request.user = user
    dummy_request.params = dummy_request.GET = {}
    # this an assignment is needed to avoid error form building (must be empty)
    dummy_request.POST = NoVars()
    dummy_request.matchdict = {}

    res = project_new(dummy_request)
    form = build_new_project_form(dummy_request)

    assert isinstance(res, Mapping)
    assert ('form',) == tuple(sorted(res.keys()))
    assert isinstance(res['form'], form.__class__)
Exemple #10
0
    def POST(self):
        if self.method not in ('POST', 'PUT', 'PATCH'):
            return NoVars('Not a form request')

        return querydict_to_multidict(self._request.POST)