mirror of https://github.com/nucypher/nucypher.git
Update code based on limitations of python 3.9. `http.HTTPMethod` and `typing.override` are not available.
parent
a629f9b9a1
commit
504c2d0498
|
@ -1,11 +1,15 @@
|
|||
from http import HTTPMethod
|
||||
from typing import Any, Optional, Tuple, override
|
||||
from typing import Any, Optional, Tuple
|
||||
|
||||
from marshmallow import ValidationError, fields, post_load, validate, validates
|
||||
from marshmallow.fields import Url
|
||||
from typing_extensions import override
|
||||
|
||||
from nucypher.policy.conditions.context import is_context_variable
|
||||
from nucypher.policy.conditions.json.base import JSONPathField, JsonRequestCall
|
||||
from nucypher.policy.conditions.json.base import (
|
||||
HTTPMethod,
|
||||
JSONPathField,
|
||||
JsonRequestCall,
|
||||
)
|
||||
from nucypher.policy.conditions.json.utils import process_result_for_condition_eval
|
||||
from nucypher.policy.conditions.lingo import (
|
||||
ConditionType,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
from abc import ABC
|
||||
from http import HTTPMethod, HTTPStatus
|
||||
from enum import Enum
|
||||
from http import HTTPStatus
|
||||
from typing import Any, Optional
|
||||
|
||||
import requests
|
||||
|
@ -17,6 +18,11 @@ from nucypher.policy.conditions.exceptions import JsonRequestException
|
|||
from nucypher.utilities.logging import Logger
|
||||
|
||||
|
||||
class HTTPMethod(Enum):
|
||||
GET = "GET"
|
||||
POST = "POST"
|
||||
|
||||
|
||||
class JsonRequestCall(ExecutionCall, ABC):
|
||||
TIMEOUT = 5 # seconds
|
||||
|
||||
|
@ -62,15 +68,14 @@ class JsonRequestCall(ExecutionCall, ABC):
|
|||
timeout=self.timeout,
|
||||
headers=headers,
|
||||
)
|
||||
elif self.http_method == HTTPMethod.POST:
|
||||
else:
|
||||
# POST
|
||||
response = requests.post(
|
||||
resolved_endpoint,
|
||||
data=json.dumps(resolved_parameters),
|
||||
timeout=self.timeout,
|
||||
headers=headers,
|
||||
)
|
||||
else:
|
||||
raise RuntimeError(f"Unsupported http method: {self.http_method}")
|
||||
|
||||
response.raise_for_status()
|
||||
if response.status_code != HTTPStatus.OK:
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
from abc import ABC
|
||||
from http import HTTPMethod
|
||||
from typing import Any, Optional, Tuple, override
|
||||
from typing import Any, Optional, Tuple
|
||||
|
||||
from marshmallow import ValidationError, fields, post_load, validate, validates
|
||||
from marshmallow.fields import Url
|
||||
from typing_extensions import override
|
||||
|
||||
from nucypher.policy.conditions.context import is_context_variable
|
||||
from nucypher.policy.conditions.exceptions import (
|
||||
JsonRequestException,
|
||||
)
|
||||
from nucypher.policy.conditions.json.base import JSONPathField, JsonRequestCall
|
||||
from nucypher.policy.conditions.json.base import (
|
||||
HTTPMethod,
|
||||
JSONPathField,
|
||||
JsonRequestCall,
|
||||
)
|
||||
from nucypher.policy.conditions.json.utils import process_result_for_condition_eval
|
||||
from nucypher.policy.conditions.lingo import (
|
||||
ConditionType,
|
||||
|
|
Loading…
Reference in New Issue