U
    g                      @  s.  d dl mZ ddlmZmZ d dlmZ d dlZd dlZddl	m
Z
 ddl	mZ eG dd	 d	ZeG d
d dZeG dd dZeG dd dZeG dd dZG dd dejZeG dd dZd(ddd	ddddZdddddZdd d!d"Zdd d#d$Zed%eG d&d' d'ZdS ))    )annotations   )event_classT_JSON_DICT)	dataclassN)dom)pagec                   @  sJ   e Zd ZU ded< ded< ded< ded< ded< dd Zed	d
 ZdS )
CreditCardstrnumbernameexpiry_monthexpiry_yearcvcc                 C  s<   t  }| j|d< | j|d< | j|d< | j|d< | j|d< |S )Nr   r   expiryMonth
expiryYearr   )dictr   r   r   r   r   selfjson r   T/tmp/pip-unpacked-wheel-3ysq0mf8/selenium/webdriver/common/devtools/v130/autofill.pyto_json!   s    




zCreditCard.to_jsonc                 C  s:   | t |d t |d t |d t |d t |d dS )Nr   r   r   r   r   )r   r   r   r   r   r
   clsr   r   r   r   	from_json*   s    




zCreditCard.from_jsonN__name__
__module____qualname____annotations__r   classmethodr   r   r   r   r   r	      s   
	r	   c                   @  s2   e Zd ZU ded< ded< dd Zedd ZdS )	AddressFieldr
   r   valuec                 C  s   t  }| j|d< | j|d< |S )Nr   r$   )r   r   r$   r   r   r   r   r   =   s    

zAddressField.to_jsonc                 C  s   | t |d t |d dS )Nr   r$   )r   r$   r   r   r   r   r   r   C   s    

zAddressField.from_jsonNr   r   r   r   r   r#   5   s
   
r#   c                   @  s.   e Zd ZU dZded< dd Zedd ZdS )	AddressFieldsz#
    A list of address fields.
    typing.List[AddressField]fieldsc                 C  s   t  }dd | jD |d< |S )Nc                 S  s   g | ]}|  qS r   r   .0ir   r   r   
<listcomp>T   s     z)AddressFields.to_json.<locals>.<listcomp>r'   r   r'   r   r   r   r   r   R   s    zAddressFields.to_jsonc                 C  s   | dd |d D dS )Nc                 S  s   g | ]}t |qS r   r#   r   r)   r   r   r   r,   Z   s     z+AddressFields.from_json.<locals>.<listcomp>r'   r'   r   r   r   r   r   r   W   s    zAddressFields.from_jsonNr   r   r    __doc__r!   r   r"   r   r   r   r   r   r%   K   s
   
r%   c                   @  s*   e Zd ZU ded< dd Zedd ZdS )Addressr&   r'   c                 C  s   t  }dd | jD |d< |S )Nc                 S  s   g | ]}|  qS r   r(   r)   r   r   r   r,   e   s     z#Address.to_json.<locals>.<listcomp>r'   r-   r   r   r   r   r   c   s    zAddress.to_jsonc                 C  s   | dd |d D dS )Nc                 S  s   g | ]}t |qS r   r.   r)   r   r   r   r,   k   s     z%Address.from_json.<locals>.<listcomp>r'   r/   r   r   r   r   r   r   h   s    zAddress.from_jsonNr   r   r   r   r   r2   ^   s   
r2   c                   @  s.   e Zd ZU dZded< dd Zedd ZdS )		AddressUIa  
    Defines how an address can be displayed like in chrome://settings/addresses.
    Address UI is a two dimensional array, each inner array is an "address information line", and when rendered in a UI surface should be displayed as such.
    The following address UI for instance:
    [[{name: "GIVE_NAME", value: "Jon"}, {name: "FAMILY_NAME", value: "Doe"}], [{name: "CITY", value: "Munich"}, {name: "ZIP", value: "81456"}]]
    should allow the receiver to render:
    Jon Doe
    Munich 81456
    ztyping.List[AddressFields]address_fieldsc                 C  s   t  }dd | jD |d< |S )Nc                 S  s   g | ]}|  qS r   r(   r)   r   r   r   r,      s     z%AddressUI.to_json.<locals>.<listcomp>addressFields)r   r4   r   r   r   r   r   }   s    zAddressUI.to_jsonc                 C  s   | dd |d D dS )Nc                 S  s   g | ]}t |qS r   )r%   r   r)   r   r   r   r,      s     z'AddressUI.from_json.<locals>.<listcomp>r5   )r4   r   r   r   r   r   r      s    zAddressUI.from_jsonNr0   r   r   r   r   r3   o   s
   

