|
14 | 14 | from collections import OrderedDict |
15 | 15 | from datetime import datetime, date |
16 | 16 | from fractions import Fraction |
| 17 | +from numbers import Number |
17 | 18 |
|
18 | 19 | import six.moves.urllib.parse |
19 | | -from numbers import Number |
20 | 20 | from six import iteritems |
21 | 21 |
|
22 | 22 | import cloudinary |
|
65 | 65 | 'version' |
66 | 66 | ] |
67 | 67 |
|
| 68 | +__SIMPLE_UPLOAD_PARAMS = [ |
| 69 | + "public_id", |
| 70 | + "callback", |
| 71 | + "format", |
| 72 | + "type", |
| 73 | + "backup", |
| 74 | + "faces", |
| 75 | + "image_metadata", |
| 76 | + "exif", |
| 77 | + "colors", |
| 78 | + "use_filename", |
| 79 | + "unique_filename", |
| 80 | + "discard_original_filename", |
| 81 | + "invalidate", |
| 82 | + "notification_url", |
| 83 | + "eager_notification_url", |
| 84 | + "eager_async", |
| 85 | + "proxy", |
| 86 | + "folder", |
| 87 | + "overwrite", |
| 88 | + "moderation", |
| 89 | + "raw_convert", |
| 90 | + "quality_override", |
| 91 | + "quality_analysis", |
| 92 | + "ocr", |
| 93 | + "categorization", |
| 94 | + "detection", |
| 95 | + "similarity_search", |
| 96 | + "background_removal", |
| 97 | + "upload_preset", |
| 98 | + "phash", |
| 99 | + "return_delete_token", |
| 100 | + "auto_tagging", |
| 101 | + "async", |
| 102 | +] |
| 103 | + |
| 104 | +__SERIALIZED_UPLOAD_PARAMS = [ |
| 105 | + "timestamp", |
| 106 | + "transformation", |
| 107 | + "headers", |
| 108 | + "eager", |
| 109 | + "tags", |
| 110 | + "allowed_formats", |
| 111 | + "face_coordinates", |
| 112 | + "custom_coordinates", |
| 113 | + "context", |
| 114 | + "auto_tagging", |
| 115 | + "responsive_breakpoints", |
| 116 | + "access_control" |
| 117 | +] |
| 118 | + |
| 119 | +upload_params = __SIMPLE_UPLOAD_PARAMS + __SERIALIZED_UPLOAD_PARAMS |
| 120 | + |
68 | 121 |
|
69 | 122 | def build_array(arg): |
70 | 123 | if isinstance(arg, list): |
@@ -844,55 +897,29 @@ def build_custom_headers(headers): |
844 | 897 |
|
845 | 898 |
|
846 | 899 | def build_upload_params(**options): |
847 | | - params = { |
| 900 | + params = {param_name: options.get(param_name) for param_name in __SIMPLE_UPLOAD_PARAMS} |
| 901 | + |
| 902 | + serialized_params = { |
848 | 903 | "timestamp": now(), |
849 | 904 | "transformation": generate_transformation_string(**options)[0], |
850 | | - "public_id": options.get("public_id"), |
851 | | - "callback": options.get("callback"), |
852 | | - "format": options.get("format"), |
853 | | - "type": options.get("type"), |
854 | | - "backup": options.get("backup"), |
855 | | - "faces": options.get("faces"), |
856 | | - "image_metadata": options.get("image_metadata"), |
857 | | - "exif": options.get("exif"), |
858 | | - "colors": options.get("colors"), |
859 | 905 | "headers": build_custom_headers(options.get("headers")), |
860 | 906 | "eager": build_eager(options.get("eager")), |
861 | | - "use_filename": options.get("use_filename"), |
862 | | - "unique_filename": options.get("unique_filename"), |
863 | | - "discard_original_filename": options.get("discard_original_filename"), |
864 | | - "invalidate": options.get("invalidate"), |
865 | | - "notification_url": options.get("notification_url"), |
866 | | - "eager_notification_url": options.get("eager_notification_url"), |
867 | | - "eager_async": options.get("eager_async"), |
868 | | - "proxy": options.get("proxy"), |
869 | | - "folder": options.get("folder"), |
870 | | - "overwrite": options.get("overwrite"), |
871 | 907 | "tags": options.get("tags") and ",".join(build_array(options["tags"])), |
872 | | - "allowed_formats": options.get("allowed_formats") and ",".join( |
873 | | - build_array(options["allowed_formats"])), |
| 908 | + "allowed_formats": options.get("allowed_formats") and ",".join(build_array(options["allowed_formats"])), |
874 | 909 | "face_coordinates": encode_double_array(options.get("face_coordinates")), |
875 | 910 | "custom_coordinates": encode_double_array(options.get("custom_coordinates")), |
876 | 911 | "context": encode_context(options.get("context")), |
877 | | - "moderation": options.get("moderation"), |
878 | | - "raw_convert": options.get("raw_convert"), |
879 | | - "quality_override": options.get("quality_override"), |
880 | | - "quality_analysis": options.get("quality_analysis"), |
881 | | - "ocr": options.get("ocr"), |
882 | | - "categorization": options.get("categorization"), |
883 | | - "detection": options.get("detection"), |
884 | | - "similarity_search": options.get("similarity_search"), |
885 | | - "background_removal": options.get("background_removal"), |
886 | | - "upload_preset": options.get("upload_preset"), |
887 | | - "phash": options.get("phash"), |
888 | | - "return_delete_token": options.get("return_delete_token"), |
889 | 912 | "auto_tagging": options.get("auto_tagging") and str(options.get("auto_tagging")), |
890 | | - "responsive_breakpoints": generate_responsive_breakpoints_string( |
891 | | - options.get("responsive_breakpoints")), |
892 | | - "async": options.get("async"), |
| 913 | + "responsive_breakpoints": generate_responsive_breakpoints_string(options.get("responsive_breakpoints")), |
893 | 914 | "access_control": options.get("access_control") and json_encode( |
894 | 915 | build_list_of_dicts(options.get("access_control"))) |
895 | 916 | } |
| 917 | + |
| 918 | + # make sure that we are in-sync with __SERIALIZED_UPLOAD_PARAMS which are in use by other methods |
| 919 | + serialized_params = {param_name: serialized_params[param_name] for param_name in __SERIALIZED_UPLOAD_PARAMS} |
| 920 | + |
| 921 | + params.update(serialized_params) |
| 922 | + |
896 | 923 | return params |
897 | 924 |
|
898 | 925 |
|
@@ -1215,6 +1242,7 @@ def file_io_size(file_io): |
1215 | 1242 |
|
1216 | 1243 | return size |
1217 | 1244 |
|
| 1245 | + |
1218 | 1246 | def check_property_enabled(f): |
1219 | 1247 | """ |
1220 | 1248 | Used as a class method decorator to check whether class is enabled(self.enabled is True) |
|
0 commit comments