OwlCyberSecurity - MANAGER
Edit File: local.cpython-39.pyc
a ���e� � @ s: d dl Z d dlZd dlZd dlZd dlZG dd� d�ZdS )� Nc sZ e Zd ZdZdedd�dd�Zdd� Zd d � Zdd� Zd d� Z � fdd�Z dd� Z� ZS )�Locala� A drop-in replacement for threading.locals that also works with asyncio Tasks (via the current_task asyncio method), and passes locals through sync_to_async and async_to_sync. Specifically: - Locals work per-coroutine on any thread not spawned using asgiref - Locals work per-thread on any thread not spawned using asgiref - Locals are shared with the parent coroutine when using sync_to_async - Locals are shared with the parent thread when using async_to_sync (and if that thread was launched using sync_to_async, with its parent coroutine as well, with this working for indefinite levels of nesting) Set thread_critical to True to not allow locals to pass from an async Task to a thread it spawns. This is needed for code that truly needs thread-safety, as opposed to things used for helpful context (e.g. sqlite does not like being called from a different thread to the one it is from). Thread-critical code will still be differentiated per-Task within a thread as it is expected it does not like concurrent access. This doesn't use contextvars as it needs to support 3.6. Once it can support 3.7 only, we can then reimplement the storage more nicely. FN)�thread_critical�returnc C sD || _ t�� | _t�� | _d�t| �d� dd� t d�D ���| _d S )Nz_asgiref_local_impl_{}_{}� c s s | ]}t �tj�V qd S �N)�random�choice�string� ascii_letters)�.0�i� r �N/home/gouroczh/virtualenv/pat/3.9/lib/python3.9/site-packages/asgiref/local.py� <genexpr>) � z!Local.__init__.<locals>.<genexpr>� )�_thread_critical� threading�RLock�_thread_lock�weakref�WeakSet� _context_refs�format�id�join�range� _attr_name)�selfr r r r �__init__! s �zLocal.__init__c C s� ddl m}m} |�� }d}|du r0t�� }d}| jr:|S tt� � �D ]D}z&|r`|j | }d}n|j | }d}W qF ty� Y q�Y qF0 qFtd��|S )zC Get the ID we should use for looking up variables � )�AsyncToSync�SyncToAsyncTNFzInfinite launch_map loops) �syncr! r"