diff options
| author | Tres Seaver <tseaver@palladion.com> | 2013-07-02 00:28:31 -0400 |
|---|---|---|
| committer | Tres Seaver <tseaver@palladion.com> | 2013-07-02 00:28:31 -0400 |
| commit | 27be34831a376e7041983531e0a17af76c06b482 (patch) | |
| tree | 337da6299a7632f1ebb8a36da1bd5d6b8f3f3cc4 | |
| parent | d59440878b67b65e57c91c7b4aa8e7cbf943a729 (diff) | |
| download | pyramid-27be34831a376e7041983531e0a17af76c06b482.tar.gz pyramid-27be34831a376e7041983531e0a17af76c06b482.tar.bz2 pyramid-27be34831a376e7041983531e0a17af76c06b482.zip | |
Allow 'prequest' to send basic auth headers.
Also, allow passing PROPFIND / OPTIONS as methods.
| -rw-r--r-- | pyramid/scripts/prequest.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/pyramid/scripts/prequest.py b/pyramid/scripts/prequest.py index 3d8921b15..874fd1bca 100644 --- a/pyramid/scripts/prequest.py +++ b/pyramid/scripts/prequest.py @@ -1,3 +1,4 @@ +import base64 import optparse import sys import textwrap @@ -29,6 +30,12 @@ class PRequestCommand(object): Use "prequest --method=PATCH config.ini /path < data" to do a PATCH with the given request body. + Use "prequest --method=OPTIONS config.ini /path" to do an + OPTIONS request. + + Use "prequest --method=PROPFIND config.ini /path" to do an + PROPFIND request. + If the path is relative (doesn't begin with "/") it is interpreted as relative to "/". The path passed to this script should be URL-quoted. The path can be succeeded with a query string (e.g. `/path?a=1&=b2'). @@ -66,9 +73,17 @@ class PRequestCommand(object): parser.add_option( '-m', '--method', dest='method', - choices=['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], + choices=['GET', 'HEAD', 'POST', 'PUT', 'PATCH','DELETE', + 'PROPFIND', 'OPTIONS'], type='choice', - help='Request method type', + help='Request method type (GET, POST, PUT, PATCH, DELETE, ' + 'PROPFIND, OPTIONS)', + ) + parser.add_option( + '-l', '--login', + dest='login', + type='string', + help='HTTP basic auth username:password pair', ) get_app = staticmethod(get_app) @@ -99,6 +114,10 @@ class PRequestCommand(object): path = url_unquote(path) headers = {} + if self.options.login: + enc = base64.b64encode(self.options.login.encode('ascii')) + headers['Authorization'] = 'Basic ' + enc.decode('ascii') + if self.options.headers: for item in self.options.headers: if ':' not in item: |
