Skip to content

Commit

Permalink
Support posting with @filename syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
hongquan committed Feb 12, 2020
1 parent 93bd09a commit fb5ea10
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions curlipie/curly.py
Expand Up @@ -56,6 +56,7 @@ class CURLArgumentParser(Tap):
form: List[str] = []
data: List[str] = []
data_raw: List[str] = []
data_binary: List[str] = []
user_agent: Optional[str] = None
head: bool = False
get: bool = False
Expand Down Expand Up @@ -106,6 +107,7 @@ def add_arguments(self):
self.add_argument('-H', '--header', nargs='?', action='append')
self.add_argument('-d', '--data', nargs='?', action='append')
self.add_argument('--data-raw', nargs='?', action='append')
self.add_argument('--data-binary', nargs='?', action='append')
self.add_argument('-F', '--form', nargs='?', action='append')
self.add_argument('-A', '--user-agent')
self.add_argument('-I', '--head')
Expand Down
7 changes: 7 additions & 0 deletions curlipie/pie.py
Expand Up @@ -8,6 +8,7 @@

import hh
import attr
from first import first
from .compat import json_dump
from .curly import CURLArgumentParser

Expand Down Expand Up @@ -129,6 +130,12 @@ def curl_to_httpie(cmd: str, long_option: bool = False) -> ConversionResult:
if isinstance(v, (list, dict)):
v = quote(json_dump(v))
cmds.append(f'{qp}:={v}' if not args.get else f'{qp}=={quote(str(v))}')
if args.data_binary:
fn = first(v for v in args.data_binary if v.startswith('@'))
if fn:
# Strip @
fn = fn[1:]
cmds.append(f'@{quote(fn)}')
if args.output:
param = '-o' if not long_option else '--output'
cmds.extend((param, quote(args.output)))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "curlipie"
version = "0.6.2"
version = "0.7.0"
description = "Library to convert cURL command line to HTTPie"
authors = ["Nguyễn Hồng Quân <ng.hong.quan@gmail.com>"]
maintainers = [
Expand Down
4 changes: 4 additions & 0 deletions tests/test_curlipie.py
Expand Up @@ -29,6 +29,10 @@
'app_id=$APP_ID&filename=file.bca" --cacert ~/Desktop/cert.pem',
"http -a '$USER:$PASS' --verify ~/Desktop/cert.pem "
"https://analysiscenter.veracode.com/api/5.0/uploadlargefile.do app_id=='$APP_ID' filename==file.bca"),
('curl --data-binary "@build/veracode.bca" -H "Content-Type: binary/octet-stream" '
'https://analysiscenter.veracode.com/api/5.0/uploadlargefile.do',
'http https://analysiscenter.veracode.com/api/5.0/uploadlargefile.do '
'Content-Type:binary/octet-stream @build/veracode.bca')
)


Expand Down

1 comment on commit fb5ea10

@vercel
Copy link

@vercel vercel bot commented on fb5ea10 Feb 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.