Skip to content

Commit 397335a

Browse files
update upload_file method to allow query params and fix file upload
1 parent b691826 commit 397335a

File tree

1 file changed

+95
-1
lines changed

1 file changed

+95
-1
lines changed

src/sasctl/_services/cas_management.py

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ def upload_file(
252252
server: str = None,
253253
header: bool = None,
254254
format_: str = None,
255+
*,
256+
detail: dict = None
255257
):
256258
"""Upload a file to a CAS table.
257259
@@ -275,6 +277,13 @@ def upload_file(
275277
format_ : {"csv", "xls", "xlsx", "sas7bdat", "sashdat"}, optional
276278
File of input `file`. Not required if format can be discerned from
277279
the file path.
280+
detail : dict, optional
281+
Additional body parameters. Allowed parameters are
282+
'sessionId', 'variables', 'label', 'scope', 'replace', 'encoding',
283+
'allowTruncation', 'allowEmbeddedNewLines', 'delimiter',
284+
'varchars', 'scanRows', 'threadCount', 'stripBlanks', 'sheetName',
285+
'password', 'decryptionKey', 'stringLengthMultiplier',
286+
'varcharConversionThreshold'.
278287
279288
Returns
280289
-------
@@ -308,10 +317,95 @@ def upload_file(
308317
if format_ is not None:
309318
data["format"] = format_
310319

320+
allowedBody = [
321+
'sessionId',
322+
'variables',
323+
'label',
324+
'scope',
325+
'replace',
326+
'encoding',
327+
'allowTruncation',
328+
'allowEmbeddedNewLines',
329+
'delimiter',
330+
'varchars',
331+
'scanRows',
332+
'threadCount',
333+
'stripBlanks',
334+
'sheetName',
335+
'password',
336+
'decryptionKey',
337+
'stringLengthMultiplier',
338+
'varcharConversionThreshold'
339+
]
340+
allowedBcsv = [
341+
'sessionId',
342+
'variables',
343+
'label',
344+
'scope',
345+
'replace',
346+
'encoding',
347+
'allowTruncation',
348+
'allowEmbeddedNewLines',
349+
'delimiter',
350+
'varchars',
351+
'scanRows',
352+
'threadCount',
353+
'stripBlanks'
354+
]
355+
allowedBxls = [
356+
'sessionId',
357+
'variables',
358+
'label',
359+
'scope',
360+
'replace',
361+
'sheetName'
362+
]
363+
allowedBsas = [
364+
'sessionId',
365+
'variables',
366+
'label',
367+
'scope',
368+
'replace',
369+
'password',
370+
'decryptionKey',
371+
'stringLengthMultiplier',
372+
'varcharConversionThreshold'
373+
]
374+
375+
if detail is not None:
376+
inputK = detail.keys()
377+
if not all(key in allowedBody for key in inputK):
378+
raise ValueError(
379+
"The body accepts only the following parameters %s." % (allowedBody)
380+
)
381+
elif (
382+
format_ == 'csv' and
383+
not all(key in allowedBcsv for key in inputK)
384+
):
385+
raise ValueError(
386+
"The parameters specific to a csv file are %s." % (allowedBcsv)
387+
)
388+
elif (
389+
format_ in ['xls','xlsx'] and
390+
not all(key in allowedBxls for key in inputK)
391+
):
392+
raise ValueError(
393+
"The parameters specific to a excel file are %s." % (allowedBxls)
394+
)
395+
elif (
396+
format_ in ['sashdat','sas7bdat'] and
397+
not all(key in allowedBsas for key in inputK)
398+
):
399+
raise ValueError(
400+
"The parameters specific to a sas file are %s." % (allowedBsas)
401+
)
402+
else:
403+
data.update(detail)
404+
311405
tbl = cls.post(
312406
"/servers/%s/caslibs/%s/tables" % (server, caslib),
313407
data=data,
314-
files={name: file},
408+
files={'file': (name,file)},
315409
)
316410
return tbl
317411

0 commit comments

Comments
 (0)