Runs the operation within the context of the given client label.
(client_label: str)
| 51 | |
| 52 | @contextmanager |
| 53 | def client_label_context(client_label: str) -> Iterator[None]: |
| 54 | """Runs the operation within the context of the given client label.""" |
| 55 | current_client_label = _LABEL_CONTEXT.get() |
| 56 | |
| 57 | if current_client_label is not None: |
| 58 | raise ValueError( |
| 59 | "Client label already exists. You can only add one client label." |
| 60 | ) |
| 61 | |
| 62 | token = _LABEL_CONTEXT.set(client_label) |
| 63 | |
| 64 | try: |
| 65 | yield |
| 66 | finally: |
| 67 | # Restore the previous state of the context variable |
| 68 | _LABEL_CONTEXT.reset(token) |
| 69 | |
| 70 | |
| 71 | def get_client_labels() -> List[str]: |
no test coverage detected