Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 75234ea

Browse files
committed
Allow PUT and POST to both send files, move params into files when both types used
1 parent fc74b5a commit 75234ea

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

cli4/cli4.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,14 @@ def process_params_content_files(method, binary_file, args):
9191
except ValueError:
9292
sys.exit('cli4: %s="%s" - can\'t parse json value' % (tag_string, value_string))
9393
elif value_string[0] == '@':
94-
# a file to be uploaded - used in dns_records/import - only via POST
94+
# a file to be uploaded - used in dns_records/import etc - only via PUT or POST
9595
filename = value_string[1:]
96-
if method != 'POST':
97-
sys.exit('cli4: %s=%s - file upload only with POST' % (tag_string, filename))
98-
files = {}
96+
if method not in ['PUT', 'POST']:
97+
sys.exit('cli4: %s=%s - file upload only with PUT or POST' % (tag_string, filename))
98+
if files is None:
99+
files = {}
100+
if tag_string in files:
101+
sys.exit('cli4: %s=%s - duplicate name' % (tag_string, filename))
99102
try:
100103
if filename == '-':
101104
files[tag_string] = sys.stdin
@@ -128,6 +131,15 @@ def process_params_content_files(method, binary_file, args):
128131
sys.exit('cli4: %s=%s - param error. Can\'t mix unnamed and named list' %
129132
(tag_string, value_string))
130133

134+
if content and params:
135+
sys.exit('cli4: content and params not allowed together')
136+
137+
if params and files:
138+
for k,v in params.items():
139+
files[k] = (None, v)
140+
params = None
141+
# sys.exit('cli4: params and files not allowed together')
142+
131143
return (params, content, files)
132144

133145
def run_command(cf, method, command, params=None, content=None, files=None):
@@ -256,10 +268,6 @@ def run_command(cf, method, command, params=None, content=None, files=None):
256268
sys.stderr.write('cli4: /%s - not found\n' % (command))
257269
raise e
258270

259-
if content and params:
260-
sys.stderr.write('cli4: /%s - content and params not allowed together\n' % (command))
261-
raise Exception
262-
263271
results = []
264272
if identifier2 is None:
265273
identifier2 = [None]
@@ -285,7 +293,7 @@ def run_command(cf, method, command, params=None, content=None, files=None):
285293
r = m.put(identifier1=identifier1,
286294
identifier2=i2,
287295
identifier3=identifier3,
288-
data=content)
296+
data=content, files=files)
289297
elif method == 'DELETE':
290298
r = m.delete(identifier1=identifier1,
291299
identifier2=i2,

0 commit comments

Comments
 (0)