-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e72e329
commit 64da657
Showing
9 changed files
with
353 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from openfeature.transaction_context.context_var_transaction_context_propagator import ( | ||
ContextVarsTransactionContextPropagator, | ||
) | ||
from openfeature.transaction_context.no_op_transaction_context_propagator import ( | ||
NoOpTransactionContextPropagator, | ||
) | ||
from openfeature.transaction_context.transaction_context_propagator import ( | ||
TransactionContextPropagator, | ||
) | ||
|
||
__all__ = [ | ||
"TransactionContextPropagator", | ||
"NoOpTransactionContextPropagator", | ||
"ContextVarsTransactionContextPropagator", | ||
] |
18 changes: 18 additions & 0 deletions
18
openfeature/transaction_context/context_var_transaction_context_propagator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from contextvars import ContextVar | ||
|
||
from openfeature.evaluation_context import EvaluationContext | ||
from openfeature.transaction_context.transaction_context_propagator import ( | ||
TransactionContextPropagator, | ||
) | ||
|
||
_transaction_context_var: ContextVar[EvaluationContext] = ContextVar( | ||
"transaction_context", default=EvaluationContext() | ||
) | ||
|
||
|
||
class ContextVarsTransactionContextPropagator(TransactionContextPropagator): | ||
def get_transaction_context(self) -> EvaluationContext: | ||
return _transaction_context_var.get() | ||
|
||
def set_transaction_context(self, transaction_context: EvaluationContext) -> None: | ||
_transaction_context_var.set(transaction_context) |
12 changes: 12 additions & 0 deletions
12
openfeature/transaction_context/no_op_transaction_context_propagator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from openfeature.evaluation_context import EvaluationContext | ||
from openfeature.transaction_context.transaction_context_propagator import ( | ||
TransactionContextPropagator, | ||
) | ||
|
||
|
||
class NoOpTransactionContextPropagator(TransactionContextPropagator): | ||
def get_transaction_context(self) -> EvaluationContext: | ||
return EvaluationContext() | ||
|
||
def set_transaction_context(self, transaction_context: EvaluationContext) -> None: | ||
pass |
16 changes: 16 additions & 0 deletions
16
openfeature/transaction_context/transaction_context_propagator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import TypeVar | ||
|
||
from openfeature.evaluation_context import EvaluationContext | ||
|
||
T = TypeVar("T", bound="TransactionContextPropagator") | ||
|
||
|
||
class TransactionContextPropagator(ABC): | ||
@abstractmethod | ||
def get_transaction_context(self) -> EvaluationContext: | ||
pass | ||
|
||
@abstractmethod | ||
def set_transaction_context(self, transaction_context: EvaluationContext) -> None: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.