aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2022-03-08 11:00:00 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2022-09-18 16:36:55 +0200
commit54ff86d9ac7de7e77b2d7a2a75dc9b8b4876438f (patch)
tree8ede3386329024afc3444430f0f8d2ef825137b2 /wee_slack.py
parent962bbc527537091cd1abfb0b95eb8bcd7a006d46 (diff)
downloadwee-slack-54ff86d9ac7de7e77b2d7a2a75dc9b8b4876438f.tar.gz
Support specifying both url encoded and raw (not url encoded) cookies
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 6c7a80a..3e80089 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -59,9 +59,9 @@ except ImportError:
Reversible = object
try:
- from urllib.parse import quote, urlencode
+ from urllib.parse import quote, unquote, urlencode
except ImportError:
- from urllib import quote, urlencode
+ from urllib import quote, unquote, urlencode
try:
JSONDecodeError = json.JSONDecodeError
@@ -393,6 +393,15 @@ def format_exc_only():
return "".join(decode_from_utf8(traceback.format_exception_only(etype, value)))
+def url_encode_if_not_encoded(value):
+ decoded = unquote(value)
+ is_encoded = value != decoded
+ if is_encoded:
+ return value
+ else:
+ return quote(value)
+
+
def get_localvar_type(slack_type):
if slack_type in ("im", "mpim"):
return "private"
@@ -1478,7 +1487,10 @@ class SlackRequest(object):
def options(self):
cookies = "; ".join(
- ["{}={}".format(key, value) for key, value in self.cookies.items()]
+ [
+ "{}={}".format(key, url_encode_if_not_encoded(value))
+ for key, value in self.cookies.items()
+ ]
)
return {
"useragent": "wee_slack {}".format(SCRIPT_VERSION),