Example #1
0
    def test_dc_from_form_params_without_files_with_multipart_enctype(self):
        form_params = FormParameters()

        form_params.set_form_encoding('multipart/form-data')
        form_params.add_field_by_attr_items([('name', 'a'), ('type', 'text'),
                                             ('value', 'bcd')])

        mpdc = dc_from_form_params(form_params)

        self.assertIsInstance(mpdc, MultipartContainer)
        self.assertEqual(mpdc.get_file_vars(), [])
        self.assertEqual(mpdc['a'], ['bcd'])
    def test_dc_from_form_params_without_files_with_multipart_enctype(self):
        form_params = FormParameters()

        form_params.set_form_encoding('multipart/form-data')
        form_params.add_field_by_attr_items([('name', 'a'),
                               ('type', 'text'),
                               ('value', 'bcd')])

        mpdc = dc_from_form_params(form_params)

        self.assertIsInstance(mpdc, MultipartContainer)
        self.assertEqual(mpdc.get_file_vars(), [])
        self.assertEqual(mpdc['a'], ['bcd'])
Example #3
0
    def _handle_form_tag_start(self, tag, attrs):
        """
        Handle the form tags.

        This method also looks if there are "pending inputs" in the
        self._saved_inputs list and parses them.
        """
        SGMLParser._handle_form_tag_start(self, tag, attrs)

        # Get the 'method'
        method = attrs.get('method', 'GET').upper()

        # Get the action
        action = attrs.get('action', None)
        missing_action = action is None

        # Get the encoding
        form_encoding = attrs.get('enctype', DEFAULT_FORM_ENCODING)

        if missing_action:
            action = self._source_url
        else:
            action = self._decode_url(action)
            try:
                action = self._base_url.url_join(action, encoding=self._encoding)
            except ValueError:
                # The URL in the action is invalid, the best thing we can do
                # is to guess, and our best guess is that the URL will be the
                # current one.
                action = self._source_url

        # Create the form object and store everything for later use
        form_params = FormParameters(encoding=self._encoding)
        form_params.set_method(method)
        form_params.set_action(action)
        form_params.set_form_encoding(form_encoding)
        self._forms.append(form_params)


        # Now I verify if there are any input tags that were found
        # outside the scope of a form tag
        for inputattrs in self._saved_inputs:
            # Parse them just like if they were found AFTER the
            # form tag opening
            if isinstance(inputattrs, dict):
                self._handle_input_tag_inside_form('input', inputattrs)

        # All parsed, remove them.
        self._saved_inputs = []
Example #4
0
    def test_set_form_encoding(self):
        f = FormParameters()
        f.set_form_encoding(DEFAULT_FORM_ENCODING)

        self.assertIs(f.get_form_encoding(), DEFAULT_FORM_ENCODING)
Example #5
0
    def test_set_form_encoding(self):
        f = FormParameters()
        f.set_form_encoding(DEFAULT_FORM_ENCODING)

        self.assertIs(f.get_form_encoding(), DEFAULT_FORM_ENCODING)