File: api.py

package info (click to toggle)
python-django-guid 3.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 664 kB
  • sloc: python: 1,267; makefile: 16
file content (33 lines) | stat: -rw-r--r-- 690 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import logging

from django_guid.context import guid

logger = logging.getLogger('django_guid')


def get_guid() -> str:
    """
    Fetches the GUID of the current request
    """
    return guid.get()


def set_guid(new_guid: str) -> str:
    """
    Assigns a GUID to the current request
    """
    old_guid = guid.get()
    if old_guid:
        logger.info('Changing the guid ContextVar from %s to %s', old_guid, new_guid)
    guid.set(new_guid)
    return new_guid


def clear_guid() -> None:
    """
    Clears the GUID of the current request
    """
    old_guid = guid.get()
    if old_guid:
        logger.info('Clearing %s from the guid ContextVar', old_guid)
    guid.set(None)