From cefb9adab4a68d5a04893cc1be75fb6cce9980d6 Mon Sep 17 00:00:00 2001 From: cesar Date: Sun, 16 Jun 2024 23:19:50 +0800 Subject: [PATCH 01/11] Fix ModuleNotFoundError when running reqable script directly --- reqable/__init__.py | 2 +- reqable/addons.py | 6 +++--- reqable/addons_mini.py | 6 +++--- reqable/main.py | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/reqable/__init__.py b/reqable/__init__.py index f317161..d9242cf 100644 --- a/reqable/__init__.py +++ b/reqable/__init__.py @@ -1,4 +1,4 @@ -import main +from reqable import main if __name__== '__main__': main.main() \ No newline at end of file diff --git a/reqable/addons.py b/reqable/addons.py index 45d88aa..468e22f 100644 --- a/reqable/addons.py +++ b/reqable/addons.py @@ -1,8 +1,8 @@ # API Docs: https://reqable.com/docs/capture/addons -from reqable import * +from reqable.reqable import CaptureContext, CaptureHttpRequest, CaptureHttpResponse -def onRequest(context, request): +def onRequest(context: CaptureContext, request: CaptureHttpRequest) -> CaptureHttpRequest: # Print url to console # print('request url ' + context.url) @@ -26,7 +26,7 @@ def onRequest(context, request): # Done return request -def onResponse(context, response): +def onResponse(context: CaptureContext, response: CaptureHttpResponse) -> CaptureHttpResponse: # Update status code # response.code = 404 diff --git a/reqable/addons_mini.py b/reqable/addons_mini.py index e7a0446..eff3266 100644 --- a/reqable/addons_mini.py +++ b/reqable/addons_mini.py @@ -1,9 +1,9 @@ # API Docs: https://reqable.com/docs/capture/addons -from reqable import * +from reqable.reqable import CaptureContext, CaptureHttpRequest, CaptureHttpResponse -def onRequest(context, request): +def onRequest(context: CaptureContext, request: CaptureHttpRequest) -> CaptureHttpRequest: return request -def onResponse(context, response): +def onResponse(context: CaptureContext, response: CaptureHttpResponse) -> CaptureHttpResponse: return response \ No newline at end of file diff --git a/reqable/main.py b/reqable/main.py index babcdd3..fe93435 100644 --- a/reqable/main.py +++ b/reqable/main.py @@ -1,7 +1,7 @@ import sys import json -from reqable import CaptureContext, CaptureHttpRequest, CaptureHttpResponse -import addons +from reqable.reqable import CaptureContext, CaptureHttpRequest, CaptureHttpResponse +from reqable import addons def main(): argv = sys.argv[1:] From 74d9e06dd144400c951705f2002939ec0cab52fa Mon Sep 17 00:00:00 2001 From: cesar Date: Mon, 17 Jun 2024 00:02:10 +0800 Subject: [PATCH 02/11] Fix ModuleNotFoundError when running reqable script directly --- reqable/__init__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/reqable/__init__.py b/reqable/__init__.py index f317161..0dbeeda 100644 --- a/reqable/__init__.py +++ b/reqable/__init__.py @@ -1,4 +1 @@ -import main - -if __name__== '__main__': - main.main() \ No newline at end of file +from reqable.reqable import * \ No newline at end of file From 64a447b02a373db2cee3538b792c22fec5603571 Mon Sep 17 00:00:00 2001 From: MegatronKing <1256980529@qq.com> Date: Thu, 1 Aug 2024 17:48:39 +0800 Subject: [PATCH 03/11] Fix lost url params issue --- reqable/reqable.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/reqable/reqable.py b/reqable/reqable.py index f6c2290..6cc7497 100644 --- a/reqable/reqable.py +++ b/reqable/reqable.py @@ -712,6 +712,7 @@ def __init__(self, json): self._trailers = CaptureHttpHeaders(json.get('trailers')) from urllib.parse import urlparse url = urlparse('https://reqable.com' + json['path']) + self._params = url.params self._path = url.path self._queries = CaptureHttpQueries.parse(url.query) @@ -812,10 +813,11 @@ def mime(self) -> Union[str, None]: # Serialize the request fields to a dict. def serialize(self) -> dict: - if len(self.queries) == 0: - path = self.path - else: - path = self.path + '?' + self.queries.serialize() + path = self.path + if self._params != None and self._params != '': + path = path + ';' + self._params + if len(self.queries) != 0: + path = path + '?' + self.queries.serialize() return { 'method': self.method, 'path': path, From a8ab5db0ebfb982f48e2a83b8638dfdd816c2f7d Mon Sep 17 00:00:00 2001 From: MegatronKing <1256980529@qq.com> Date: Sun, 3 Nov 2024 19:42:44 +0800 Subject: [PATCH 04/11] Remove prefix 'Capture' of class name --- reqable/main.py | 2 + reqable/reqable.py | 149 +++++++++++++++++++++++++++------------------ 2 files changed, 93 insertions(+), 58 deletions(-) diff --git a/reqable/main.py b/reqable/main.py index babcdd3..fff9575 100644 --- a/reqable/main.py +++ b/reqable/main.py @@ -25,6 +25,7 @@ def onRequest(request): callback.write(json.dumps({ 'request': result.serialize(), 'env': context.env, + 'highlight': context.highlight, 'shared': context.shared, })) @@ -38,6 +39,7 @@ def onResponse(response): callback.write(json.dumps({ 'response': result.serialize(), 'env': context.env, + 'highlight': context.highlight, 'shared': context.shared, })) diff --git a/reqable/reqable.py b/reqable/reqable.py index 6cc7497..c1f374c 100644 --- a/reqable/reqable.py +++ b/reqable/reqable.py @@ -2,9 +2,10 @@ import uuid import os from email.message import EmailMessage +from enum import Enum from typing import Union, List, Tuple, Dict -class CaptureApp: +class App: def __init__(self, json: dict): self._name = json['name'] self._id = json.get('id') @@ -35,7 +36,16 @@ def serialize(self) -> dict: 'path': self._path, } -class CaptureContext: +class Highlight(Enum): + none = 0 + red = 1 + yellow = 2 + green = 3 + blue = 4 + teal = 5 + strikethrough = 6 + +class Context: def __init__(self, json: dict): self._url = json['url'] self._scheme = json['scheme'] @@ -50,7 +60,8 @@ def __init__(self, json: dict): if app is None: self._app = None else: - self._app = CaptureApp(app) + self._app = App(app) + self._highlight = None self.shared = json.get('shared') def __str__(self): @@ -114,9 +125,18 @@ def env(self) -> Dict[str, str]: # App info, return None means unknown app. @property - def app(self) -> Union[CaptureApp, None]: + def app(self) -> Union[App, None]: return self._app + @property + def highlight(self) -> Union[None, int]: + return self._highlight + + # Set the highlight color. + @highlight.setter + def highlight(self, highlight: Highlight): + self._highlight = highlight.value + def toJson(self) -> str: return json.dumps({ 'url': self._url, @@ -130,9 +150,10 @@ def toJson(self) -> str: 'env': self._env, 'app': self._app.serialize(), 'shared': self.shared, + 'highlight': self._highlight, }) -class CaptureHttpQueries: +class HttpQueries: def __init__(self, entries = None, origin = None): if entries is None: @@ -259,7 +280,7 @@ def toJson(self) -> str: def serialize(self) -> str: return self.origin if self.mod == 0 else self.concat() -class CaptureHttpHeaders: +class HttpHeaders: def __init__(self, entries = None): self._entries = ([] if entries is None else entries) @@ -364,7 +385,7 @@ def toJson(self) -> str: def serialize(self) -> List[str]: return self._entries -class CaptureHttpBody: +class HttpBody: __type_none = 0 __type_text = 1 @@ -386,7 +407,7 @@ def of(cls, data = None): elif isinstance(data, bytes): type = cls.__type_binary payload = data - elif isinstance(data, CaptureHttpBody): + elif isinstance(data, HttpBody): return data else: type = cls.__type_none @@ -414,7 +435,7 @@ def parse(cls, dict): elif type == cls.__type_multipart: payload = [] for multipart in dict['payload']: - payload.append(CaptureHttpMultipartBody(multipart)) + payload.append(HttpMultipartBody(multipart)) return cls(type, payload) def __repr__(self): @@ -462,38 +483,38 @@ def payload(self) -> Union[None, str, bytes, List]: # Determine whether the body is None. @property def isNone(self) -> bool: - return self._type is CaptureHttpBody.__type_none + return self._type is HttpBody.__type_none # Determine whether the body is a text string. @property def isText(self) -> bool: - return self._type is CaptureHttpBody.__type_text + return self._type is HttpBody.__type_text # Determine whether the body is a binary bytes. @property def isBinary(self) -> bool: - return self._type is CaptureHttpBody.__type_binary + return self._type is HttpBody.__type_binary # Determine whether the body is a multipart type. @property def isMultipart(self) -> bool: - return self._type is CaptureHttpBody.__type_multipart + return self._type is HttpBody.__type_multipart # Set the body to None. def none(self): - self._type = CaptureHttpBody.__type_none + self._type = HttpBody.__type_none self._payload = None # Set the body to a text string. def text(self, value: str): - self._type = CaptureHttpBody.__type_text + self._type = HttpBody.__type_text self._payload = value # Set the body to a specified file content, the file content must be a text string. def textFromFile(self, value: str): with open(value, mode = 'r', encoding='UTF-8') as file: self._payload = file.read() - self._type = CaptureHttpBody.__type_text + self._type = HttpBody.__type_text # Set the body to the specified file content, the file content must be a binary bytes. def file(self, value: str): @@ -503,11 +524,11 @@ def file(self, value: str): # Set the body to binary bytes. def binary(self, value: Union[str, bytes]): if isinstance(value, str): - self._type = CaptureHttpBody.__type_binary + self._type = HttpBody.__type_binary with open(value, mode = 'rb') as file: self._payload = file.read() if isinstance(value, bytes): - self._type = CaptureHttpBody.__type_binary + self._type = HttpBody.__type_binary self._payload = value # Set the body to binary bytes. @@ -516,11 +537,11 @@ def multiparts(self, value: list): return payload = [] for multipart in value: - if isinstance(multipart, CaptureHttpMultipartBody): + if isinstance(multipart, HttpMultipartBody): payload.append(multipart) if len(payload) == 0: return - self._type = CaptureHttpBody.__type_multipart + self._type = HttpBody.__type_multipart self._payload = payload # Convert the body content to a json dict. @@ -576,14 +597,14 @@ def serialize(self): if isinstance(self._payload, str): if len(self._payload) == 0: payload = None - type = CaptureHttpBody.__type_none + type = HttpBody.__type_none else: payload = self._payload else: payload = json.dumps(self._payload) elif self.isBinary: if len(self._payload) == 0: - type = CaptureHttpBody.__type_none + type = HttpBody.__type_none payload = None else: payload = os.path.join(os.getcwd(), 'tmp-' + str(uuid.uuid4())) @@ -591,7 +612,7 @@ def serialize(self): file.write(self._payload) elif self.isMultipart: if len(self._payload) == 0: - type = CaptureHttpBody.__type_none + type = HttpBody.__type_none payload = None else: payload = [] @@ -602,11 +623,11 @@ def serialize(self): 'payload': payload, } -class CaptureHttpMultipartBody(CaptureHttpBody): +class HttpMultipartBody(HttpBody): def __init__(self, json: dict): - self._headers = CaptureHttpHeaders(json['headers']) - body = CaptureHttpBody.parse(json['body']) + self._headers = HttpHeaders(json['headers']) + body = HttpBody.parse(json['body']) super().__init__(body.type, body.payload) def _concatDisposition(name: str, filename: str, type: str): @@ -623,7 +644,7 @@ def text(cls, text: str, name: str = '', filename: str = '', headers = None, typ if headers is None: headers = [] headers.append(f'content-length: {len(text)}') - disposition = CaptureHttpMultipartBody._concatDisposition(name, filename, type) + disposition = HttpMultipartBody._concatDisposition(name, filename, type) if disposition is not None: headers.append(f'content-disposition: {disposition}') return cls({ @@ -639,7 +660,7 @@ def file(cls, file: str, name: str = '', filename: str = '', headers = None, typ if headers is None: headers = [] headers.append(f'content-length: {os.stat(file).st_size}') - disposition = CaptureHttpMultipartBody._concatDisposition(name, filename, type) + disposition = HttpMultipartBody._concatDisposition(name, filename, type) if disposition is not None: headers.append(f'content-disposition: {disposition}') return cls({ @@ -652,13 +673,13 @@ def file(cls, file: str, name: str = '', filename: str = '', headers = None, typ # Get the part headers. @property - def headers(self) -> CaptureHttpHeaders: + def headers(self) -> HttpHeaders: return self._headers # Set the part headers. @headers.setter def headers(self, data: Union[List[str], List[Tuple[str, str]], Dict[str, str]]): - self._headers = CaptureHttpHeaders.of(data) + self._headers = HttpHeaders.of(data) # Get the part name. @property @@ -703,18 +724,18 @@ def _setDispositionParamValue(self, param, value): message.set_param(param, value, header='content-disposition') self._headers['content-disposition'] = message.get('content-disposition') -class CaptureHttpRequest: +class HttpRequest: def __init__(self, json): self._method = json['method'] self._protocol = json['protocol'] - self._headers = CaptureHttpHeaders(json.get('headers')) - self._body = CaptureHttpBody.parse(json.get('body')) - self._trailers = CaptureHttpHeaders(json.get('trailers')) + self._headers = HttpHeaders(json.get('headers')) + self._body = HttpBody.parse(json.get('body')) + self._trailers = HttpHeaders(json.get('trailers')) from urllib.parse import urlparse url = urlparse('https://reqable.com' + json['path']) self._params = url.params self._path = url.path - self._queries = CaptureHttpQueries.parse(url.query) + self._queries = HttpQueries.parse(url.query) def __str__(self): return self.toJson() @@ -758,43 +779,43 @@ def path(self, data: str): # Get the request query paramaters. @property - def queries(self) -> CaptureHttpQueries: + def queries(self) -> HttpQueries: return self._queries # Set the request query paramaters. @queries.setter def queries(self, data: Union[str, List[Tuple[str, str]], Dict[str, str]]): - self._queries = CaptureHttpQueries.of(data) + self._queries = HttpQueries.of(data) # Get the request headers. @property - def headers(self) -> CaptureHttpHeaders: + def headers(self) -> HttpHeaders: return self._headers # Set the request headers. @headers.setter def headers(self, data: Union[List[str], List[Tuple[str, str]], Dict[str, str]]): - self._headers = CaptureHttpHeaders.of(data) + self._headers = HttpHeaders.of(data) # Get the request trailers. Note that the implementation of this function is incomplete, please do not use it. @property - def trailers(self) -> CaptureHttpHeaders: + def trailers(self) -> HttpHeaders: return self._trailers # Set the request trailers. Note that the implementation of this function is incomplete, please do not use it. @trailers.setter def trailers(self, data: Union[List[str], List[Tuple[str, str]], Dict[str, str]]): - self._trailers = CaptureHttpHeaders.of(data) + self._trailers = HttpHeaders.of(data) # Get the request body. @property - def body(self) -> CaptureHttpBody: + def body(self) -> HttpBody: return self._body # Set the request body. @body.setter - def body(self, data: Union[str, bytes, dict, CaptureHttpBody]): - self._body = CaptureHttpBody.of(data) + def body(self, data: Union[str, bytes, dict, HttpBody]): + self._body = HttpBody.of(data) # Get the request content type from headers. @property @@ -830,15 +851,15 @@ def serialize(self) -> dict: def toJson(self) -> str: return json.dumps(self.serialize()) -class CaptureHttpResponse: +class HttpResponse: def __init__(self, json): - self._request = CaptureHttpRequest(json['request']) + self._request = HttpRequest(json['request']) self._code = json['code'] self._message = json['message'] self._protocol = json['protocol'] - self._headers = CaptureHttpHeaders(json.get('headers')) - self._body = CaptureHttpBody.parse(json.get('body')) - self._trailers = CaptureHttpHeaders(json.get('trailers')) + self._headers = HttpHeaders(json.get('headers')) + self._body = HttpBody.parse(json.get('body')) + self._trailers = HttpHeaders(json.get('trailers')) def __str__(self): return self.toJson() @@ -851,7 +872,7 @@ def __radd__(self, other): # Get the request informations. @property - def request(self) -> CaptureHttpRequest: + def request(self) -> HttpRequest: return self._request # Get the response status code. @@ -879,33 +900,33 @@ def protocol(self) -> str: # Get the response headers. @property - def headers(self) -> CaptureHttpHeaders: + def headers(self) -> HttpHeaders: return self._headers # Set the response headers. @headers.setter def headers(self, data: Union[List[str], List[Tuple[str, str]], Dict[str, str]]): - self._headers = CaptureHttpHeaders.of(data) + self._headers = HttpHeaders.of(data) # Set the response trailers. Note that the implementation of this function is incomplete, please do not use it. @property - def trailers(self) -> CaptureHttpHeaders: + def trailers(self) -> HttpHeaders: return self._trailers # Get the response trailers. Note that the implementation of this function is incomplete, please do not use it. @trailers.setter def trailers(self, data: Union[List[str], List[Tuple[str, str]], Dict[str, str]]): - self._trailers = CaptureHttpHeaders.of(data) + self._trailers = HttpHeaders.of(data) # Get the response body. @property - def body(self) -> CaptureHttpBody: + def body(self) -> HttpBody: return self._body # Set the response body. @body.setter - def body(self, data: Union[str, bytes, dict, CaptureHttpBody]): - self._body = CaptureHttpBody.of(data) + def body(self, data: Union[str, bytes, dict, HttpBody]): + self._body = HttpBody.of(data) # Get the response content type from headers. @property @@ -935,4 +956,16 @@ def serialize(self) -> dict: } def toJson(self) -> str: - return json.dumps(self.serialize()) \ No newline at end of file + return json.dumps(self.serialize()) + +#################################################################################################### +# Below is the legacy classes, they are deprecated and will be removed in the future. +#################################################################################################### +CaptureApp = App +CaptureContext = Context +CaptureHttpQueries = HttpQueries +CaptureHttpHeaders = HttpHeaders +CaptureHttpBody = HttpBody +CaptureHttpMultipartBody = HttpMultipartBody +CaptureHttpRequest = HttpRequest +CaptureHttpResponse = HttpResponse \ No newline at end of file From 90d36a4e1c4b7556d622c905310cdf4599605082 Mon Sep 17 00:00:00 2001 From: MegatronKing <1256980529@qq.com> Date: Fri, 15 Nov 2024 15:37:22 +0800 Subject: [PATCH 05/11] Add comment api --- reqable/main.py | 2 ++ reqable/reqable.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/reqable/main.py b/reqable/main.py index fff9575..3c9caae 100644 --- a/reqable/main.py +++ b/reqable/main.py @@ -26,6 +26,7 @@ def onRequest(request): 'request': result.serialize(), 'env': context.env, 'highlight': context.highlight, + 'comment': context.comment, 'shared': context.shared, })) @@ -40,6 +41,7 @@ def onResponse(response): 'response': result.serialize(), 'env': context.env, 'highlight': context.highlight, + 'comment': context.comment, 'shared': context.shared, })) diff --git a/reqable/reqable.py b/reqable/reqable.py index c1f374c..cb6e221 100644 --- a/reqable/reqable.py +++ b/reqable/reqable.py @@ -56,6 +56,7 @@ def __init__(self, json: dict): self._sid = json['sid'] self._stime = json['stime'] self._env = json.get('env') + self._comment = json.get('comment') app = json.get('app') if app is None: self._app = None @@ -137,6 +138,16 @@ def highlight(self) -> Union[None, int]: def highlight(self, highlight: Highlight): self._highlight = highlight.value + # Get the comment. + @property + def comment(self) -> Union[None, int]: + return self._comment + + # Set the comment. + @comment.setter + def comment(self, comment: str): + self._comment = comment + def toJson(self) -> str: return json.dumps({ 'url': self._url, @@ -151,6 +162,7 @@ def toJson(self) -> str: 'app': self._app.serialize(), 'shared': self.shared, 'highlight': self._highlight, + 'comment': self._comment, }) class HttpQueries: From 978d35dcebde6ac1d579a71ad43e5d12877bfcf5 Mon Sep 17 00:00:00 2001 From: MegatronKing <1256980529@qq.com> Date: Thu, 27 Feb 2025 11:05:10 +0800 Subject: [PATCH 06/11] Add charset field for text payload --- reqable/reqable.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/reqable/reqable.py b/reqable/reqable.py index cb6e221..16cc5b8 100644 --- a/reqable/reqable.py +++ b/reqable/reqable.py @@ -404,9 +404,10 @@ class HttpBody: __type_binary = 2 __type_multipart = 3 - def __init__(self, type: int = 0, payload = None): + def __init__(self, type: int = 0, payload = None, charset = None): self._type = type self._payload = payload + self._charset = charset @classmethod def of(cls, data = None): @@ -424,7 +425,7 @@ def of(cls, data = None): else: type = cls.__type_none payload = None - return cls(type, payload) + return cls(type, payload, 'utf-8') @classmethod def parse(cls, dict): @@ -433,10 +434,13 @@ def parse(cls, dict): type = dict['type'] if type == cls.__type_none: payload = None + charset = None elif type == cls.__type_text: - payload = dict['payload'] + payload = dict['payload']['text'] + charset = dict['payload']['charset'] elif type == cls.__type_binary: payload = dict['payload'] + charset = None if isinstance(payload, str): with open(payload, mode = 'rb') as file: payload = file.read() @@ -446,9 +450,10 @@ def parse(cls, dict): payload = bytes() elif type == cls.__type_multipart: payload = [] + charset = None for multipart in dict['payload']: payload.append(HttpMultipartBody(multipart)) - return cls(type, payload) + return cls(type, payload, charset) def __repr__(self): if self.isMultipart: @@ -611,9 +616,15 @@ def serialize(self): payload = None type = HttpBody.__type_none else: - payload = self._payload + payload = { + 'text': self._payload, + 'charset': self._charset + } else: - payload = json.dumps(self._payload) + payload = { + 'text': json.dumps(self._payload), + 'charset': self._charset + } elif self.isBinary: if len(self._payload) == 0: type = HttpBody.__type_none From 2727e2478223fd0b2c411b39ded8ab26e8d89880 Mon Sep 17 00:00:00 2001 From: MegatronKing <1256980529@qq.com> Date: Tue, 4 Mar 2025 19:15:26 +0800 Subject: [PATCH 07/11] Fixed a charset issue for multiparts --- reqable/reqable.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/reqable/reqable.py b/reqable/reqable.py index 16cc5b8..3675bbb 100644 --- a/reqable/reqable.py +++ b/reqable/reqable.py @@ -425,7 +425,7 @@ def of(cls, data = None): else: type = cls.__type_none payload = None - return cls(type, payload, 'utf-8') + return cls(type, payload, 'UTF-8') @classmethod def parse(cls, dict): @@ -663,7 +663,7 @@ def _concatDisposition(name: str, filename: str, type: str): return None @classmethod - def text(cls, text: str, name: str = '', filename: str = '', headers = None, type = 'form-data'): + def text(cls, text: str, name: str = '', filename: str = '', headers = None, type = 'form-data', charset= 'UTF-8'): if headers is None: headers = [] headers.append(f'content-length: {len(text)}') @@ -674,7 +674,10 @@ def text(cls, text: str, name: str = '', filename: str = '', headers = None, typ 'headers': headers, 'body': { 'type': 1, - 'payload': text + 'payload': { + 'text': text, + 'charset': charset + } } }) From caf39cdd6636ce1f912c112342e4f66f87911ab4 Mon Sep 17 00:00:00 2001 From: MegatronKing <1256980529@qq.com> Date: Mon, 17 Mar 2025 18:06:08 +0800 Subject: [PATCH 08/11] add current path to python search path --- reqable/main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/reqable/main.py b/reqable/main.py index 3c9caae..7d95dc1 100644 --- a/reqable/main.py +++ b/reqable/main.py @@ -1,4 +1,10 @@ import sys +import os + +pwd = os.path.dirname(os.path.abspath(__file__)) +if pwd not in sys.path: + sys.path.append(pwd) + import json from reqable import CaptureContext, CaptureHttpRequest, CaptureHttpResponse import addons From 6c8b045a16877d90188b8306df4f671ab654c1c4 Mon Sep 17 00:00:00 2001 From: MegatronKing <1256980529@qq.com> Date: Tue, 15 Apr 2025 16:38:44 +0800 Subject: [PATCH 09/11] Support setItem for binary and multipart body --- reqable/reqable.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/reqable/reqable.py b/reqable/reqable.py index 3675bbb..301a813 100644 --- a/reqable/reqable.py +++ b/reqable/reqable.py @@ -585,12 +585,18 @@ def __getitem__(self, name: Union[str, int]): return self._payload[name] return None - # Set the json dict value by name. Note: you must call jsonify() before this. - def __setitem__(self, name: str, value): + # If the body type is a json dict, set the value. Note: you must call jsonify() before this. + # If the body type is binary, set the value at the index. + # If the body type is multipart, set the part at the index. + def __setitem__(self, name: Union[str, int], value): if self.isText: if not isinstance(self._payload, dict): raise Exception('Did you forget to call `jsonify()` before operating json dict?') self._payload[name] = value + if self.isBinary and isinstance(name, int): + self._payload[name] = value + if self.isMultipart and isinstance(name, int): + self._payload[name] = value # Write the body content to a file. def writeFile(self, path: str): From a9be5bcf65a6d10887508e140d8a5cf5f50e1d3d Mon Sep 17 00:00:00 2001 From: MegatronKing <1256980529@qq.com> Date: Wed, 7 May 2025 12:11:52 +0800 Subject: [PATCH 10/11] update version to 1.1.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f51c49b..114c952 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="reqable-scripting", - version="1.0.0", + version="1.1.0", author="MegatronKing", author_email="coding@reqable.com", url="https://reqable.com/docs/capture/addons", From 03a31eddb94f856178100e9618627d9eecfc5c1d Mon Sep 17 00:00:00 2001 From: MegatronKing <1256980529@qq.com> Date: Wed, 7 May 2025 12:14:40 +0800 Subject: [PATCH 11/11] update version to 1.2.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 114c952..5d99619 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="reqable-scripting", - version="1.1.0", + version="1.2.0", author="MegatronKing", author_email="coding@reqable.com", url="https://reqable.com/docs/capture/addons",