kopia lustrzana https://gitlab.com/jaywink/federation
Optionally support PUT in send_document
Defaults to POST. Matrix display name update uses PUT.matrix-delivery
rodzic
602c576aec
commit
3dd9921899
|
|
@ -67,13 +67,14 @@ class MatrixProfile(Profile, MatrixEntityMixin):
|
||||||
"payload": {
|
"payload": {
|
||||||
"username": f"{self.localpart}",
|
"username": f"{self.localpart}",
|
||||||
"type": "m.login.application_service",
|
"type": "m.login.application_service",
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
payloads.append({
|
payloads.append({
|
||||||
"endpoint": f"{super().get_endpoint()}/profile/{self.mxid}/displayname",
|
"endpoint": f"{super().get_endpoint()}/profile/{self.mxid}/displayname",
|
||||||
"payload": {
|
"payload": {
|
||||||
"displayname": self.name,
|
"displayname": self.name,
|
||||||
},
|
},
|
||||||
|
"method": "put",
|
||||||
})
|
})
|
||||||
# TODO avatar url in mxc format
|
# TODO avatar url in mxc format
|
||||||
return payloads
|
return payloads
|
||||||
|
|
|
||||||
|
|
@ -142,18 +142,21 @@ def handle_send(
|
||||||
"headers": {},
|
"headers": {},
|
||||||
"payload": None,
|
"payload": None,
|
||||||
"urls": set(),
|
"urls": set(),
|
||||||
|
"method": None,
|
||||||
},
|
},
|
||||||
"diaspora": {
|
"diaspora": {
|
||||||
"auth": None,
|
"auth": None,
|
||||||
"headers": {},
|
"headers": {},
|
||||||
"payload": None,
|
"payload": None,
|
||||||
"urls": set(),
|
"urls": set(),
|
||||||
|
"method": None,
|
||||||
},
|
},
|
||||||
"matrix": {
|
"matrix": {
|
||||||
"auth": None,
|
"auth": None,
|
||||||
"headers": {},
|
"headers": {},
|
||||||
"payload": None,
|
"payload": None,
|
||||||
"urls": set(),
|
"urls": set(),
|
||||||
|
"method": None,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
skip_ready_payload = {
|
skip_ready_payload = {
|
||||||
|
|
@ -288,7 +291,6 @@ def handle_send(
|
||||||
# Don't try to do anything with these entities currently
|
# Don't try to do anything with these entities currently
|
||||||
skip_ready_payload["matrix"] = True
|
skip_ready_payload["matrix"] = True
|
||||||
continue
|
continue
|
||||||
# noinspection PyBroadException
|
|
||||||
payload_info = []
|
payload_info = []
|
||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
try:
|
try:
|
||||||
|
|
@ -314,6 +316,7 @@ def handle_send(
|
||||||
},
|
},
|
||||||
"payload": rendered_payload,
|
"payload": rendered_payload,
|
||||||
"urls": {payload["endpoint"]},
|
"urls": {payload["endpoint"]},
|
||||||
|
"method": payload["method"],
|
||||||
})
|
})
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error(
|
logger.error(
|
||||||
|
|
@ -355,6 +358,7 @@ def handle_send(
|
||||||
payload["payload"],
|
payload["payload"],
|
||||||
auth=payload["auth"],
|
auth=payload["auth"],
|
||||||
headers=payload["headers"],
|
headers=payload["headers"],
|
||||||
|
method=payload["method"],
|
||||||
)
|
)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.error("handle_send - failed to send payload to %s: %s, payload: %s", url, ex, payload["payload"])
|
logger.error("handle_send - failed to send payload to %s: %s, payload: %s", url, ex, payload["payload"])
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@ def parse_http_date(date):
|
||||||
raise ValueError("%r is not a valid date" % date) from exc
|
raise ValueError("%r is not a valid date" % date) from exc
|
||||||
|
|
||||||
|
|
||||||
def send_document(url, data, timeout=10, *args, **kwargs):
|
def send_document(url, data, timeout=10, method="post", *args, **kwargs):
|
||||||
"""Helper method to send a document via POST.
|
"""Helper method to send a document via POST.
|
||||||
|
|
||||||
Additional ``*args`` and ``**kwargs`` will be passed on to ``requests.post``.
|
Additional ``*args`` and ``**kwargs`` will be passed on to ``requests.post``.
|
||||||
|
|
@ -165,9 +165,10 @@ def send_document(url, data, timeout=10, *args, **kwargs):
|
||||||
:arg url: Full url to send to, including protocol
|
:arg url: Full url to send to, including protocol
|
||||||
:arg data: Dictionary (will be form-encoded), bytes, or file-like object to send in the body
|
:arg data: Dictionary (will be form-encoded), bytes, or file-like object to send in the body
|
||||||
:arg timeout: Seconds to wait for response (defaults to 10)
|
:arg timeout: Seconds to wait for response (defaults to 10)
|
||||||
|
:arg method: Method to use, defaults to post
|
||||||
:returns: Tuple of status code (int or None) and error (exception class instance or None)
|
:returns: Tuple of status code (int or None) and error (exception class instance or None)
|
||||||
"""
|
"""
|
||||||
logger.debug("send_document: url=%s, data=%s, timeout=%s", url, data, timeout)
|
logger.debug("send_document: url=%s, data=%s, timeout=%s, method=%s", url, data, timeout, method)
|
||||||
headers = CaseInsensitiveDict({
|
headers = CaseInsensitiveDict({
|
||||||
'User-Agent': USER_AGENT,
|
'User-Agent': USER_AGENT,
|
||||||
})
|
})
|
||||||
|
|
@ -177,8 +178,9 @@ def send_document(url, data, timeout=10, *args, **kwargs):
|
||||||
kwargs.update({
|
kwargs.update({
|
||||||
"data": data, "timeout": timeout, "headers": headers
|
"data": data, "timeout": timeout, "headers": headers
|
||||||
})
|
})
|
||||||
|
request_func = getattr(requests, method)
|
||||||
try:
|
try:
|
||||||
response = requests.post(url, *args, **kwargs)
|
response = request_func(url, *args, **kwargs)
|
||||||
logger.debug("send_document: response status code %s", response.status_code)
|
logger.debug("send_document: response status code %s", response.status_code)
|
||||||
return response.status_code, None
|
return response.status_code, None
|
||||||
except RequestException as ex:
|
except RequestException as ex:
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue