HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //usr/local/lib/python3.9/site-packages/celery/backends/__pycache__/dynamodb.cpython-39.pyc
a

X>h|L�@s�dZddlmZddlmZddlmZmZddlmZm	Z	ddl
mZddl
mZddlmZd	d
lmZzddlZddlmZWney�dZZYn0d
Zedd�Zee�ZGdd�de�ZdS)z"AWS DynamoDB result store backend.�)�
namedtuple)�
ip_address)�sleep�time)�Any�Dict)�
_parse_url)�ImproperlyConfigured)�
get_logger�)�KeyValueStoreBackendN)�ClientError)�DynamoDBBackend�DynamoDBAttribute��name�	data_typecsjeZdZdZdZdZdZdZdZdZ	dZ
eddd�Zed	d
d�Z
eddd�Zed
dd�Zeddd�ZdZdZd?�fdd�	Zedd��Zd@dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�ZdAd$d%�Zd&d'�Zd(d)�Z e!e"e!e#fd*�d+d,�Z$e!e"e!e#fd*�d-d.�Z%d/d0�Z&e'd1d2��Z(d3d4�Z)d5d6�Z*d7d8�Z+d9d:�Z,e-e.d*�d;d<�Z/�fd=d>�Z0�Z1S)Brz�AWS DynamoDB result backend.

    Raises:
        celery.exceptions.ImproperlyConfigured:
            if module :pypi:`boto3` is not available.
    ZceleryrNT�id�Sr�result�BZchord_count�N�	timestamp�ttlc
s�t�j|i|��||_|p |j|_ts0td��d}d}d}|du�r�t|�\}}	}
}}}
}|}|}|du}|du}||kr�td��|}|	dks�t�|	�r�d|	�d|
��|_	d|_
t�d�
|j	��n|	|_
|jjj}|d	�}|r�||_	t|�d
|j��|_t|�d|j��|_|�d|j�}|�rtzt|�|_Wn@t�yr}z&tjd
|�d�|d�|�WYd}~n
d}~00|
�p~|j|_|j|j|jf|_d|_|�r�|j||d�dS)NzBYou need to install the boto3 library to use the DynamoDB backend.Fz6You need to specify both the Access Key ID and Secret.�	localhostzhttp://�:z	us-east-1z*Using local-only DynamoDB endpoint URL: {}Zdynamodb_endpoint_url�read�writeZttl_secondszTTL must be a number; got "�")�exc_info)�
access_key_id�secret_access_key)�super�__init__�url�
table_name�boto3r	�	parse_urlr�_is_valid_ip�endpoint_url�
aws_region�logger�warning�formatZapp�conf�get�int�read_capacity_units�write_capacity_units�time_to_live_seconds�
ValueError�error�
_key_field�_value_field�_timestamp_field�_available_fields�_client�_get_client)�selfr$r%�args�kwargsZaws_credentials_given�aws_access_key_id�aws_secret_access_key�schemeZregion�port�username�password�table�queryZaccess_key_givenZsecret_key_given�_getZconfig_endpoint_urlr�e��	__class__��B/usr/local/lib/python3.9/site-packages/celery/backends/dynamodb.pyr#Ds��
����
����
���zDynamoDBBackend.__init__cCs(zt|�WdSty"YdS0dS)NTF)rr4)�iprKrKrLr(�s
zDynamoDBBackend._is_valid_ipcCs||jdurvd|ji}|dur,|�||d��|jdur@|j|d<tjdi|��|_|��|��durv|��|�	�|jS)zGet client connection.NZregion_name)r?r@r)�dynamodb)rN)
r:r*�updater)r&�client�_get_or_create_table�_has_ttl�_validate_ttl_methods�_set_table_ttl)r<r r!Zclient_parametersrKrKrLr;�s(
��

��zDynamoDBBackend._get_clientcCs6|jj|jjd�g|j|jjdd�g|j|jd�d�S)z=Get the boto3 structure describing the DynamoDB table schema.)�
AttributeNameZ
AttributeType�HASH)rUZKeyType)ZReadCapacityUnitsZWriteCapacityUnits)ZAttributeDefinitions�	TableNameZ	KeySchemaZProvisionedThroughput)r6rrr%r1r2�r<rKrKrL�_get_table_schema�s������z!DynamoDBBackend._get_table_schemac
Cs�|��}z|jj|jd�WSty�}zz|jd�dd�}|dkr�|jjfi|��}t�	d�
|j��|�d�t�	d�
|j��|WYd	}~S|�WYd	}~n
d	}~00d	S)
z=Create table if not exists, otherwise return the description.�rW�Error�Code�UnknownZResourceNotFoundExceptionz*DynamoDB Table {} did not exist, creating.�ACTIVEz#DynamoDB Table {} is now available.N)rYr:�describe_tabler%r
�responser/Zcreate_tabler+�infor-�_wait_for_table_status)r<Ztable_schemarH�
error_code�table_descriptionrKrKrLrQ�s(��
��z$DynamoDBBackend._get_or_create_tablecCs|jdurdS|jdkS)z�Return the desired Time to Live config.

        - True:  Enable TTL on the table; use expiry.
        - False: Disable TTL on the table; don't use expiry.
        - None:  Ignore TTL on the table; don't use expiry.
        Nr)r3rXrKrKrLrR�s�zDynamoDBBackend._has_ttlcCsbd}g}t|�D]}t|j|�s|�|�q|r^t�djd�|�d��tdjd�|�d���dS)z:Verify boto support for the DynamoDB Time to Live methods.)�update_time_to_live�describe_time_to_livezdboto3 method(s) {methods} not found; ensure that boto3>=1.9.178 and botocore>=1.12.178 are installed�,)�methodsz#boto3 method(s) {methods} not foundN)	�list�hasattrr:�appendr+r5r-�join�AttributeError)r<Zrequired_methodsZmissing_methods�methodrKrKrLrS�s"�����z%DynamoDBBackend._validate_ttl_methodscCs|j|��|d�d�S)zBGet the boto3 structure describing the DynamoDB TTL specification.)ZEnabledrU)rWZTimeToLiveSpecification)r%rR)r<�
