o
    h                  	   @   s   d dl mZ d dlmZmZmZmZ d dlmZ d dl	Z	d dl
mZ d dlmZ dedefd	d
Zeddee deeeef fddZdeeef defddZdS )    )contextmanager)Any	GeneratorOptionalUnion)UUIDN)transaction)BaseDatabaseWrapper
connectionreturnc                 C   s&   | j dkrdS tjdk rdS | jdkS )z
    Determine whether the backend requires manual transaction handling.

    Extracted from `exclusive_transaction` for unit testing purposes.
    sqliteF      T	EXCLUSIVE)vendordjangoVERSIONtransaction_mode)r
    r   d/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/django_tasks/backends/database/utils.py0connection_requires_manual_exclusive_transaction
   s
   


r   usingc              
   c   s    t | }t|r@tjdkrtd| }|d z
dV  W |d n|d w W d   dS 1 s9w   Y  dS t j| d dV  W d   dS 1 sUw   Y  dS )z
    Wrapper around `transaction.atomic` which ensures transactions on SQLite are exclusive.

    This functionality is built-in to Django 5.1+.
    r   zTransactions must be EXCLUSIVEzBEGIN EXCLUSIVENCOMMIT)r   )	r   get_connectionr   r   r   RuntimeErrorcursorexecuteatomic)r   r
   cr   r   r   exclusive_transaction   s   



""r    valc                 C   s   t | tr	t| } t| S )z
    Normalize a UUID into its dashed representation.

    This works around engines like MySQL which don't store values in a uuid field,
    and thus drops the dashes.
    )
isinstancestrr   )r!   r   r   r   normalize_uuid3   s   
r$   )N)
contextlibr   typingr   r   r   r   uuidr   r   	django.dbr   django.db.backends.base.baser	   boolr   r#   r    r$   r   r   r   r   <module>   s    
$