(args=None)
| 25 | |
| 26 | |
| 27 | def parse_args(args=None): |
| 28 | parser = OptionParser( |
| 29 | """usage: %prog [options] mode url [<url2>...] |
| 30 | |
| 31 | mode:\tparallel or serial""" |
| 32 | ) |
| 33 | |
| 34 | # Should be enough that any connection leak will exhaust available file |
| 35 | # descriptors. |
| 36 | parser.add_option( |
| 37 | "-n", |
| 38 | "--nrequests", |
| 39 | type="int", |
| 40 | dest="nrequests", |
| 41 | default=50 * 1000, |
| 42 | help="Number of times to GET the URLs, in total", |
| 43 | ) |
| 44 | |
| 45 | parser.add_option( |
| 46 | "-t", |
| 47 | "--nthreads", |
| 48 | type="int", |
| 49 | dest="nthreads", |
| 50 | default=100, |
| 51 | help="Number of threads with mode 'parallel'", |
| 52 | ) |
| 53 | |
| 54 | parser.add_option( |
| 55 | "-q", |
| 56 | "--quiet", |
| 57 | action="store_false", |
| 58 | dest="verbose", |
| 59 | default=True, |
| 60 | help="Don't print status messages to stdout", |
| 61 | ) |
| 62 | |
| 63 | parser.add_option( |
| 64 | "-c", |
| 65 | "--continue", |
| 66 | action="store_true", |
| 67 | dest="continue_", |
| 68 | default=False, |
| 69 | help="Continue after HTTP errors", |
| 70 | ) |
| 71 | |
| 72 | try: |
| 73 | options, args = parser.parse_args(args or sys.argv[1:]) |
| 74 | mode, urls = args[0], args[1:] |
| 75 | except (ValueError, IndexError): |
| 76 | parser.print_usage() |
| 77 | sys.exit(1) |
| 78 | |
| 79 | if mode not in ("parallel", "serial"): |
| 80 | parser.print_usage() |
| 81 | sys.exit(1) |
| 82 | |
| 83 | return options, mode, urls |
| 84 |
no test coverage detected