ttl_attr_namerKrKrL�_get_ttl_specifications
��z&DynamoDBBackend._get_ttl_specificationc
Cs~z|jj|jd�}Wndtyx}zL|jd�dd�}|jd�dd�}t�dj|j||d��|�WYd}~n
d}~00|S)NrZr[r\r]�MessagezJError describing Time to Live on DynamoDB table {table}: {code}: {message})rE�code�message)	r:rfr%r
r`r/r+r5r-)r<�descriptionrHrc�
error_messagerKrKrL�_get_table_ttl_description!s �
��z*DynamoDBBackend._get_table_ttl_descriptionc	Cs�|��}|dd}|dvrd|dd}|��r�||jjkr�t�dj|dkrPdnd|jd	��|SnN|d
vr�|��s�t�dj|dkr�dnd
|jd	��|Snt�dj||jd��|dkr�|n|jj}z@|j	j
fi|j|d���}t�dj|j|��|jjd��|WSt
�y|}z\|jd�dd�}|jd�dd�}t�dj|���rRdnd|j||d��|�WYd}~n
d}~00dS)z,Enable or disable Time to Live on the table.ZTimeToLiveDescriptionZTimeToLiveStatus)�ENABLEDZENABLINGrUz5DynamoDB Time to Live is {situation} on table {table}rwzalready enabledzcurrently being enabled)Z	situationrE)�DISABLEDZ	DISABLINGrxzalready disabledzcurrently being disabledzWUnknown DynamoDB Time to Live status {status} on table {table}. Attempting to continue.)�statusrE)rozUDynamoDB table Time to Live updated: table={table} enabled={enabled} attribute={attr})rE�enabled�attrr[r\r]rqzHError {action} Time to Live on DynamoDB table {table}: {code}: {message}ZenablingZ	disabling)�actionrErrrsN)rvrR�
_ttl_fieldrr+�debugr-r%r,r:rerprar
r`r/r5)	r<rtryZ
cur_attr_name�	attr_name�
specificationrHrcrurKrKrLrT6s|
����	���	��&�
�����
��	zDynamoDBBackend._set_table_ttlr^cCsNd}|sJ|jj|jd�}t�d�|j|��|dd}||k}td�qdS)z#Poll for the expected table status.FrZz+Waiting for DynamoDB table {} to become {}.ZTableZTableStatusrN)rPr_r%r+r~r-r)r<�expectedZachieved_staterdZcurrent_statusrKrKrLrb�s���z&DynamoDBBackend._wait_for_table_statuscCs|j|jj|jj|iid�S)z0Construct the item retrieval request parameters.)rW�Key)r%r6rr�r<�keyrKrKrL�_prepare_get_request�s���z$DynamoDBBackend._prepare_get_requestc	Cs~t�}|j|jj|jj|i|jj|jj|i|jj|jjt|�iid�}|��rz|d�	|j
j|j
jtt||j��ii�|S)z/Construct the item creation request parameters.�rW�Itemr�)
rr%r6rrr7r8�strrRrOr}r0r3)r<r��valuerZput_requestrKrKrL�_prepare_put_request�s*�������z$DynamoDBBackend._prepare_put_request)r��returnc	CsFt�}|j|jj|jj|i|jj|jjdi|jj|jjt|�iid�S)z7Construct the counter initialization request parameters�0r�)rr%r6rr�_count_filedr8r�)r<r�rrKrKrL�_prepare_init_count_request�s�����z+DynamoDBBackend._prepare_init_count_requestcCs@|j|jj|jj|iid|jj�d|jj�d�dddiidd�S)	z2Construct the counter increment request parameterszset z = z + :numz:numr�1ZUPDATED_NEW)rWr�ZUpdateExpressionZExpressionAttributeValuesZReturnValues)r%r6rrr�r�rKrKrL�_prepare_inc_count_request�s����z*DynamoDBBackend._prepare_inc_count_requestcs d�vriS�fdd�|jD�S)z1Convert get_item() response to field-value pairs.r�cs$i|]}|j�d|j|j�qS)r�r)�.0�field��raw_responserKrL�
<dictcomp>s�z1DynamoDBBackend._item_to_dict.<locals>.<dictcomp>)r9)r<r�rKr�rL�
_item_to_dict�s

