o
    tBh                     @   s   d dl Zd dlmZmZmZ d dlZd dlm	Z	 d dlZd dl
Z
d dlZd dlmZ d dlZd dlmZ d dlmZ G dd dejjZG dd	 d	eZeeG d
d dee	jZdS )    N)ActiveResourceResourceMetaformats)urllib)PaginatedCollection)
Collectionc                       s    e Zd ZdZ fddZ  ZS )ShopifyConnectionNc              
      sN   d | _ ztt| j|i || _ W | j S  tjjy& } z|j | _  d }~ww N)responsesuperr   _openpyactiveresource
connectionConnectionError)selfargskwargserr	__class__ c/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/shopify/base.pyr      s   zShopifyConnection._open)__name__
__module____qualname__r
   r   __classcell__r   r   r   r   r      s    r   c                   @   s&  e Zd Zedd Zdd Zdd ZeeeddZd	d
 Zdd Z	eee	ddZ
dd Zdd ZeeeddZdd Zdd ZeeeddZdd Zdd ZeeeddZdd Zdd  Zeeedd!Zd"d# Zd$d% Zeeedd&Zd'd( Zd)d* Zeeedd+Zd,d- Zd.d/ Zeeedd0ZdS )1ShopifyResourceMetac                 C   s   | j }t|dds@| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j	|_	| jdu r2t
dt| j| j| j| j| j|_|jS )z&HTTP connection for the current threadr   NzNo shopify session is active)_threadlocalgetattruserpasswordsitetimeoutheadersformatversionurl
ValueErrorr   r   )clslocalr   r   r   r   "   s   
zShopifyResourceMeta.connectionc                 C      t | jdtjS )Nr   )r   r   ShopifyResource_userr(   r   r   r   get_user5      zShopifyResourceMeta.get_userc                 C      d | j _| t_| j _d S r	   )r   r   r+   r,   r   r(   valuer   r   r   set_user8      zShopifyResourceMeta.set_userNz!The username for HTTP Basic Auth.c                 C   r*   )Nr    )r   r   r+   	_passwordr-   r   r   r   get_password>   r/   z ShopifyResourceMeta.get_passwordc                 C   r0   r	   )r   r   r+   r5   r    r1   r   r   r   set_passwordA   r4   z ShopifyResourceMeta.set_passwordz!The password for HTTP Basic Auth.c                 C   r*   )Nr!   )r   r   r+   _siter-   r   r   r   get_siteG   r/   zShopifyResourceMeta.get_sitec                 C   s   d | j _| t_| j _|d urQtj|}|j}|j	r$|dt
|j	 7 }tj|j||jdddf}| t_| j _|jrDtj|j| _|jrStj|j| _d S d S d S )N: )r   r   r+   r8   r!   r   parseurlparsehostnameportstr
urlunparseschemepathusernameunquoter   r    )r(   r2   partshostnew_siter   r   r   set_siteJ   s   	zShopifyResourceMeta.set_sitez!The base REST site to connect to.c                 C   r*   )Nr"   )r   r   r+   _timeoutr-   r   r   r   get_timeout[   r/   zShopifyResourceMeta.get_timeoutc                 C   r0   r	   )r   r   r+   rJ   r"   r1   r   r   r   set_timeout^   r4   zShopifyResourceMeta.set_timeoutz Socket timeout for HTTP requestsc                 C   s"   t | jdstj | j_| jjS )Nr#   )hasattrr   r+   _headerscopyr#   r-   r   r   r   get_headersd   s   zShopifyResourceMeta.get_headersc                 C   s   || j _d S r	   )r   r#   r1   r   r   r   set_headersi   s   zShopifyResourceMeta.set_headersz#The headers sent with HTTP requestsc                 C   r*   )Nr$   )r   r   r+   _formatr-   r   r   r   
get_formatn   r/   zShopifyResourceMeta.get_formatc                 C   r0   r	   )r   r   r+   rR   r$   r1   r   r   r   
set_formatq   r4   zShopifyResourceMeta.set_formatz'Encoding used for request and responsesc                 C   s>   z|   W S  ty   t| dr| j| j  Y S | j Y S w )z7Return the prefix source, by default derived from site._prefix_source)override_prefixAttributeErrorrM   r!   rU   r-   r   r   r   get_prefix_sourcew   s   


z%ShopifyResourceMeta.get_prefix_sourcec                 C   s
   || _ dS )z>Set the prefix source, which will be rendered into the prefix.N)rU   r1   r   r   r   set_prefix_source   s   
z%ShopifyResourceMeta.set_prefix_sourcez+prefix for lookups for this type of object.c                 C   s@   t | jds	tjrt| jdtjS tjd urtjdd S d S )Nr%   /)rM   r   r+   _versionr   r8   splitr-   r   r   r   get_version   s
   
zShopifyResourceMeta.get_versionc                 C      | t _| j_d S r	   )r+   r\   r   r%   r1   r   r   r   set_version      zShopifyResourceMeta.set_versionzShopify Api Versionc                 C   r*   )Nr&   )r   r   r+   _urlr-   r   r   r   get_url   r/   zShopifyResourceMeta.get_urlc                 C   r_   r	   )r+   rb   r   r&   r1   r   r   r   set_url   ra   zShopifyResourceMeta.set_urlz.Base URL including protocol and shopify domain) r   r   r   propertyr   r.   r3   r   r6   r7   r    r9   rI   r!   rK   rL   r"   rP   rQ   r#   rS   rT   r$   rX   rY   prefix_sourcer^   r`   r%   rc   rd   r&   r   r   r   r   r   !   s<    

r   c                       s   e Zd ZejZe Zdde	j
ejddd f iZdZdZd fdd	Zd	d
 Zdd Zedd Zedd Zed fdd	Z  ZS )r+   z
User-AgentzShopifyPythonAPI/%s Python/%s    r   Nc                    s2   |d ur|d u r| j |\}}tt| ||S r	   )r   _split_optionsr   r+   __init__)r   
attributesprefix_optionsr   r   r   rj      s   zShopifyResource.__init__c                 C   s   | j  S r	   )id)r   r   r   r   is_new   s   zShopifyResource.is_newc                 C   s(   |j  r| | jj|j  d S d S r	   )bodystrip_updater   r$   decode)r   r
   r   r   r   _load_attributes_from_response   s   
z.ShopifyResource._load_attributes_from_responsec                 C   s6   |j | _ |j| _d | _d | _|jj| _|j| jd< d S NzX-Shopify-Access-Token)	r!   r&   r   r    api_versionnamer%   tokenr#   )r(   sessionr   r   r   activate_session   s   
z ShopifyResource.activate_sessionc                 C   s0   d | _ d | _d | _d | _d | _| jdd  d S rt   )r!   r&   r   r    r%   r#   popr-   r   r   r   clear_session   s   zShopifyResource.clear_sessionc                    sL   t t| jd||d|}t|tr$d|jv r$t|fdd| ii|S |S )z8Checks the resulting collection for pagination metadata.)id_from_r#   metadataresource_classNr   )r   r+   find
isinstancer   r~   r   )r(   r|   r}   r   
collectionr   r   r   r      s   zShopifyResource.find)NN)r   r   r   r   
JSONFormatrR   	threadingr)   r   shopifyVERSIONsysr%   r]   rN   r\   rb   rj   rn   rs   classmethodry   r{   r   r   r   r   r   r   r+      s     

r+   )pyactiveresource.connectionr   pyactiveresource.activeresourcer   r   r   shopify.yamlobjectsr   shopify.mixinsmixinsr   r   	six.movesr   sixshopify.collectionr   pyactiveresource.collectionr   r   
Connectionr   r   add_metaclass	Countabler+   r   r   r   r   <module>   s    z