Changeset 1813:3167f313bdbf
- Timestamp:
- 10/29/09 13:18:13 (9 months ago)
- Author:
- Ismael Carnales <icarnales@…>
- Branch:
- default
- Message:
-
added dont_click attr to FormRequest?
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r1803
|
r1813
|
|
| 251 | 251 | addition to the standard :class:`Request` methods: |
| 252 | 252 | |
| 253 | | .. classmethod:: FormRequest.from_response(response, [formnumber=0, formdata=None, clickdata=None, ...]) |
| | 253 | .. classmethod:: FormRequest.from_response(response, [formnumber=0, formdata=None, clickdata=None, dont_click=False, ...]) |
| 254 | 254 | |
| 255 | 255 | Returns a new :class:`FormRequest` object with its form field values |
| … |
… |
|
| 276 | 276 | more info. |
| 277 | 277 | :type clickdata: dict |
| | 278 | |
| | 279 | :param dont_click: If True the form data will be sumbitted without |
| | 280 | clicking in any element. |
| | 281 | :type clickdata: bool |
| 278 | 282 | |
| 279 | 283 | The other parameters of this class method are passed directly to the |
-
|
r1802
|
r1813
|
|
| 38 | 38 | |
| 39 | 39 | @classmethod |
| 40 | | def from_response(cls, response, formnumber=0, formdata=None, clickdata=None, **kwargs): |
| | 40 | def from_response(cls, response, formnumber=0, formdata=None, |
| | 41 | clickdata=None, dont_click=False, **kwargs): |
| 41 | 42 | encoding = getattr(response, 'encoding', 'utf-8') |
| 42 | 43 | forms = ParseFile(StringIO(response.body), response.url, |
| … |
… |
|
| 56 | 57 | for v2 in v if hasattr(v, '__iter__') else [v]: |
| 57 | 58 | form.new_control('text', k, {'value': v2}) |
| | 59 | |
| | 60 | if not dont_click: |
| | 61 | url, body, headers = form.click_request_data(**(clickdata or {})) |
| | 62 | else: |
| | 63 | url, body, headers = form._switch_click('request_data') |
| 58 | 64 | |
| 59 | | url, body, headers = form.click_request_data(**(clickdata or {})) |
| 60 | 65 | return cls(url, method=form.method, body=body, headers=headers, **kwargs) |
-
|
r1802
|
r1813
|
|
| 293 | 293 | self.assertEqual(urlargs['two'], ['2']) |
| 294 | 294 | |
| | 295 | def test_from_response_dont_click(self): |
| | 296 | respbody = """ |
| | 297 | <form action="get.php" method="GET"> |
| | 298 | <input type="submit" name="clickeable1" value="clicked1"> |
| | 299 | <input type="hidden" name="one" value="1"> |
| | 300 | <input type="hidden" name="two" value="3"> |
| | 301 | <input type="submit" name="clickeable2" value="clicked2"> |
| | 302 | </form> |
| | 303 | """ |
| | 304 | response = Response("http://www.example.com/this/list.html", body=respbody) |
| | 305 | r1 = self.request_class.from_response(response, dont_click=True) |
| | 306 | urlargs = cgi.parse_qs(urlparse(r1.url).query) |
| | 307 | self.assertFalse('clickeable1' in urlargs, urlargs) |
| | 308 | self.assertFalse('clickeable2' in urlargs, urlargs) |
| | 309 | |
| 295 | 310 | def test_from_response_errors_noform(self): |
| 296 | 311 | respbody = """<html></html>""" |