@@ -252,6 +252,8 @@ def upload_file(
252
252
server : str = None ,
253
253
header : bool = None ,
254
254
format_ : str = None ,
255
+ * ,
256
+ detail : dict = None
255
257
):
256
258
"""Upload a file to a CAS table.
257
259
@@ -275,6 +277,13 @@ def upload_file(
275
277
format_ : {"csv", "xls", "xlsx", "sas7bdat", "sashdat"}, optional
276
278
File of input `file`. Not required if format can be discerned from
277
279
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'.
278
287
279
288
Returns
280
289
-------
@@ -308,10 +317,95 @@ def upload_file(
308
317
if format_ is not None :
309
318
data ["format" ] = format_
310
319
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
+
311
405
tbl = cls .post (
312
406
"/servers/%s/caslibs/%s/tables" % (server , caslib ),
313
407
data = data ,
314
- files = {name : file },
408
+ files = {'file' : ( name , file ) },
315
409
)
316
410
return tbl
317
411
0 commit comments