示例#1
0
 def params(self):
     """ A :class:`FormsDict` with the combined values of :attr:`query` and
         :attr:`forms`. File uploads are stored in :attr:`files`. """
     params = commons.FormsDict()
     for key, value in self.query.allitems():
         params[key] = value
     for key, value in self.forms.allitems():
         params[key] = value
     return params
示例#2
0
 def query(self):
     ''' The :attr:`query_string` parsed into a :class:`FormsDict`. These
         values are sometimes called "URL arguments" or "GET parameters", but
         not to be confused with "URL wildcards" as they are provided by the
         :class:`Router`. '''
     get = self.environ['bottle.get'] = commons.FormsDict()
     pairs = _parse_qsl(self.environ.get('QUERY_STRING', ''))
     for key, value in pairs:
         get[key] = value
     return get
示例#3
0
    def files(self):
        """ File uploads parsed from `multipart/form-data` encoded POST or PUT
            request body. The values are instances of :class:`FileUpload`.

        """
        files = commons.FormsDict()
        for name, item in self.POST.allitems():
            if isinstance(item, FileUpload):
                files[name] = item
        return files
示例#4
0
 def forms(self):
     """ Form values parsed from an `url-encoded` or `multipart/form-data`
         encoded POST or PUT request body. The result is returned as a
         :class:`FormsDict`. All keys and values are strings. File uploads
         are stored separately in :attr:`files`. """
     forms = commons.FormsDict()
     for name, item in self.POST.allitems():
         if not isinstance(item, FileUpload):
             forms[name] = item
     return forms
示例#5
0
    def POST(self):
        """ The values of :attr:`forms` and :attr:`files` combined into a single
            :class:`FormsDict`. Values are either strings (form values) or
            instances of :class:`cgi.FieldStorage` (file uploads).
        """
        post = commons.FormsDict()
        # We default to application/x-www-form-urlencoded for everything that
        # is not multipart and take the fast path (also: 3.1 workaround)
        if not self.content_type.startswith('multipart/'):
            pairs = _parse_qsl(
                settings.tonat(self._get_body_string(), 'latin1'))
            for key, value in pairs:
                post[key] = value
            return post

        safe_env = {'QUERY_STRING': ''}  # Build a safe environment for cgi
        for key in ('REQUEST_METHOD', 'CONTENT_TYPE', 'CONTENT_LENGTH'):
            if key in self.environ: safe_env[key] = self.environ[key]
        args = dict(fp=self.body, environ=safe_env, keep_blank_values=True)
        if settings.py31:
            args['fp'] = settings.NCTextIOWrapper(args['fp'],
                                                  encoding='utf8',
                                                  newline='\n')
        elif settings.py3k:
            args['encoding'] = 'utf8'
        data = settings.cgi.FieldStorage(**args)
        self[
            '_cgi.FieldStorage'] = data  #http://bugs.python.org/issue18394#msg207958
        data = data.list or []
        for item in data:
            if item.filename:
                post[item.name] = FileUpload(item.file, item.name,
                                             item.filename, item.headers)
            else:
                post[item.name] = item.value
        return post
示例#6
0
 def cookies(self):
     """ Cookies parsed into a :class:`FormsDict`. Signed cookies are NOT
         decoded. Use :meth:`get_cookie` if you expect signed cookies. """
     cookies = settings.SimpleCookie(self.environ.get('HTTP_COOKIE',
                                                      '')).values()
     return commons.FormsDict((c.key, c.value) for c in cookies)