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": { | ||||
|                     "username": f"{self.localpart}", | ||||
|                     "type": "m.login.application_service", | ||||
|                 } | ||||
|                 }, | ||||
|             }) | ||||
|         payloads.append({ | ||||
|             "endpoint": f"{super().get_endpoint()}/profile/{self.mxid}/displayname", | ||||
|             "payload": { | ||||
|                 "displayname": self.name, | ||||
|             }, | ||||
|             "method": "put", | ||||
|         }) | ||||
|         # TODO avatar url in mxc format | ||||
|         return payloads | ||||
|  |  | |||
|  | @ -142,18 +142,21 @@ def handle_send( | |||
|             "headers": {}, | ||||
|             "payload": None, | ||||
|             "urls": set(), | ||||
|             "method": None, | ||||
|         }, | ||||
|         "diaspora": { | ||||
|             "auth": None, | ||||
|             "headers": {}, | ||||
|             "payload": None, | ||||
|             "urls": set(), | ||||
|             "method": None, | ||||
|         }, | ||||
|         "matrix": { | ||||
|             "auth": None, | ||||
|             "headers": {}, | ||||
|             "payload": None, | ||||
|             "urls": set(), | ||||
|             "method": None, | ||||
|         }, | ||||
|     } | ||||
|     skip_ready_payload = { | ||||
|  | @ -288,7 +291,6 @@ def handle_send( | |||
|                 # Don't try to do anything with these entities currently | ||||
|                 skip_ready_payload["matrix"] = True | ||||
|                 continue | ||||
|             # noinspection PyBroadException | ||||
|             payload_info = [] | ||||
|             # noinspection PyBroadException | ||||
|             try: | ||||
|  | @ -314,6 +316,7 @@ def handle_send( | |||
|                         }, | ||||
|                         "payload": rendered_payload, | ||||
|                         "urls": {payload["endpoint"]}, | ||||
|                         "method": payload["method"], | ||||
|                     }) | ||||
|             except Exception: | ||||
|                 logger.error( | ||||
|  | @ -355,6 +358,7 @@ def handle_send( | |||
|                     payload["payload"], | ||||
|                     auth=payload["auth"], | ||||
|                     headers=payload["headers"], | ||||
|                     method=payload["method"], | ||||
|                 ) | ||||
|             except Exception as ex: | ||||
|                 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 | ||||
| 
 | ||||
| 
 | ||||
| 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. | ||||
| 
 | ||||
|     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 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 method: Method to use, defaults to post | ||||
|     :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({ | ||||
|         'User-Agent': USER_AGENT, | ||||
|     }) | ||||
|  | @ -177,8 +178,9 @@ def send_document(url, data, timeout=10, *args, **kwargs): | |||
|     kwargs.update({ | ||||
|         "data": data, "timeout": timeout, "headers": headers | ||||
|     }) | ||||
|     request_func = getattr(requests, method) | ||||
|     try: | ||||
|         response = requests.post(url, *args, **kwargs) | ||||
|         response = request_func(url, *args, **kwargs) | ||||
|         logger.debug("send_document: response status code %s", response.status_code) | ||||
|         return response.status_code, None | ||||
|     except RequestException as ex: | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 Jason Robinson
						Jason Robinson