(self)
| 440 | |
| 441 | class ParseHeaderParameterTests(unittest.TestCase): |
| 442 | def test_basic(self): |
| 443 | tests = [ |
| 444 | ("", ("", {})), |
| 445 | (None, ("", {})), |
| 446 | ("text/plain", ("text/plain", {})), |
| 447 | ("text/vnd.just.made.this.up ; ", ("text/vnd.just.made.this.up", {})), |
| 448 | ("text/plain;charset=us-ascii", ("text/plain", {"charset": "us-ascii"})), |
| 449 | ( |
| 450 | 'text/plain ; charset="us-ascii"', |
| 451 | ("text/plain", {"charset": "us-ascii"}), |
| 452 | ), |
| 453 | ( |
| 454 | 'text/plain ; charset="us-ascii"; another=opt', |
| 455 | ("text/plain", {"charset": "us-ascii", "another": "opt"}), |
| 456 | ), |
| 457 | ( |
| 458 | 'attachment; filename="silly.txt"', |
| 459 | ("attachment", {"filename": "silly.txt"}), |
| 460 | ), |
| 461 | ( |
| 462 | 'attachment; filename="strange;name"', |
| 463 | ("attachment", {"filename": "strange;name"}), |
| 464 | ), |
| 465 | ( |
| 466 | 'attachment; filename="strange;name";size=123;', |
| 467 | ("attachment", {"filename": "strange;name", "size": "123"}), |
| 468 | ), |
| 469 | ( |
| 470 | 'attachment; filename="strange;name";;;;size=123;;;', |
| 471 | ("attachment", {"filename": "strange;name", "size": "123"}), |
| 472 | ), |
| 473 | ( |
| 474 | 'form-data; name="files"; filename="fo\\"o;bar"', |
| 475 | ("form-data", {"name": "files", "filename": 'fo"o;bar'}), |
| 476 | ), |
| 477 | ( |
| 478 | 'form-data; name="files"; filename="\\"fo\\"o;b\\\\ar\\""', |
| 479 | ("form-data", {"name": "files", "filename": '"fo"o;b\\ar"'}), |
| 480 | ), |
| 481 | ] |
| 482 | for header, expected in tests: |
| 483 | with self.subTest(header=header): |
| 484 | self.assertEqual(parse_header_parameters(header), expected) |
| 485 | |
| 486 | def test_rfc2231_parsing(self): |
| 487 | test_data = ( |
nothing calls this directly
no test coverage detected