files-com 1.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of files-com might be problematic. Click here for more details.

Files changed (113) hide show
  1. README.md +682 -0
  2. _VERSION +1 -0
  3. files_com-1.5.0.dist-info/METADATA +694 -0
  4. files_com-1.5.0.dist-info/RECORD +113 -0
  5. files_com-1.5.0.dist-info/WHEEL +5 -0
  6. files_com-1.5.0.dist-info/licenses/LICENSE +21 -0
  7. files_com-1.5.0.dist-info/top_level.txt +1 -0
  8. files_sdk/__init__.py +270 -0
  9. files_sdk/api.py +57 -0
  10. files_sdk/api_client.py +327 -0
  11. files_sdk/error.py +2891 -0
  12. files_sdk/list_obj.py +42 -0
  13. files_sdk/models/__init__.py +104 -0
  14. files_sdk/models/account_line_item.py +51 -0
  15. files_sdk/models/action.py +49 -0
  16. files_sdk/models/action_notification_export.py +147 -0
  17. files_sdk/models/action_notification_export_result.py +88 -0
  18. files_sdk/models/api_key.py +322 -0
  19. files_sdk/models/api_request_log.py +87 -0
  20. files_sdk/models/app.py +89 -0
  21. files_sdk/models/as2_incoming_message.py +123 -0
  22. files_sdk/models/as2_outgoing_message.py +119 -0
  23. files_sdk/models/as2_partner.py +374 -0
  24. files_sdk/models/as2_station.py +271 -0
  25. files_sdk/models/auto.py +36 -0
  26. files_sdk/models/automation.py +691 -0
  27. files_sdk/models/automation_log.py +77 -0
  28. files_sdk/models/automation_run.py +108 -0
  29. files_sdk/models/bandwidth_snapshot.py +91 -0
  30. files_sdk/models/behavior.py +334 -0
  31. files_sdk/models/bundle.py +550 -0
  32. files_sdk/models/bundle_action.py +86 -0
  33. files_sdk/models/bundle_download.py +94 -0
  34. files_sdk/models/bundle_notification.py +217 -0
  35. files_sdk/models/bundle_path.py +37 -0
  36. files_sdk/models/bundle_recipient.py +120 -0
  37. files_sdk/models/bundle_registration.py +79 -0
  38. files_sdk/models/clickwrap.py +268 -0
  39. files_sdk/models/dns_record.py +59 -0
  40. files_sdk/models/email_incoming_message.py +102 -0
  41. files_sdk/models/email_log.py +74 -0
  42. files_sdk/models/errors.py +37 -0
  43. files_sdk/models/exavault_api_request_log.py +85 -0
  44. files_sdk/models/external_event.py +148 -0
  45. files_sdk/models/file.py +791 -0
  46. files_sdk/models/file_action.py +39 -0
  47. files_sdk/models/file_comment.py +191 -0
  48. files_sdk/models/file_comment_reaction.py +125 -0
  49. files_sdk/models/file_migration.py +69 -0
  50. files_sdk/models/file_migration_log.py +78 -0
  51. files_sdk/models/file_upload_part.py +54 -0
  52. files_sdk/models/folder.py +154 -0
  53. files_sdk/models/form_field.py +43 -0
  54. files_sdk/models/form_field_set.py +240 -0
  55. files_sdk/models/ftp_action_log.py +87 -0
  56. files_sdk/models/gpg_key.py +254 -0
  57. files_sdk/models/group.py +276 -0
  58. files_sdk/models/group_user.py +231 -0
  59. files_sdk/models/history.py +236 -0
  60. files_sdk/models/history_export.py +238 -0
  61. files_sdk/models/history_export_result.py +98 -0
  62. files_sdk/models/image.py +37 -0
  63. files_sdk/models/inbox_recipient.py +118 -0
  64. files_sdk/models/inbox_registration.py +79 -0
  65. files_sdk/models/inbox_upload.py +80 -0
  66. files_sdk/models/invoice.py +91 -0
  67. files_sdk/models/invoice_line_item.py +46 -0
  68. files_sdk/models/ip_address.py +119 -0
  69. files_sdk/models/lock.py +158 -0
  70. files_sdk/models/message.py +244 -0
  71. files_sdk/models/message_comment.py +223 -0
  72. files_sdk/models/message_comment_reaction.py +181 -0
  73. files_sdk/models/message_reaction.py +170 -0
  74. files_sdk/models/notification.py +357 -0
  75. files_sdk/models/outbound_connection_log.py +88 -0
  76. files_sdk/models/payment.py +91 -0
  77. files_sdk/models/payment_line_item.py +42 -0
  78. files_sdk/models/permission.py +174 -0
  79. files_sdk/models/preview.py +40 -0
  80. files_sdk/models/priority.py +63 -0
  81. files_sdk/models/project.py +205 -0
  82. files_sdk/models/public_hosting_request_log.py +82 -0
  83. files_sdk/models/public_ip_address.py +42 -0
  84. files_sdk/models/public_key.py +212 -0
  85. files_sdk/models/remote_bandwidth_snapshot.py +91 -0
  86. files_sdk/models/remote_server.py +1677 -0
  87. files_sdk/models/remote_server_configuration_file.py +72 -0
  88. files_sdk/models/request.py +180 -0
  89. files_sdk/models/restore.py +104 -0
  90. files_sdk/models/session.py +100 -0
  91. files_sdk/models/settings_change.py +71 -0
  92. files_sdk/models/sftp_action_log.py +91 -0
  93. files_sdk/models/sftp_host_key.py +215 -0
  94. files_sdk/models/share_group.py +228 -0
  95. files_sdk/models/share_group_member.py +41 -0
  96. files_sdk/models/siem_http_destination.py +773 -0
  97. files_sdk/models/site.py +767 -0
  98. files_sdk/models/snapshot.py +255 -0
  99. files_sdk/models/sso_strategy.py +167 -0
  100. files_sdk/models/status.py +42 -0
  101. files_sdk/models/style.py +152 -0
  102. files_sdk/models/sync_log.py +75 -0
  103. files_sdk/models/usage_by_top_level_dir.py +41 -0
  104. files_sdk/models/usage_daily_snapshot.py +93 -0
  105. files_sdk/models/usage_snapshot.py +73 -0
  106. files_sdk/models/user.py +893 -0
  107. files_sdk/models/user_cipher_use.py +68 -0
  108. files_sdk/models/user_request.py +166 -0
  109. files_sdk/models/user_sftp_client_use.py +68 -0
  110. files_sdk/models/web_dav_action_log.py +87 -0
  111. files_sdk/models/webhook_test.py +104 -0
  112. files_sdk/path_util.py +42 -0
  113. files_sdk/util.py +34 -0
