Skip to content

Commit

Permalink
Added the ability to pass query string parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Basile committed Jul 19, 2012
1 parent c2d70e2 commit 06ea36a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions httpie/__main__.py
Expand Up @@ -41,6 +41,7 @@ def _get_response(args):
# the `Content-Type` for us.
args.headers['Content-Type'] = TYPE_FORM


# Fire the request.
try:
credentials = None
Expand All @@ -61,6 +62,7 @@ def _get_response(args):
proxies=dict((p.key, p.value) for p in args.proxy),
files=args.files,
allow_redirects=args.allow_redirects,
params=args.queries,
)

except (KeyboardInterrupt, SystemExit):
Expand Down
1 change: 1 addition & 0 deletions httpie/cli.py
Expand Up @@ -203,6 +203,7 @@ def _(text):
metavar='ITEM',
type=cliparse.KeyValueType(
cliparse.SEP_COMMON,
cliparse.SEP_QUERY,
cliparse.SEP_DATA,
cliparse.SEP_DATA_RAW_JSON,
cliparse.SEP_FILES
Expand Down
19 changes: 14 additions & 5 deletions httpie/cliparse.py
Expand Up @@ -25,6 +25,7 @@
SEP_DATA = '='
SEP_DATA_RAW_JSON = ':='
SEP_FILES = '@'
SEP_QUERY = '=:'
DATA_ITEM_SEPARATORS = [
SEP_DATA,
SEP_DATA_RAW_JSON,
Expand Down Expand Up @@ -102,6 +103,7 @@ def _guess_method(self, args, stdin_isatty=sys.stdin.isatty()):

item = KeyValueType(
SEP_COMMON,
SEP_QUERY,
SEP_DATA,
SEP_DATA_RAW_JSON,
SEP_FILES).__call__(args.url)
Expand All @@ -118,16 +120,17 @@ def _guess_method(self, args, stdin_isatty=sys.stdin.isatty()):

def _parse_items(self, args):
"""
Parse `args.items` into `args.headers`, `args.data` and `args.files`.
Parse `args.items` into `args.headers`, `args.data`, `args.queries`, and `args.files`.
"""
args.headers = CaseInsensitiveDict()
args.headers['User-Agent'] = DEFAULT_UA
args.data = OrderedDict()
args.files = OrderedDict()
args.queries = CaseInsensitiveDict()
try:
parse_items(items=args.items, headers=args.headers,
data=args.data, files=args.files)
data=args.data, files=args.files, queries=args.queries)
except ParseError as e:
if args.traceback:
raise
Expand Down Expand Up @@ -207,6 +210,8 @@ def __call__(self, string):
if start >= estart and end <= eend:
inside_escape = True
break
if start in found and len(found[start]) > len(sep):
break
if not inside_escape:
found[start] = sep

Expand Down Expand Up @@ -264,19 +269,23 @@ def __call__(self, string):
)


def parse_items(items, data=None, headers=None, files=None):
"""Parse `KeyValueType` `items` into `data`, `headers` and `files`."""
def parse_items(items, data=None, headers=None, files=None, queries=None):
"""Parse `KeyValueType` `items` into `data`, `headers`, `files`, and `queries`."""
if headers is None:
headers = {}
if data is None:
data = {}
if files is None:
files = {}
if queries is None:
queries = {}
for item in items:
value = item.value
key = item.key
if item.sep == SEP_HEADERS:
target = headers
elif item.sep == SEP_QUERY:
target = queries
elif item.sep == SEP_FILES:
try:
value = open(os.path.expanduser(item.value), 'r')
Expand All @@ -301,4 +310,4 @@ def parse_items(items, data=None, headers=None, files=None):

target[key] = value

return headers, data, files
return headers, data, files, queries

0 comments on commit 06ea36a

Please sign in to comment.