Skip to content

Commit 6c8b045

Browse files
committed
Support setItem for binary and multipart body
1 parent caf39cd commit 6c8b045

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Diff for: reqable/reqable.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -585,12 +585,18 @@ def __getitem__(self, name: Union[str, int]):
585585
return self._payload[name]
586586
return None
587587

588-
# Set the json dict value by name. Note: you must call jsonify() before this.
589-
def __setitem__(self, name: str, value):
588+
# If the body type is a json dict, set the value. Note: you must call jsonify() before this.
589+
# If the body type is binary, set the value at the index.
590+
# If the body type is multipart, set the part at the index.
591+
def __setitem__(self, name: Union[str, int], value):
590592
if self.isText:
591593
if not isinstance(self._payload, dict):
592594
raise Exception('Did you forget to call `jsonify()` before operating json dict?')
593595
self._payload[name] = value
596+
if self.isBinary and isinstance(name, int):
597+
self._payload[name] = value
598+
if self.isMultipart and isinstance(name, int):
599+
self._payload[name] = value
594600

595601
# Write the body content to a file.
596602
def writeFile(self, path: str):

0 commit comments

Comments
 (0)