r3   c                   @  s,   e Zd ZdZdZdZdd Zedd ZdS )	FillingStrategyzw
    Specified whether a filled field was done so by using the html autocomplete attribute or autofill heuristics.
    ZautocompleteAttributeZautofillInferredc                 C  s   | j S N)r$   )r   r   r   r   r      s    zFillingStrategy.to_jsonc                 C  s   | |S r7   r   r   r   r   r   r      s    zFillingStrategy.from_jsonN)	r   r   r    r1   ZAUTOCOMPLETE_ATTRIBUTEZAUTOFILL_INFERREDr   r"   r   r   r   r   r   r6      s   r6   c                   @  sb   e Zd ZU ded< ded< ded< ded< ded< ded< d	ed
< ded< dd Zedd ZdS )FilledFieldr
   	html_typeid_r   r$   autofill_typer6   filling_strategyzpage.FrameIdframe_iddom.BackendNodeIdfield_idc                 C  sf   t  }| j|d< | j|d< | j|d< | j|d< | j|d< | j |d< | j |d< | j	 |d< |S )	NhtmlTypeidr   r$   autofillTypefillingStrategyframeIdfieldId)
r   r9   r:   r   r$   r;   r<   r   r=   r?   r   r   r   r   r      s    




zFilledField.to_jsonc                 C  sb   | t |d t |d t |d t |d t |d t|d tj|d tj|d d	S )
Nr@   rA   r   r$   rB   rC   rD   rE   )r9   r:   r   r$   r;   r<   r=   r?   )r
   r6   r   r   ZFrameIdr   ZBackendNodeIdr   r   r   r   r      s    




zFilledField.from_jsonNr   r   r   r   r   r8      s   
r8   r>   ztyping.Optional[page.FrameId]z0typing.Generator[T_JSON_DICT, T_JSON_DICT, None])r?   r=   cardreturnc                 c  sF   t  }|  |d< |dk	r&| |d< | |d< d|d}|V }dS )a  
    Trigger autofill on a form identified by the fieldId.
    If the field and related form cannot be autofilled, returns an error.

    :param field_id: Identifies a field that serves as an anchor for autofill.
    :param frame_id: *(Optional)* Identifies the frame that field belongs to.
    :param card: Credit card information to fill out the form. Credit card data is not saved.
    rE   NrD   rF   zAutofill.triggermethodparams)r   r   )r?   r=   rF   rJ   cmd_dictr   r   r   r   trigger   s    rL   ztyping.List[Address])	addressesrG   c                 c  s,   t  }dd | D |d< d|d}|V }dS )zh
    Set addresses so that developers can verify their forms implementation.

    :param addresses:
    c                 S  s   g | ]}|  qS r   r(   r)   r   r   r   r,      s     z!set_addresses.<locals>.<listcomp>rM   zAutofill.setAddressesrH   N)r   )rM   rJ   rK   r   r   r   r   set_addresses   s    rN   )rG   c                  c  s   ddi} | V }dS )z1
    Disables autofill domain notifications.
    rI   zAutofill.disableNr   rK   r   r   r   r   disable   s     rP   c                  c  s   ddi} | V }dS )z0
    Enables autofill domain notifications.
    rI   zAutofill.enableNr   rO   r   r   r   enable   s     rQ   zAutofill.addressFormFilledc                   @  s6   e Zd ZU dZded< ded< edd ddd	Zd
S )AddressFormFilledz1
    Emitted when an address form is filled.
    ztyping.List[FilledField]filled_fieldsr3   
address_uir   )r   rG   c                 C  s$   | dd |d D t |d dS )Nc                 S  s   g | ]}t |qS r   )r8   r   r)   r   r   r   r,     s     z/AddressFormFilled.from_json.<locals>.<listcomp>ZfilledFieldsZ	addressUi)rS   rT   )r3   r   r   r   r   r   r     s    zAddressFormFilled.from_jsonN)r   r   r    r1   r!   r"   r   r   r   r   r   rR   
  s
   
rR   )NN)
__future__r   utilr   r   Zdataclassesr   enumtyping r   r   r	   r#   r%   r2   r3   Enumr6   r8   rL   rN   rP   rQ   rR   r   r   r   r   <module>   s8   $5  

