o
    e                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZ d dlZd dlm	Z	 d dl
mZ d dlmZ d dlmZ G dd	 d	ZG d
d de jZG dd dZdS )    N)List)
HTTPStatus)BeautifulSoup)guard)ConfirmationExpected)InvalidCredentialsc                   @   s   e Zd Zdd ZdS )Confirmationc                 C   s   || _ || _d S N)data_confidnonce)selfr
   r    r   ?/usr/local/lib/python3.10/dist-packages/steampy/confirmation.py__init__   s   
zConfirmation.__init__N)__name__
__module____qualname__r   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdZdZdZdS )TagconfdetailsallowcancelN)r   r   r   CONFDETAILSALLOWCANCELr   r   r   r   r      s
    r   c                   @   s  e Zd ZdZdededejddfddZd	edefd
dZ	dedefddZ
dedefddZdee fddZdejfddZdedefddZdedefddZdee d	edefddZdee dedefddZed edefd!d"Zed edefd#d$ZdS )%ConfirmationExecutorz%https://steamcommunity.com/mobileconfidentity_secretmy_steam_idsessionreturnNc                 C   s   || _ || _|| _d S r	   )_my_steam_id_identity_secret_session)r   r   r   r   r   r   r   r      s   
zConfirmationExecutor.__init__trade_offer_idc                 C      |   }| ||}| |S r	   )_get_confirmations _select_trade_offer_confirmation_send_confirmation)r   r$   confirmationsconfirmationr   r   r   send_trade_allow_request$      
z-ConfirmationExecutor.send_trade_allow_requestasset_idc                 C   r%   r	   )r&   !_select_sell_listing_confirmationr(   )r   r-   r)   r*   r   r   r   confirm_sell_listing)   r,   z)ConfirmationExecutor.confirm_sell_listingr*   c                 C   sX   t j}| |j}|jf|d< |j|d< |j|d< ddi}| jj| j d||d	 S )NopcidckX-Requested-WithXMLHttpRequestz/ajaxopparamsheaders)
r   r   _create_confirmation_paramsvaluer
   r   r#   getCONF_URLjson)r   r*   tagr6   r7   r   r   r   r(   .   s   

z'ConfirmationExecutor._send_confirmationc                 C   sZ   g }|   }|jtjkr+t|j}|d D ]}|d }|d }|t|| q|S t	)Nr   idr   )
_fetch_confirmations_pagestatus_coder   OKr<   loadstextappendr   r   )r   r)   confirmations_pageconfirmations_jsonr   r
   r   r   r   r   r&   7   s   z'ConfirmationExecutor._get_confirmationsc                 C   sJ   t jj}| |}ddi}| jj| j d||d}d|jv r#td|S )Nr3   z)com.valvesoftware.android.steam.communityz/getlistr5   zJSteam Guard Mobile Authenticator is providing incorrect Steam Guard codes.zInvalid Steam Guard file)	r   r   r9   r8   r#   r:   r;   rC   r   )r   r=   r6   r7   responser   r   r   r?   D   s   

z.ConfirmationExecutor._fetch_confirmations_pagec                 C   s@   d|j  }| |}| jj| j d|j  |d}| d S )Nr   z	/details/)r6   html)r
   r8   r#   r:   r;   r<   )r   r*   r=   r6   rG   r   r   r    _fetch_confirmation_details_pageM   s   
z5ConfirmationExecutor._fetch_confirmation_details_page
tag_stringc                 C   s<   t t }t| j||}t| j}|| j||d|dS )Nandroid)paktmr=   )inttimer   generate_confirmation_keyr"   generate_device_idr!   )r   rJ   	timestampconfirmation_key
android_idr   r   r   r8   S   s   z0ConfirmationExecutor._create_confirmation_paramsr)   c                 C   2   |D ]}|  |}| |}||kr|  S qtr	   )rI    _get_confirmation_trade_offer_idr   )r   r)   r$   r*   confirmation_details_pageconfirmation_idr   r   r   r'   `      

z5ConfirmationExecutor._select_trade_offer_confirmationc                 C   rX   r	   )rI   !_get_confirmation_sell_listing_idr   )r   r)   r-   r*   rZ   r[   r   r   r   r.   h   r\   z6ConfirmationExecutor._select_sell_listing_confirmationrZ   c                 C   s\   t | d}|dd j }||dd d  }|d |d dd}t|d	 S )
Nhtml.parserscript   z'confiteminfo',    z	, UserYou
 r>   )r   selectstringstripindexreplacer<   rB   )rZ   soupscr_rawr   r   r   r]   p   s
   
z6ConfirmationExecutor._get_confirmation_sell_listing_idc                 C   s*   t | d}|dd d }|dd S )Nr^   z.tradeofferr   r>   _   )r   rd   split)rZ   ri   full_offer_idr   r   r   rY   x   s   
z5ConfirmationExecutor._get_confirmation_trade_offer_id)r   r   r   r;   strrequestsSessionr   dictr+   r/   r   r(   r   r&   Responser?   rI   r8   r'   r.   staticmethodr]   rY   r   r   r   r   r      s     		r   )enumr<   rR   typingr   httpr   rp   bs4r   steampyr   steampy.exceptionsr   steampy.loginr   r   Enumr   r   r   r   r   r   <module>   s    