moved HEADER_JSON copy to httpclient

This commit is contained in:
NichtJens
2021-06-01 09:04:43 +02:00
parent db884be531
commit c32aa34bf4
2 changed files with 9 additions and 10 deletions

View File

@ -11,10 +11,10 @@ def authenticated(func):
if not issubclass(type(args[0]), HttpClient):
raise AttributeError("First argument must be an instance of HttpClient")
if "headers" in kwargs:
kwargs["headers"]["Authorization"] = args[0].token
kwargs["headers"] = kwargs["headers"].copy()
else:
kwargs["headers"] = {}
kwargs["headers"]["Authorization"] = args[0].token
kwargs["headers"]["Authorization"] = args[0].token
return func(*args, **kwargs)
return authenticated_call

View File

@ -1,7 +1,6 @@
from __future__ import annotations
from .authclient import AuthMixin, AuthError, HEADER_JSON
from .mkfilt import make_filter
from .httpclient import HttpClient
from .snippet import Snippet, Basesnippet, Paragraph
from typing import TypeVar, Union, List, Type, get_type_hints
@ -51,17 +50,15 @@ class SciLog():
url = self.http_client.address + "/basesnippets"
snippet = Paragraph()
snippet.import_dict(kwargs)
snippet.textcontent = msg
snippet.textcontent = msg
payload = snippet.to_dict(include_none=False)
headers = HEADER_JSON.copy()
return Basesnippet.from_http_response(self.http_client.post_request(url, payload=payload, headers=headers))
return Basesnippet.from_http_response(self.http_client.post_request(url, payload=payload, headers=HEADER_JSON))
@pinned_to_logbook(["parentId", "ownerGroup", "accessGroups"])
def post_snippet(self, **kwargs):
url = self.http_client.address + "/basesnippets"
payload = kwargs
headers = HEADER_JSON.copy()
return Basesnippet.from_http_response(self.http_client.post_request(url, payload=payload, headers=headers))
return Basesnippet.from_http_response(self.http_client.post_request(url, payload=payload, headers=HEADER_JSON))
def get_logbooks(self, **kwargs):
url = self.http_client.address + "/basesnippets"
@ -69,9 +66,11 @@ class SciLog():
snippet.import_dict(kwargs)
snippet.snippetType = "logbook"
params = self.http_client.make_filter(where=snippet.to_dict(include_none=False))
headers = HEADER_JSON.copy()
return Basesnippet.from_http_response(self.http_client.get_request(url, params=params, headers=headers))
return Basesnippet.from_http_response(self.http_client.get_request(url, params=params, headers=HEADER_JSON))
class SciLogAuthError(AuthError):
pass