�zDynamoDBBackend._item_to_dictcCs|��S�N)r;rXrKrKrLrPszDynamoDBBackend.clientcCs<t|�}|�|�}|jjfi|��}|�|�}|�|jj�Sr�)r�r�rPZget_itemr�r/r7r)r<r��request_parameters�
item_response�itemrKrKrLr/s


zDynamoDBBackend.getcCs*t|�}|�||�}|jjfi|��dSr�)r�r�rP�put_item)r<r�r�r�rKrKrL�setszDynamoDBBackend.setcs�fdd�|D�S)Ncsg|]}��|��qSrK)r/)r�r�rXrKrL�
<listcomp>�z(DynamoDBBackend.mget.<locals>.<listcomp>rK)r<�keysrKrXrL�mgetszDynamoDBBackend.mgetcCs(t|�}|�|�}|jjfi|��dSr�)r�r�rPZdelete_item)r<r�r�rKrKrL�deletes
zDynamoDBBackend.deletecCsDt|�}|�|�}|jjfi|��}|d|jj|jj}t|�S)z<Atomically increase the chord_count and return the new countZ
Attributes)r�r�rPZupdate_itemr�rrr0)r<r�r�r�Z	new_countrKrKrL�incrs

zDynamoDBBackend.incrcsD|�|d�}|�t|��}|jjfi|��t�j||fi|��S)Nr)Zget_key_for_chordr�r�rPr�r"�_apply_chord_incr)r<Zheader_result_args�bodyr>Z	chord_keyZinit_count_requestrIrKrLr�'s��z!DynamoDBBackend._apply_chord_incr)NN)NN)r^)2�__name__�
__module__�__qualname__�__doc__r%r1r2r*r)r3Zsupports_autoexpirerr6r7r�r8r}r9Zimplements_incrr#�staticmethodr(r;rYrQrRrSrprvrTrbr�r�r�rrr�r�r��propertyrPr/r�r�r��bytesr0r�r��
__classcell__rKrKrIrLrsPY



p
	
r)r��collectionsr�	ipaddressrrr�typingrrZkombu.utils.urlrr'Zcelery.exceptionsr	Zcelery.utils.logr
�baserr&Zbotocore.exceptionsr
�ImportError�__all__rr�r+rrKrKrKrL�<module>s"