@@ -0,0 +1,791 @@
1
+ import builtins # noqa: F401
2
+ from builtins import open as builtin_open
3
+ from datetime import datetime
4
+ import io
5
+ from pathlib import Path
6
+ from files_sdk.models.file_action import FileAction
7
+ from files_sdk.models.file_upload_part import FileUploadPart
8
+ from files_sdk.api import Api # noqa: F401
9
+ from files_sdk.error import ( # noqa: F401
10
+ InvalidParameterError,
11
+ MissingParameterError,
12
+ NotImplementedError,
13
+ )
14
+
15
+
16
+ class File:
17
+ default_attributes = {
18
+ "path": None, # string - File/Folder path. This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters.
19
+ "created_by_id": None, # int64 - User ID of the User who created the file/folder
20
+ "created_by_api_key_id": None, # int64 - ID of the API key that created the file/folder
21
+ "created_by_as2_incoming_message_id": None, # int64 - ID of the AS2 Incoming Message that created the file/folder
22
+ "created_by_automation_id": None, # int64 - ID of the Automation that created the file/folder
23
+ "created_by_bundle_registration_id": None, # int64 - ID of the Bundle Registration that created the file/folder
24
+ "created_by_inbox_id": None, # int64 - ID of the Inbox that created the file/folder
25
+ "created_by_remote_server_id": None, # int64 - ID of the Remote Server that created the file/folder
26
+ "created_by_remote_server_sync_id": None, # int64 - ID of the Remote Server Sync that created the file/folder
27
+ "custom_metadata": None, # object - Custom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value.
28
+ "display_name": None, # string - File/Folder display name
29
+ "type": None, # string - Type: `directory` or `file`.
30
+ "size": None, # int64 - File/Folder size
31
+ "created_at": None, # date-time - File created date/time
32
+ "last_modified_by_id": None, # int64 - User ID of the User who last modified the file/folder
33
+ "last_modified_by_api_key_id": None, # int64 - ID of the API key that last modified the file/folder
34
+ "last_modified_by_automation_id": None, # int64 - ID of the Automation that last modified the file/folder
35
+ "last_modified_by_bundle_registration_id": None, # int64 - ID of the Bundle Registration that last modified the file/folder
36
+ "last_modified_by_remote_server_id": None, # int64 - ID of the Remote Server that last modified the file/folder
37
+ "last_modified_by_remote_server_sync_id": None, # int64 - ID of the Remote Server Sync that last modified the file/folder
38
+ "mtime": None, # date-time - File last modified date/time, according to the server. This is the timestamp of the last Files.com operation of the file, regardless of what modified timestamp was sent.
39
+ "provided_mtime": None, # date-time - File last modified date/time, according to the client who set it. Files.com allows desktop, FTP, SFTP, and WebDAV clients to set modified at times. This allows Desktop<->Cloud syncing to preserve modified at times.
40
+ "crc32": None, # string - File CRC32 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
41
+ "md5": None, # string - File MD5 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
42
+ "sha1": None, # string - File SHA1 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
43
+ "sha256": None, # string - File SHA256 checksum. This is sometimes delayed, so if you get a blank response, wait and try again.
44
+ "mime_type": None, # string - MIME Type. This is determined by the filename extension and is not stored separately internally.
45
+ "region": None, # string - Region location
46
+ "permissions": None, # string - A short string representing the current user's permissions. Can be `r` (Read),`w` (Write),`d` (Delete), `l` (List) or any combination
47
+ "subfolders_locked?": None, # boolean - Are subfolders locked and unable to be modified?
48
+ "is_locked": None, # boolean - Is this folder locked and unable to be modified?
49
+ "download_uri": None, # string - Link to download file. Provided only in response to a download request.
50
+ "priority_color": None, # string - Bookmark/priority color of file/folder
51
+ "preview_id": None, # int64 - File preview ID
52
+ "preview": None, # Preview - File preview
53
+ "action": None, # string - The action to perform. Can be `append`, `attachment`, `end`, `upload`, `put`, or may not exist
54
+ "length": None, # int64 - Length of file.
55
+ "mkdir_parents": None, # boolean - Create parent directories if they do not exist?
56
+ "part": None, # int64 - Part if uploading a part.
57
+ "parts": None, # int64 - How many parts to fetch?
58
+ "ref": None, # string -
59
+ "restart": None, # int64 - File byte offset to restart from.
60
+ "structure": None, # string - If copying folder, copy just the structure?
61
+ "with_rename": None, # boolean - Allow file rename instead of overwrite?
62
+ }
63
+
64
+ def __init__(self, *args):
65
+ self.set_attributes({})
66
+ self.options = {}
67
+ self.mode = "r"
68
+ self.upload = None
69
+ self.etags = None
70
+ self.io_obj = io.StringIO()
71
+ self.closed = True
72
+
73
+ self.bytes_written = 0
74
+ if len(args) >= 1:
75
+ if isinstance(args[0], dict):
76
+ self.set_attributes(args[0])
77
+ elif isinstance(args[0], str):
78
+ self.set_attributes({"path": args[0]})
79
+ if len(args) >= 2:
80
+ if isinstance(args[1], dict):
81
+ self.options = args[1]
82
+ elif isinstance(args[1], str):
83
+ self.mode = args[1]
84
+ if len(args) >= 3:
85
+ if isinstance(args[2], dict):
86
+ self.options = args[2]
87
+
88
+ def set_attributes(self, attributes):
89
+ for attribute, default_value in File.default_attributes.items():
90
+ setattr(self, attribute, attributes.get(attribute, default_value))
91
+
92
+ def get_attributes(self):
93
+ return {
94
+ k: getattr(self, k, None)
95
+ for k in File.default_attributes
96
+ if getattr(self, k, None) is not None
97
+ }
98
+
99
+ def __enter__(self):
100
+ return self
101
+
102
+ def __exit__(self, type, value, traceback):
103
+ self.close()
104
+
105
+ def __del__(self):
106
+ if not self.io_obj.closed:
107
+ self.io_obj.close()
108
+
109
+ def close(self):
110
+ self.flush()
111
+
112
+ if self.upload:
113
+ end_options = {
114
+ "action": "end",
115
+ "etags": self.etags,
116
+ "provided_mtime": datetime.now().isoformat(),
117
+ "ref": self.upload.ref,
118
+ "size": self.bytes_written,
119
+ }
120
+
121
+ file = create(self.path, end_options, self.options)
122
+ self.set_attributes(file.get_attributes())
123
+ self.mode = "r"
124
+ self.upload = None
125
+ self.etags = None
126
+ self.io_obj = io.StringIO()
127
+ self.io_obj.close
128
+ self.closed = True
129
+
130
+ def fileno(self):
131
+ raise OSError
132
+
133
+ def flush(self, *_args):
134
+ if "w" in self.mode:
135
+ if self.io_obj.seekable():
136
+ self.io_obj.seek(0)
137
+
138
+ self.upload, self.etags, bytes_written = upload_chunks(
139
+ self.io_obj, self.path, self.options, self.upload, self.etags
140
+ )
141
+ self.bytes_written += bytes_written
142
+ elif "a" in self.mode:
143
+ raise io.UnsupportedOperation("Append is not a supported mode")
144
+
145
+ def isatty(self):
146
+ return False
147
+
148
+ def read(self):
149
+ if self.readable():
150
+ self.download_content(
151
+ self.io_obj, False if "b" in self.mode else True
152
+ )
153
+ self.io_obj.seek(0)
154
+ return self.io_obj.read()
155
+ else:
156
+ raise OSError("read mode not indicated")
157
+
158
+ def readable(self):
159
+ if "r" in self.mode and not self.closed:
160
+ return True
161
+ return False
162
+
163
+ def readall(self):
164
+ self.read()
165
+
166
+ def readinto(self):
167
+ return NotImplementedError
168
+
169
+ def readline(self):
170
+ return NotImplementedError
171
+
172
+ def seek(self):
173
+ raise OSError
174
+
175
+ def seekable(self):
176
+ return False
177
+
178
+ def tell(self):
179
+ raise OSError
180
+
181
+ def truncate(self):
182
+ raise OSError
183
+
184
+ def writeable(self):
185
+ if "w" in self.mode and not self.closed:
186
+ return True
187
+ return False
188
+
189
+ def write(self, *args):
190
+ if self.writeable():
191
+ self.io_obj.write(*args)
192
+ else:
193
+ raise OSError("write mode not indicated")
194
+
195
+ def download_uri_with_load(self):
196
+ if self.download_uri:
197
+ return self.download_uri
198
+
199
+ f = download(self.path, {}, self.options)
200
+ self.set_attributes(f.get_attributes())
201
+ return self.download_uri
202
+
203
+ def download_content(self, io, is_string_io=False):
204
+ Api.client().stream_download(
205
+ self.download_uri_with_load(), io, is_string_io
206
+ )
207
+
208
+ def download_file(self, output_file):
209
+ with builtin_open(output_file, "wb") as file:
210
+ self.download_content(file)
211
+
212
+ # Download File
213
+ #
214
+ # Parameters:
215
+ # action - string - Can be blank, `redirect` or `stat`. If set to `stat`, we will return file information but without a download URL, and without logging a download. If set to `redirect` we will serve a 302 redirect directly to the file. This is used for integrations with Zapier, and is not recommended for most integrations.
216
+ # preview_size - string - Request a preview size. Can be `small` (default), `large`, `xlarge`, or `pdf`.
217
+ # with_previews - boolean - Include file preview information?
218
+ # with_priority_color - boolean - Include file priority color information?
219
+ def download(self, params=None):
220
+ if not isinstance(params, dict):
221
+ params = {}
222
+
223
+ if hasattr(self, "path") and self.path:
224
+ params["path"] = self.path
225
+ else:
226
+ raise MissingParameterError("Current object doesn't have a path")
227
+ if "path" not in params:
228
+ raise MissingParameterError("Parameter missing: path")
229
+ if "path" in params and not isinstance(params["path"], str):
230
+ raise InvalidParameterError("Bad parameter: path must be an str")
231
+ if "action" in params and not isinstance(params["action"], str):
232
+ raise InvalidParameterError("Bad parameter: action must be an str")
233
+ if "preview_size" in params and not isinstance(
234
+ params["preview_size"], str
235
+ ):
236
+ raise InvalidParameterError(
237
+ "Bad parameter: preview_size must be an str"
238
+ )
239
+ response, _options = Api.send_request(
240
+ "GET",
241
+ "/files/{path}".format(path=params["path"]),
242
+ params,
243
+ self.options,
244
+ )
245
+ return response.data
246
+
247
+ # Parameters:
248
+ # custom_metadata - object - Custom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value.
249
+ # provided_mtime - string - Modified time of file.
250
+ # priority_color - string - Priority/Bookmark color of file.
251
+ def update(self, params=None):
252
+ if not isinstance(params, dict):
253
+ params = {}
254
+
255
+ if hasattr(self, "path") and self.path:
256
+ params["path"] = self.path
257
+ else:
258
+ raise MissingParameterError("Current object doesn't have a path")
259
+ if "path" not in params:
260
+ raise MissingParameterError("Parameter missing: path")
261
+ if "path" in params and not isinstance(params["path"], str):
262
+ raise InvalidParameterError("Bad parameter: path must be an str")
263
+ if "provided_mtime" in params and not isinstance(
264
+ params["provided_mtime"], str
265
+ ):
266
+ raise InvalidParameterError(
267
+ "Bad parameter: provided_mtime must be an str"
268
+ )
269
+ if "priority_color" in params and not isinstance(
270
+ params["priority_color"], str
271
+ ):
272
+ raise InvalidParameterError(
273
+ "Bad parameter: priority_color must be an str"
274
+ )
275
+ response, _options = Api.send_request(
276
+ "PATCH",
277
+ "/files/{path}".format(path=params["path"]),
278
+ params,
279
+ self.options,
280
+ )
281
+ return response.data
282
+
283
+ # Parameters:
284
+ # recursive - boolean - If true, will recursively delete folders. Otherwise, will error on non-empty folders.
285
+ def delete(self, params=None):
286
+ if not isinstance(params, dict):
287
+ params = {}
288
+
289
+ if hasattr(self, "path") and self.path:
290
+ params["path"] = self.path
291
+ else:
292
+ raise MissingParameterError("Current object doesn't have a path")
293
+ if "path" not in params:
294
+ raise MissingParameterError("Parameter missing: path")
295
+ if "path" in params and not isinstance(params["path"], str):
296
+ raise InvalidParameterError("Bad parameter: path must be an str")
297
+ Api.send_request(
298
+ "DELETE",
299
+ "/files/{path}".format(path=params["path"]),
300
+ params,
301
+ self.options,
302
+ )
303
+
304
+ def destroy(self, params=None):
305
+ self.delete(params)
306
+
307
+ # Copy File/Folder
308
+ #
309
+ # Parameters:
310
+ # destination (required) - string - Copy destination path.
311
+ # structure - boolean - Copy structure only?
312
+ # overwrite - boolean - Overwrite existing file(s) in the destination?
313
+ def copy(self, params=None):
314
+ if not isinstance(params, dict):
315
+ params = {}
316
+
317
+ if hasattr(self, "path") and self.path:
318
+ params["path"] = self.path
319
+ else:
320
+ raise MissingParameterError("Current object doesn't have a path")
321
+ if "path" not in params:
322
+ raise MissingParameterError("Parameter missing: path")
323
+ if "destination" not in params:
324
+ raise MissingParameterError("Parameter missing: destination")
325
+ if "path" in params and not isinstance(params["path"], str):
326
+ raise InvalidParameterError("Bad parameter: path must be an str")
327
+ if "destination" in params and not isinstance(
328
+ params["destination"], str
329
+ ):
330
+ raise InvalidParameterError(
331
+ "Bad parameter: destination must be an str"
332
+ )
333
+ response, _options = Api.send_request(
334
+ "POST",
335
+ "/file_actions/copy/{path}".format(path=params["path"]),
336
+ params,
337
+ self.options,
338
+ )
339
+ return response.data
340
+
341
+ # Move File/Folder
342
+ #
343
+ # Parameters:
344
+ # destination (required) - string - Move destination path.
345
+ # overwrite - boolean - Overwrite existing file(s) in the destination?
346
+ def move(self, params=None):
347
+ if not isinstance(params, dict):
348
+ params = {}
349
+
350
+ if hasattr(self, "path") and self.path:
351
+ params["path"] = self.path
352
+ else:
353
+ raise MissingParameterError("Current object doesn't have a path")
354
+ if "path" not in params:
355
+ raise MissingParameterError("Parameter missing: path")
356
+ if "destination" not in params:
357
+ raise MissingParameterError("Parameter missing: destination")
358
+ if "path" in params and not isinstance(params["path"], str):
359
+ raise InvalidParameterError("Bad parameter: path must be an str")
360
+ if "destination" in params and not isinstance(
361
+ params["destination"], str
362
+ ):
363
+ raise InvalidParameterError(
364
+ "Bad parameter: destination must be an str"
365
+ )
366
+ response, _options = Api.send_request(
367
+ "POST",
368
+ "/file_actions/move/{path}".format(path=params["path"]),
369
+ params,
370
+ self.options,
371
+ )
372
+ return response.data
373
+
374
+ # Begin File Upload
375
+ #
376
+ # Parameters:
377
+ # mkdir_parents - boolean - Create parent directories if they do not exist?
378
+ # part - int64 - Part if uploading a part.
379
+ # parts - int64 - How many parts to fetch?
380
+ # ref - string -
381
+ # restart - int64 - File byte offset to restart from.
382
+ # size - int64 - Total bytes of file being uploaded (include bytes being retained if appending/restarting).
383
+ # with_rename - boolean - Allow file rename instead of overwrite?
384
+ def begin_upload(self, params=None):
385
+ if not isinstance(params, dict):
386
+ params = {}
387
+
388
+ if hasattr(self, "path") and self.path:
389
+ params["path"] = self.path
390
+ else:
391
+ raise MissingParameterError("Current object doesn't have a path")
392
+ if "path" not in params:
393
+ raise MissingParameterError("Parameter missing: path")
394
+ if "path" in params and not isinstance(params["path"], str):
395
+ raise InvalidParameterError("Bad parameter: path must be an str")
396
+ if "part" in params and not isinstance(params["part"], int):
397
+ raise InvalidParameterError("Bad parameter: part must be an int")
398
+ if "parts" in params and not isinstance(params["parts"], int):
399
+ raise InvalidParameterError("Bad parameter: parts must be an int")
400
+ if "ref" in params and not isinstance(params["ref"], str):
401
+ raise InvalidParameterError("Bad parameter: ref must be an str")
402
+ if "restart" in params and not isinstance(params["restart"], int):
403
+ raise InvalidParameterError(
404
+ "Bad parameter: restart must be an int"
405
+ )
406
+ if "size" in params and not isinstance(params["size"], int):
407
+ raise InvalidParameterError("Bad parameter: size must be an int")
408
+ response, _options = Api.send_request(
409
+ "POST",
410
+ "/file_actions/begin_upload/{path}".format(path=params["path"]),
411
+ params,
412
+ self.options,
413
+ )
414
+ return response.data
415
+
416
+ def save(self):
417
+ new_obj = create(self.path, self.get_attributes(), self.options)
418
+ self.set_attributes(new_obj.get_attributes())
419
+ return True
420
+
421
+
422
+ # Download File
423
+ #
424
+ # Parameters:
425
+ # action - string - Can be blank, `redirect` or `stat`. If set to `stat`, we will return file information but without a download URL, and without logging a download. If set to `redirect` we will serve a 302 redirect directly to the file. This is used for integrations with Zapier, and is not recommended for most integrations.
426
+ # preview_size - string - Request a preview size. Can be `small` (default), `large`, `xlarge`, or `pdf`.
427
+ # with_previews - boolean - Include file preview information?
428
+ # with_priority_color - boolean - Include file priority color information?
429
+ def download(path, params=None, options=None):
430
+ if not isinstance(params, dict):
431
+ params = {}
432
+ if not isinstance(options, dict):
433
+ options = {}
434
+ params["path"] = path
435
+ if "path" in params and not isinstance(params["path"], str):
436
+ raise InvalidParameterError("Bad parameter: path must be an str")
437
+ if "action" in params and not isinstance(params["action"], str):
438
+ raise InvalidParameterError("Bad parameter: action must be an str")
439
+ if "preview_size" in params and not isinstance(
440
+ params["preview_size"], str
441
+ ):
442
+ raise InvalidParameterError(
443
+ "Bad parameter: preview_size must be an str"
444
+ )
445
+ if "path" not in params:
446
+ raise MissingParameterError("Parameter missing: path")
447
+ response, options = Api.send_request(
448
+ "GET", "/files/{path}".format(path=params["path"]), params, options
449
+ )
450
+ return File(response.data, options)
451
+
452
+
453
+ # Parameters:
454
+ # path (required) - string - Path to operate on.
455
+ # action - string - The action to perform. Can be `append`, `attachment`, `end`, `upload`, `put`, or may not exist
456
+ # etags[etag] (required) - array(string) - etag identifier.
457
+ # etags[part] (required) - array(int64) - Part number.
458
+ # length - int64 - Length of file.
459
+ # mkdir_parents - boolean - Create parent directories if they do not exist?
460
+ # part - int64 - Part if uploading a part.
461
+ # parts - int64 - How many parts to fetch?
462
+ # provided_mtime - string - User provided modification time.
463
+ # ref - string -
464
+ # restart - int64 - File byte offset to restart from.
465
+ # size - int64 - Size of file.
466
+ # structure - string - If copying folder, copy just the structure?
467
+ # with_rename - boolean - Allow file rename instead of overwrite?
468
+ def create(path, params=None, options=None):
469
+ if not isinstance(params, dict):
470
+ params = {}
471
+ if not isinstance(options, dict):
472
+ options = {}
473
+ params["path"] = path
474
+ if "path" in params and not isinstance(params["path"], str):
475
+ raise InvalidParameterError("Bad parameter: path must be an str")
476
+ if "action" in params and not isinstance(params["action"], str):
477
+ raise InvalidParameterError("Bad parameter: action must be an str")
478
+ if "length" in params and not isinstance(params["length"], int):
479
+ raise InvalidParameterError("Bad parameter: length must be an int")
480
+ if "part" in params and not isinstance(params["part"], int):
481
+ raise InvalidParameterError("Bad parameter: part must be an int")
482
+ if "parts" in params and not isinstance(params["parts"], int):
483
+ raise InvalidParameterError("Bad parameter: parts must be an int")
484
+ if "provided_mtime" in params and not isinstance(
485
+ params["provided_mtime"], str
486
+ ):
487
+ raise InvalidParameterError(
488
+ "Bad parameter: provided_mtime must be an str"
489
+ )
490
+ if "ref" in params and not isinstance(params["ref"], str):
491
+ raise InvalidParameterError("Bad parameter: ref must be an str")
492
+ if "restart" in params and not isinstance(params["restart"], int):
493
+ raise InvalidParameterError("Bad parameter: restart must be an int")
494
+ if "size" in params and not isinstance(params["size"], int):
495
+ raise InvalidParameterError("Bad parameter: size must be an int")
496
+ if "structure" in params and not isinstance(params["structure"], str):
497
+ raise InvalidParameterError("Bad parameter: structure must be an str")
498
+ if "path" not in params:
499
+ raise MissingParameterError("Parameter missing: path")
500
+ response, options = Api.send_request(
501
+ "POST", "/files/{path}".format(path=params["path"]), params, options
502
+ )
503
+ return File(response.data, options)
504
+
505
+
506
+ # Parameters:
507
+ # custom_metadata - object - Custom metadata map of keys and values. Limited to 32 keys, 256 characters per key and 1024 characters per value.
508
+ # provided_mtime - string - Modified time of file.
509
+ # priority_color - string - Priority/Bookmark color of file.
510
+ def update(path, params=None, options=None):
511
+ if not isinstance(params, dict):
512
+ params = {}
513
+ if not isinstance(options, dict):
514
+ options = {}
515
+ params["path"] = path
516
+ if "path" in params and not isinstance(params["path"], str):
517
+ raise InvalidParameterError("Bad parameter: path must be an str")
518
+ if "custom_metadata" in params and not isinstance(
519
+ params["custom_metadata"], dict
520
+ ):
521
+ raise InvalidParameterError(
522
+ "Bad parameter: custom_metadata must be an dict"
523
+ )
524
+ if "provided_mtime" in params and not isinstance(
525
+ params["provided_mtime"], str
526
+ ):
527
+ raise InvalidParameterError(
528
+ "Bad parameter: provided_mtime must be an str"
529
+ )
530
+ if "priority_color" in params and not isinstance(
531
+ params["priority_color"], str
532
+ ):
533
+ raise InvalidParameterError(
534
+ "Bad parameter: priority_color must be an str"
535
+ )
536
+ if "path" not in params:
537
+ raise MissingParameterError("Parameter missing: path")
538
+ response, options = Api.send_request(
539
+ "PATCH", "/files/{path}".format(path=params["path"]), params, options
540
+ )
541
+ return File(response.data, options)
542
+
543
+
544
+ # Parameters:
545
+ # recursive - boolean - If true, will recursively delete folders. Otherwise, will error on non-empty folders.
546
+ def delete(path, params=None, options=None):
547
+ if not isinstance(params, dict):
548
+ params = {}
549
+ if not isinstance(options, dict):
550
+ options = {}
551
+ params["path"] = path
552
+ if "path" in params and not isinstance(params["path"], str):
553
+ raise InvalidParameterError("Bad parameter: path must be an str")
554
+ if "path" not in params:
555
+ raise MissingParameterError("Parameter missing: path")
556
+ Api.send_request(
557
+ "DELETE", "/files/{path}".format(path=params["path"]), params, options
558
+ )
559
+
560
+
561
+ def destroy(path, params=None, options=None):
562
+ delete(path, params, options)
563
+
564
+
565
+ # Parameters:
566
+ # path (required) - string - Path to operate on.
567
+ # preview_size - string - Request a preview size. Can be `small` (default), `large`, `xlarge`, or `pdf`.
568
+ # with_previews - boolean - Include file preview information?
569
+ # with_priority_color - boolean - Include file priority color information?
570
+ def find(path, params=None, options=None):
571
+ if not isinstance(params, dict):
572
+ params = {}
573
+ if not isinstance(options, dict):
574
+ options = {}
575
+ params["path"] = path
576
+ if "path" in params and not isinstance(params["path"], str):
577
+ raise InvalidParameterError("Bad parameter: path must be an str")
578
+ if "preview_size" in params and not isinstance(
579
+ params["preview_size"], str
580
+ ):
581
+ raise InvalidParameterError(
582
+ "Bad parameter: preview_size must be an str"
583
+ )
584
+ if "path" not in params:
585
+ raise MissingParameterError("Parameter missing: path")
586
+ response, options = Api.send_request(
587
+ "GET",
588
+ "/file_actions/metadata/{path}".format(path=params["path"]),
589
+ params,
590
+ options,
591
+ )
592
+ return File(response.data, options)
593
+
594
+
595
+ def get(path, params=None, options=None):
596
+ find(path, params, options)
597
+
598
+
599
+ # Copy File/Folder
600
+ #
601
+ # Parameters:
602
+ # destination (required) - string - Copy destination path.
603
+ # structure - boolean - Copy structure only?
604
+ # overwrite - boolean - Overwrite existing file(s) in the destination?
605
+ def copy(path, params=None, options=None):
606
+ if not isinstance(params, dict):
607
+ params = {}
608
+ if not isinstance(options, dict):
609
+ options = {}
610
+ params["path"] = path
611
+ if "path" in params and not isinstance(params["path"], str):
612
+ raise InvalidParameterError("Bad parameter: path must be an str")
613
+ if "destination" in params and not isinstance(params["destination"], str):
614
+ raise InvalidParameterError(
615
+ "Bad parameter: destination must be an str"
616
+ )
617
+ if "path" not in params:
618
+ raise MissingParameterError("Parameter missing: path")
619
+ if "destination" not in params:
620
+ raise MissingParameterError("Parameter missing: destination")
621
+ response, options = Api.send_request(
622
+ "POST",
623
+ "/file_actions/copy/{path}".format(path=params["path"]),
624
+ params,
625
+ options,
626
+ )
627
+ return FileAction(response.data, options)
628
+
629
+
630
+ # Move File/Folder
631
+ #
632
+ # Parameters:
633
+ # destination (required) - string - Move destination path.
634
+ # overwrite - boolean - Overwrite existing file(s) in the destination?
635
+ def move(path, params=None, options=None):
636
+ if not isinstance(params, dict):
637
+ params = {}
638
+ if not isinstance(options, dict):
639
+ options = {}
640
+ params["path"] = path
641
+ if "path" in params and not isinstance(params["path"], str):
642
+ raise InvalidParameterError("Bad parameter: path must be an str")
643
+ if "destination" in params and not isinstance(params["destination"], str):
644
+ raise InvalidParameterError(
645
+ "Bad parameter: destination must be an str"
646
+ )
647
+ if "path" not in params:
648
+ raise MissingParameterError("Parameter missing: path")
649
+ if "destination" not in params:
650
+ raise MissingParameterError("Parameter missing: destination")
651
+ response, options = Api.send_request(
652
+ "POST",
653
+ "/file_actions/move/{path}".format(path=params["path"]),
654
+ params,
655
+ options,
656
+ )
657
+ return FileAction(response.data, options)
658
+
659
+
660
+ # Begin File Upload
661
+ #
662
+ # Parameters:
663
+ # mkdir_parents - boolean - Create parent directories if they do not exist?
664
+ # part - int64 - Part if uploading a part.
665
+ # parts - int64 - How many parts to fetch?
666
+ # ref - string -
667
+ # restart - int64 - File byte offset to restart from.
668
+ # size - int64 - Total bytes of file being uploaded (include bytes being retained if appending/restarting).
669
+ # with_rename - boolean - Allow file rename instead of overwrite?
670
+ def begin_upload(path, params=None, options=None):
671
+ if not isinstance(params, dict):
672
+ params = {}
673
+ if not isinstance(options, dict):
674
+ options = {}
675
+ params["path"] = path
676
+ if "path" in params and not isinstance(params["path"], str):
677
+ raise InvalidParameterError("Bad parameter: path must be an str")
678
+ if "part" in params and not isinstance(params["part"], int):
679
+ raise InvalidParameterError("Bad parameter: part must be an int")
680
+ if "parts" in params and not isinstance(params["parts"], int):
681
+ raise InvalidParameterError("Bad parameter: parts must be an int")
682
+ if "ref" in params and not isinstance(params["ref"], str):
683
+ raise InvalidParameterError("Bad parameter: ref must be an str")
684
+ if "restart" in params and not isinstance(params["restart"], int):
685
+ raise InvalidParameterError("Bad parameter: restart must be an int")
686
+ if "size" in params and not isinstance(params["size"], int):
687
+ raise InvalidParameterError("Bad parameter: size must be an int")
688
+ if "path" not in params:
689
+ raise MissingParameterError("Parameter missing: path")
690
+ response, options = Api.send_request(
691
+ "POST",
692
+ "/file_actions/begin_upload/{path}".format(path=params["path"]),
693
+ params,
694
+ options,
695
+ )
696
+ return [
697
+ FileUploadPart(entity_data, options) for entity_data in response.data
698
+ ]
699
+
700
+
701
+ def open(path, mode="r", options=None):
702
+ if not isinstance(options, dict):
703
+ options = {}
704
+ file = File(path, mode, options)
705
+
706
+ if "w" in mode:
707
+ if "b" in mode:
708
+ file.io_obj = io.BytesIO()
709
+ else:
710
+ file.io_obj = io.StringIO()
711
+
712
+ if "r" in mode:
713
+ if "b" in mode:
714
+ file.io_obj = io.BytesIO()
715
+ else:
716
+ file.io_obj = io.StringIO()
717
+ file.closed = False
718
+ return file
719
+
720
+
721
+ def upload_chunks(io, path, options, upload=None, etags=None, params=None):
722
+ if not etags:
723
+ etags = []
724
+ if not params:
725
+ params = {}
726
+ bytes_written = 0
727
+ while True:
728
+ chunk_params = (
729
+ {"part": 1}
730
+ if not upload
731
+ else {"ref": upload.ref, "part": upload.part_number + 1}
732
+ )
733
+ params.update(chunk_params)
734
+ upload = begin_upload(path, params, options)[0]
735
+ buf = io.read(upload.partsize)
736
+ if buf is not None: # None means no data but io still open
737
+ bytes_written += len(buf)
738
+ response = Api.client().send_remote_request(
739
+ upload.http_method,
740
+ upload.upload_uri,
741
+ {"Content-Length": str(len(buf))},
742
+ buf,
743
+ )
744
+ if "ETag" in response.headers:
745
+ etags.append(
746
+ {
747
+ "etag": response.headers["ETag"].strip('"'),
748
+ "part": upload.part_number,
749
+ }
750
+ )
751
+ if buf in [b"", ""] or (
752
+ len(buf) < upload.partsize
753
+ ): # Empty bytearray means EOF for BytesIO, Empty String means EOF for StringIO
754
+ return (upload, etags, bytes_written)
755
+
756
+
757
+ def upload_file(path, destination=None, options=None, params=None):
758
+ if not isinstance(options, dict):
759
+ options = {}
760
+ pth = Path(path)
761
+ stat = pth.stat()
762
+ with builtin_open(path, "rb") as local_file:
763
+ if destination is None:
764
+ destination = pth.name
765
+ upload, etags, _bytes_written = upload_chunks(
766
+ local_file, destination, options, params=params
767
+ )
768
+
769
+ final_params = {
770
+ "action": "end",
771
+ "etags": etags,
772
+ "provided_mtime": datetime.utcfromtimestamp(
773
+ stat.st_mtime
774
+ ).isoformat(),
775
+ "ref": upload.ref,
776
+ "size": stat.st_size,
777
+ }
778
+
779
+ create(destination, final_params, options)
780
+
781
+
782
+ def download_file(path, local_path=None, options=None):
783
+ if not isinstance(options, dict):
784
+ options = {}
785
+ if local_path is None:
786
+ local_path = Path(path).name
787
+ return File(path, {}, options).download_file(local_path)
788
+
789
+
790
+ def new(*args, **kwargs):
791
+ return File(*args, **kwargs)