From 27be34831a376e7041983531e0a17af76c06b482 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Tue, 2 Jul 2013 00:28:31 -0400 Subject: Allow 'prequest' to send basic auth headers. Also, allow passing PROPFIND / OPTIONS as methods. --- pyramid/scripts/prequest.py | 23 +++++++++++++++++++++-- 1 file 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: -- cgit v1.2.3