
    mif                       d dl mZ d dlZd dlmZmZ d dlmZ d dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlZ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mZ d dlZd dlZd dlmZ d dlmZ d d	lmZmZ d d
l m!Z! d dl"m"Z" d dl#m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z) d dl*Z*d dl+m,Z,m-Z-m.Z.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5m6Z6 d dl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZI d dlJmKZKmLZLmMZMmNZNmOZO d dlPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z` d dlambZbmcZcmdZdmeZe d dlfmgZgmhZhmiZi d dljmkZk d dllmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZu d dlvmwZwmxZx d dlymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZmZmZ d dlmZ d dlmZ dd lmZ dd!lmZ d dlZ+d d"lmZ d d#lmZ d d$lmZ d d%lmZmZmZmZmZmZmZmZmZmZ  ed&          Z G d' d(e          Z G d) d*e          Z G d+ d,e          Z G d- d.e          Z G d/ d0e          Z G d1 d2          Z G d3 d4ej                  Zd d5lmZ d d6lmZ d d7lmZ d8 Zd9 ZdS ):    )print_functionN)datetime	timedelta)Enum)relativedelta)
expanduser)random)RequestException)ResumableUploadResultFile)HTTPAdapter)slugify)tqdm)Retry)field_mask_pb2)parse)get_access_token_from_envKaggleClientKaggleCredentials	KaggleEnvKaggleOAuth)CreateInboxFileRequest)ApiStartBlobUploadRequestApiStartBlobUploadResponseApiBlobType)ApiListCompetitionsRequestApiCompetitionApiCreateCodeSubmissionRequestApiCreateSubmissionResponseApiStartSubmissionUploadRequestApiCreateSubmissionRequestApiSubmissionApiListSubmissionsRequestApiListDataFilesResponseApiListDataFilesRequestApiDownloadDataFileRequestApiDownloadDataFilesRequestApiDownloadLeaderboardRequestApiLeaderboardSubmissionApiGetLeaderboardRequestApiDataFileApiCreateCodeSubmissionResponseApiListCompetitionsResponse)CompetitionListTabHostSegmentCompetitionSortBySubmissionGroupSubmissionSortBy)ApiListDatasetsRequestApiListDatasetFilesRequestApiGetDatasetStatusRequestApiDownloadDatasetRequestApiCreateDatasetRequest"ApiCreateDatasetVersionRequestBody"ApiCreateDatasetVersionByIdRequestApiCreateDatasetVersionRequestApiDatasetNewFileApiUpdateDatasetMetadataRequestApiGetDatasetMetadataRequestApiDatasetFile
ApiDatasetApiCreateDatasetResponseApiDatasetColumnApiDeleteDatasetRequest)DatasetSelectionGroupDatasetSortByDatasetFileTypeGroupDatasetLicenseGroup)DatasetSettingsSettingsLicenseDatasetCollaborator)KaggleObject)	ApiListKernelsRequestApiListKernelFilesRequestApiSaveKernelRequestApiGetKernelRequest!ApiListKernelSessionOutputRequest ApiGetKernelSessionStatusRequestApiSaveKernelResponseApiKernelMetadataApiDeleteKernelRequest)KernelsListSortTypeKernelsListViewType)ApiListModelsRequestApiCreateModelRequestApiGetModelRequestApiDeleteModelRequestApiUpdateModelRequestApiGetModelInstanceRequestApiCreateModelInstanceRequest!ApiCreateModelInstanceRequestBody'ApiListModelInstanceVersionFilesRequestApiUpdateModelInstanceRequestApiDeleteModelInstanceRequest$ApiCreateModelInstanceVersionRequest(ApiCreateModelInstanceVersionRequestBody&ApiDownloadModelInstanceVersionRequest$ApiDeleteModelInstanceVersionRequestApiModelApiCreateModelResponseApiDeleteModelResponseApiModelInstance(ApiListModelInstanceVersionFilesResponse#ApiListModelInstanceVersionsRequest$ApiListModelInstanceVersionsResponseApiListModelInstancesRequestApiListModelInstancesResponse)ListModelsOrderByModelInstanceTypeModelFramework)Owner)IntrospectTokenRequest   )DatasetColumn)
UploadFile)EnumMeta)	HTTPError)Response)
CallablecastDictListMappingOptionalTupleUnionTypeVarIterableTc                        e Zd ZdZdZdZd ZdS )
AuthMethodr      rs   c                     | j         S Nnameselfs    v/var/www/html/bestrading.cuttalo.com/scripts/kaggle-env/lib/python3.11/site-packages/kaggle/api/kaggle_api_extended.py__str__zAuthMethod.__str__   s
    y    N)__name__
__module____qualname__LEGACY_API_KEYACCESS_TOKENOAUTHr    r   r   r   r      s2        NLE    r   r   c                   $    e Zd ZdZd Zd Zd ZdS )DirectoryArchivez
    Context manager for handling directory archives.

    This class provides a context manager for working with directory archives in various formats.
    It manages the lifecycle of the archive, including opening and closing resources as needed.
    c                 >    || _         || _        d | _        d | _        d S r   )	_fullpath_formatr   path)r   fullpathfmts      r   __init__zDirectoryArchive.__init__   s"    !				r   c                 l   t          j                    | _        t          j                            | j                  \  }}t          j        t          j        	                    | j        |          | j
        | j                  | _        t          j                            | j                  \  }| _        | S r   )tempfilemkdtemp	_temp_dirosr   splitr   shutilmake_archivejoinr   r   )r   _dir_names      r   	__enter__zDirectoryArchive.__enter__   s{    !)++gmmDN338'T^X(N(NPTP\^b^lmm	w}}TY//49r   c                 8    t          j        | j                   d S r   )r   rmtreer   )r   argss     r   __exit__zDirectoryArchive.__exit__   s    dn%%%%%r   N)r   r   r   __doc__r   r   r   r   r   r   r   r      sK             & & & & &r   r   c                   ^    e Zd ZdZddeddfdZddZd Zd	edefd
Z	d	ede
ddfdZddZdS )ResumableUploadContexta6  
    Context manager for handling resumable file uploads.

    This class manages the context for resumable uploads, allowing multiple files to be uploaded
    with the ability to resume interrupted uploads. It manages temporary directories and tracks
    the state of each file upload within the context.
    F	no_resumereturnNc                     || _         t          j                            t	          j                    d          | _        g | _        d S )Nz.kaggle/uploads)r   r   r   r   r   
gettempdirr   _file_uploads)r   r   s     r   r   zResumableUploadContext.__init__   s8    "h&9&;&;=NOO:<r   c                 @    | j         r| S |                                  | S r   )r   _create_temp_dirr   s    r   r   z ResumableUploadContext.__enter__   s(    > 	Kr   c                 \    | j         rd S |d S | j        D ]}|                                 d S r   )r   r   cleanup)r   exc_type	exc_valueexc_tracebackfile_uploads        r   r   zResumableUploadContext.__exit__   sO    > 	F F- 	" 	"K!!!!	" 	"r   r   c                     t           j                            | j        d|                    t           j        j        d                              dd          z            S )zReturns the path to the upload info file for a given file.

        Args:
            path (str): The path to the file for which to get the upload info file path.

        Returns:
            str: The path to the upload info file.
        z%s.jsonr   :)r   r   r   r   replacesep)r   r   s     r   get_upload_info_file_pathz0ResumableUploadContext.get_upload_info_file_path   sF     w||DNIRW[RU8V8V8^8^_bdg8h8h,hiiir   start_blob_upload_requestResumableFileUploadc                     t          |||           }| j                            |           |                                 |S r   )r   r   appendload)r   r   r   r   s       r   new_resumable_file_uploadz0ResumableUploadContext.new_resumable_file_upload   sE     *$0I4PP!!+...r   c                 \    	 t          j        | j                   d S # t          $ r Y d S w xY wr   )r   makedirsr   FileExistsErrorr   s    r   r   z'ResumableUploadContext._create_temp_dir   sA    	K''''' 	 	 	DD	s    
++F)r   r   r   N)r   r   r   r   boolr   r   r   strr   r   r   r   r   r   r   r   r      s         = =$ =4 = = = =
   " " "	jc 	jc 	j 	j 	j 	j4M	        r   r   c                       e Zd ZdZdZdedededdfdZd	 Z	dd
Z
defdZd ZdeddfdZd Zd Zd Zd Zed             Zd Zd ZdS )r   a7  
    Represents a single file upload that supports resuming after interruption.

    This class manages the state and metadata for uploading a file in a resumable way,
    including saving and loading upload progress, handling upload tokens, and managing
    temporary files used to track the upload state.
    i  r   r   contextr   Nc                     || _         || _        || _        t          t	          j                              | _        d | _        d| _        d| _        | j        j	        rd S | j        
                    |          | _        d S NF)r   r   r   inttime	timestampstart_blob_upload_response
can_resumeupload_completer   r   _upload_info_file_path)r   r   r   r   s       r   r   zResumableFileUpload.__init__  sv     	)B&TY[[))SW'$<! 	F&*l&L&LT&R&R###r   c                 R    | j         rt          t          | j                  j        S dS )a+  Retrieves the upload token for a completed upload.

        This method returns the token of the blob upload response if the upload is complete.
        If the upload is not complete, it returns None.

        Returns:
            The upload token if the upload is complete, otherwise None.
        N)r   rz   r   r   tokenr   s    r   	get_tokenzResumableFileUpload.get_token  s,      	[2D4STTZZtr   c                 J    | j         j        rdS |                                  dS )a  Loads a previous upload if it exists and is valid.

        This method checks for a previous upload information file and, if it exists,
        validates it. If the previous upload is valid, it loads the information
        and sets the `can_resume` flag to True.
        N)r   r   _load_previous_if_anyr   s    r   r   zResumableFileUpload.load&  s.     <! 	F""$$$$$r   c                    t           j                            | j                  sdS 	 t	          j        | j        d          5 }t                              t          j	        |          | j
                  }|                     |          r|j        | _        |j        | _        d| _        d d d            n# 1 swxY w Y   dS # t          $ r}t!          d|           Y d }~dS d }~ww xY w)NFrTz'Error while trying to load upload info:)r   r   existsr   ioopenr   	from_dictjsonr   r   _is_previous_validr   r   r   	Exceptionprint)r   fpreviouses       r   r   z)ResumableFileUpload._load_previous_if_any1  s!   w~~d9:: 	5
	4c:: +a.881t|TT**844 +6>6YD3%-%7DN&*DO+ + + + + + + + + + + + + + + 4 	 	 	;Q???55555	s<   C A'B5)C 5B99C <B9=C 
C'C""C'c                     |j         | j         k    o8|j        | j        k    o(|j        t          j                    t          j        z
  k    S r   )r   r   r   r   r   RESUMABLE_UPLOAD_EXPIRY_SECONDS)r   r   s     r   r   z&ResumableFileUpload._is_previous_validA  sG    MTY& g2d6TTg"TY[[3F3f%ff	
r   r   c                     | j         j        rdS || _        t          j        | j        d          5 }t          j        |                                 |d           ddd           dS # 1 swxY w Y   dS )an  Saves the upload information to a file.

        This method is called after an upload has been initiated. It saves the
        upload information to a file so that it can be resumed later.

        Args:
            start_blob_upload_response (ApiStartBlobUploadResponse): The response from the start blob upload request.
        Returns:
            None:
        NwTindent)	r   r   r   r   r   r   r   dumpto_dict)r   r   r   s      r   upload_initiatedz$ResumableFileUpload.upload_initiatedH  s     <! 	F*D'WT0#66 	6!Idllnna5555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   *A''A+.A+c                 X    | j         j        rdS d| _        |                                  dS )zMarks the upload as complete.

        This method sets the `upload_complete` flag to True and saves the upload
        information to a file.
        NT)r   r   r   _saver   s    r   upload_completedz$ResumableFileUpload.upload_completedZ  s/     <! 	F#

r   c                     t          j        | j        d          5 }t          j        |                                 |d           d d d            d S # 1 swxY w Y   d S )Nr   Tr   )r   r   r   r   r   r   )r   r   s     r   r   zResumableFileUpload._savef  s    WT0#66 	6!Idllnna5555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   *AAAc                 x    | j         j        rdS 	 t          j        | j                   dS # t
          $ r Y dS w xY w)zRemoves the upload information file.

        This method is called to clean up the upload information file after the
        upload is complete.
        N)r   r   r   remover   OSErrorr   s    r   r   zResumableFileUpload.cleanupj  sV     <! 	F	Id122222 	 	 	DD	s   + 
99c                     | j         | j                                        | j        | j        | j                                        nd| j        dS )zConverts the ResumableFileUpload object to a dictionary.

        Returns:
            A dictionary representation of the ResumableFileUpload object.
        N)r   r   r   r   r   )r   r   r   r   r   r   r   s    r   r   zResumableFileUpload.to_dictx  sU     I)-)G)O)O)Q)Q=A=\=h/77999nr#3
 
 	
r   c                 d   t                      }|                    | d                    t          | d         ||          }|                     d          |_        |                     d          }|>t                      } |j        di | ||_        |                     d          pd|_        |S )	a  Creates a ResumableFileUpload object from a dictionary.

        Args:
            other: A dictionary containing the ResumableFileUpload object's data.
            context: The ResumableUploadContext object.

        Returns:
            A new ResumableFileUpload object.
        r   r   r   r   Nr   Fr   )r   r   r   getr   r   r   r   )otherr   reqnewr   rsps         r   r   zResumableFileUpload.from_dict  s     ())e78999!%-g>>		+..%*YY/K%L%L"%1,..CCM776777-0C*"')),=">">"G%C
r   c                 D    t          |                                           S )zConverts the ResumableFileUpload object to a string.

        Returns:
            A string representation of the ResumableFileUpload object.
        )r   r   r   s    r   to_strzResumableFileUpload.to_str  s     4<<>>"""r   c                 *    |                                  S r   )r  r   s    r   __repr__zResumableFileUpload.__repr__  s    {{}}r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   staticmethodr   r  r	  r   r   r   r   r      sH         '4#SS4MSXnS	S S S S  	% 	% 	% 	%t     
 
 
6;U 6Z^ 6 6 6 6$
 
 
6 6 6  
 
 
    \,# # #    r   r   c                   >    e Zd ZdZd Zededd fd            Zd ZdS )FileListz
    Represents a list of files returned from a Kaggle API response.

    This class parses and stores information about files (such as datasets or model files)
    returned by the Kaggle API, including handling pagination tokens and error messages.
    c                     d| _         |d         }|r&|D ]}d|v r|d         |d<   d |D             | _        ng | _        |d         }|r	|| _        d S d| _        d S )N filessize
totalBytesc                 ,    g | ]}t          |          S r   r   .0r   s     r   
<listcomp>z%FileList.__init__.<locals>.<listcomp>      111a$q''111r   nextPageToken)error_messager  r  )r   	init_dictr  r   r   s        r   r   zFileList.__init__  s    '" 	 0 0Q;;&'iAlO115111DJJDJ/* 	$!&D!#Dr   responser   c                     t          g dd          }d|_        | j        }|rd |D             |_        ng |_        | j        }|r||_        nd|_        |S )zCreates a FileList object from an API response.

        Args:
            response (ApiListModelInstanceVersionFilesResponse): The API response.

        Returns:
            FileList: A new FileList object.
        r  r  r  c                 ,    g | ]}t          |          S r   r  r  s     r   r  z*FileList.from_response.<locals>.<listcomp>  r  r   )r  r  r  next_page_tokenr  )r  instr  r   s       r   from_responsezFileList.from_response  sv     "r::;; 	115111DJJDJ( 	$!&D!#Dr   c                     dS )Nr  r   r   s    r   r	  zFileList.__repr__  s    rr   N)	r   r   r   r   r   r
  ri   r!  r	  r   r   r   r  r    sk         $ $ $   H Z    \.    r   r  c                      e Zd ZU dZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZej                            d          Zesej                             ed          d          Zej                            d          rqej                            e          sWej                            ej                            d          p#ej                             ed          d          d          Zej                            e          s ej        e           dZ ej                            ee           Z!i Z"e#e$e$f         e%d<   dZ&g Z'e(e$         e%d<   ej                            d          dk    re')                    d           ej                            d           pej                            d!          pd"*                                Z+e+d#v r+e')                    d$            e,j-        e,j.        %            e,j/        e           Z0d&d'gZ1g d(Z2d)d*gZ3g d+Z4g d,Z5g d-Z6g d.Z7g d/Z8g d0Z9g d1Z:g d2Z;g d3Z<g d4Z=g d5Z>d6Z?g d7Z@g d8ZAg d9ZBg d:ZCg d;ZDg d<ZEg d=ZFg d>ZGg d?ZHg d@ZIg d:ZJg dAZKg dBZLg dCZMg dDZNdHdEeOfdFZPdGeQdHeOfdIZRdJ ZS	 	 	 	 dIdNeTeUgeUf         dOeVdPeVdQeWdReWdHeTeUgeUf         fdSZXdJdUZYdHeOfdVZZdW Z[dHeOfdXZ\dYe$dHe$fdZZ]d[e$dHeOfd\Z^d[e$dHeOfd]Z_dKd^e`e#e$e$f                  dHe#e$e$f         fd_ZadLd^e`e#e$e$f                  d`eOdHe#e$e$f         fdaZbdb ZcdMddZddHdee$dfe$d`eOdHdTfdgZedHdhZfdee$dHe`e$         fdiZgdje$dHe$fdkZhdNdnZidOdoZjdPdpeOdqeOfdrZkdKdse$fdtZldue$dHemfdvZndwe$fdxZodHepjq        jr        fdyZset	 dQde(e$         de$dze$d{e$dHepjq        jr        f
d|            Zudee$dHe$fd}Zvd~ewdexde$dHexfdZydfe$dHe$fdZz	 	 	 	 	 	 	 dRde`e$         de`e$         de`e$         de`eV         de`e$         de`eV         de`e$         dHe{dTz  fdZ|	 	 	 	 	 	 	 	 dSde`e$         de`e$         de`e$         de`eV         de`e$         de`eO         de`eV         de`e$         dHdTfdZ}	 	 	 	 dTde$de$de`e$         de`e$         de`eV         d`eOdHe~fdZ	 dHde$de$de$d`eOdHef
dZ	 	 	 	 	 	 	 dUde`e$         de`e$         de`e$         de`e$         de`e$         de`e$         d`eOdHe$fdZej        ej        ddfde$dedede$deVdHeedTz           dTz  fdZ	 	 	 	 	 	 	 dVdZ	 dWde$de`e$         deVdHefdZ	 dXdZ	 dYde$de$de`e$         dqeOd`eOdHdTfdZ	 dZde$de`e$         dqeOd`eOdHdTf
dZ	 d[dZd\de$de$d`eOdHdTfdZ	 d]de$de`eV         de`e$         dHeedTz           dTz  fdZ	 	 	 	 	 	 	 	 d^de`eV         de`e$         fdZ	 	 	 	 	 	 	 	 	 	 	 d_de`e$         de`e$         de`e$         de`e$         de`e$         de`e$         de`e$         de`eO         de`eV         de`e$         de`e$         dHeedTz           dTz  fdZ	 	 	 	 	 	 	 	 	 	 	 	 d`dZd Zd Zetd             Zetd             Zd ZdKdZdWdZdadZde$dHe$fdZdKdZdTddg fdZdTdddg fdZd Z	 dbdZde$d`eOdededHee$z  dTz  f
dZ	 	 	 	 dcde$de$d`eOdeOdeOde$dHefdȄZ	 dcdɄZdHde$de$deOdHdTfd̈́ZdHde$deOdHdTfd΄ZdHde$deOdHdTfdτZdHde$deOdHdTfdЄZde$dHe$fdфZdKd҄Z	 	 	 	 ddde$deOd`eOdeOde$dHefdԄZdedՄZdfdׄZ	 	 	 	 	 	 	 	 	 	 	 	 dgdeVdeVde`e$         de`e$         de`e$         de`e$         deOde`e$         de`e$         de`e$         de`e$         de`e$         dHeedTz           dTz  fd܄Z	 	 	 	 	 	 	 	 	 	 	 	 	 dhd݄ZdWdބZdad߄Zde$dHe$fdZdKdZdKde$de`e$         dHefdZd ZdidZdjdZdide$de$dqeOd`eOdHee(e$         e$f         f
dZÐdkdZd ZŐdKdZde$dHefdZȐdKdZ	 	 	 	 	 dlde`e$         de`e$         de`e$         deVde`e$         dHeedTz           dTz  fdZʐdmdZde$dHe$fdZ̐dKdZde$dHefdZϐdKdZde$deOdHefdZd Zd ZԐdKdZde$dHefdZאdKdZde$dHe$fdZd Zڐdnde$d`eOde$dHefdZېdndZܐdHde$deOdHefd Zݐd Z	 dode$dee$dTf         deVdeOdHef
dZdodZd]dHefdZdpdZd ZdKdZ	 dqde$de$de$d`eOde$dHefdZdqd	Z	 	 	 	 drd
e$de`e$         dqeOd`eOdeOdHe$fdZ	 dsdZ	 	 	 dod
e$dee$dTf         deVdeOdHeedTf         f
dZ	 dodZ	 d]dHefdZdpdZ	 dHd
e$deOdHefdZd Zd Zd ZdMdZd\dede$d`eOdHeOfdZdKdZdKdZd Zdee$exf         de$dHexfdZde#e$exf         de$de`ex         dHe`ex         fd Zde#e$ee$eOf         f         de$deOdHeOfd!Zde$dHe$fd"Z de$dHe$fd#Zde$dHe$fd$Zd% Z	 	 dnd&eߐeeeef         d'e`e(e#e$ee$e#e$e(e#e$e$f                  f         f         f                           de$deded`eOde$dHdTfd(Zd)e	dHe
fd*Z	 	 dtd+e$d,e$dedede$d`eOd'e`e(e#e$ee$e#e$e(e#e$e$f                  f         f         f                           dHeߐe	dTf         fd-Zde$d.e$deded`eOd'e`e(e#e$ee$e#e$e(e#e$e$f                  f         f         f                           dHeߐe	dTf         fd/Zd0 ZdHd1Zd2 Zd3 Zd4 Zde`e$         dHdTfd5Zd6 Zde$dHdTfd7Zde$dHeee$dTf         e$f         fd8Zde$dHdTfd9Zde$dHee$e$e$e$f         fd:Zd
e$dHdTfd;Zde`e$         dHdTfd<Zde$d'e(e#e$ee$e#e$e(e#e$e$f                  f         f         f                  dHdTfd=Zde$d'e(e#e$ee$e#e$e(e#e$e$f                  f         f         f                  dHdTfd>Zd'e(e#e$ee$e#e$e(e#e$e$f                  f         f         f                  dHdTfd?Zd@ ZdA ZdBe$dHe$fdCZ dudDe$fdEZ!defdFZ"dG Z#dTS (v  	KaggleApia/  
    KaggleApi provides methods for interacting with Kaggle's public API.

    This class manages authentication, configuration, and communication with Kaggle endpoints
    for datasets, competitions, kernels, models, and more. It supports downloading and uploading
    datasets, managing competition submissions, handling kernels (notebooks and scripts), and
    querying Kaggle resources.

    Configuration is handled via environment variables or a configuration file, and the class
    supports both API key and OAuth authentication methods. It validates input parameters for
    various Kaggle resource types and manages local paths and proxy settings.

    Usage:
        api = KaggleApi()
        api.authenticate()
        api.dataset_download_files('username/dataset-name')
        api.competition_submit('submission.csv', 'My submission', 'competition-name')

    There are many methods that have the suffix '_cli' in their name, which are intended to be used
    only from the command line interface (cli.py). These methods are not part of the public API.
    proxycompetitionr   usernameauth_methodkeyr   ssl_ca_certzX-Kaggle-ApiVersionzdataset-metadata.jsonzdatapackage.jsonzkernel-metadata.jsonzmodel-metadata.jsonzmodel-instance-metadata.jsoni  
   KAGGLE_CONFIG_DIR~z.kagglelinuxXDG_CONFIG_HOMEz.configkagglezkaggle.jsonconfig_valuesFr   KAGGLE_API_ENVIRONMENT	LOCALHOST--localVERBOSEVERBOSE_OUTPUTfalse)1trueyes	--verbose)levelscriptnotebook)pythonr   	rmarkdownoriginallatest)allr?  r   sqlitejulia)rC  r=  r>  )rC  visualizationdata)	hotnesscommentCountdateCreateddateRun	relevancescoreAscendingscoreDescending	viewCount	voteCount)generalentered	communityhosted
unlaunchedunlaunched_community)unspecifiedfeaturedresearchrecruitmentgettingStartedmasters
playground)groupedbestprizeearliestDeadlinelatestDeadlinenumberOfTeamsrL  recentlyCreated)rC  csvrD  r   bigQueryparquet)rC  ccgplodbr  )hottestvotesupdatedactive	published)rH  downloadCountrP  notebookCount
createTime)zdatasets downloadzdatasets filesz
auth login)refdeadlinecategoryreward	teamCountuserHasEntered)fileNamedatedescriptionstatuspublicScoreprivateScore)r   r  creationDater   r  r  )teamIdteamNamesubmissionDatescore)rs  titler  lastUpdatedrp  rP  usabilityRating)rs  r  r  r  rp  rP  r  )r   total_bytesr  idrs  r  subtitleauthor)	r  rs  r  slugr  r  	isPrivater{  publishTime)versionNumberversionNotescreationStatustotalUncompressedBytes)versionnotescreatedr  )r  variationSlug
modelTitler  )r  	variationr  privateenable_oauthc                     || _         d S r   )r  )r   r  s     r   r   zKaggleApi.__init__i  s    (r   r   r   c                    t          t          |          t                    pt          t          |          t          j                  pt          t          |          t          j                  p~t          t          |          t          j                  pWt          t          |          t          j        j                  p+t          t          |          t          j        j                  S r   )	
issubclasstypeConnectionErrorurllib3_exceptionsConnectTimeoutErrorProtocolErrorrequests
exceptionsConnectTimeout)r   r   s     r   _is_retriablezKaggleApi._is_retriablel  s    tAww00 G$q''#5#EFFG$q''#5#IJJG $q''#5#CDDG $q''8#6#FGG	G
 $q''8#6#EFF	
r   c                 t    |||z  z  }t          t                      dz
            dz  |z  |z  }||z   dz  }|S )N      ?rs   g     @@)r   r	   )r   attemptinitial_delay_millisretry_multiplierrandomness_factordelay_msrandom_wait_mstotal_delays           r   _calculate_backoff_delayz"KaggleApi._calculate_backoff_delayv  sL    '+;W+DEVXX^,,q08;>OO.0F:r     333333?r  funcmax_retriesr  r  r  c                 &      fd}|S )Nc                  T   t          ddz             D ]}	  |  c S # t          $ r|}t          |          t          u r`	                    |          rK|k     rE	                    |          }t          d||fz             t          j        |           Y d }~ d }~ww xY wd S )Nr   z/Request failed: %s. Will retry in %2.1f seconds)	ranger   r  rw   r  r  r   r   sleep)
r   ir   r  r  r  r  r  r  r   s
       r   retriable_funcz,KaggleApi.with_retry.<locals>.retriable_func  s    1kAo..  4;&&&  	 	 	Aww)++--a00 %Q__*.*G*G !#79IK\+ +K ""SWXZeVf"fggg J{333$HHHH	 s   
B%A1B B  B%r   )r   r  r  r  r  r  r  s   `````` r   
with_retryzKaggleApi.with_retry|  sB    	 	 	 	 	 	 	 	 	 	 r   Nc                 \   | j         r|                                 rdS |                                 rdS |                                 rdS | j         rt	          d           t	          d           n-t	          d                    | j        | j                             t          d           dS )zAuthenticate the user with the Kaggle API, using either a legacy API key or a Kaggle OAuth token.

        Returns:
            None:
        Nz0You must log in to Kaggle to use the Kaggle API.)Please run "kaggle auth login" to log in.zCould not find {}. Make sure it's located in {}. Or use the environment method. See setup instructions at https://github.com/Kaggle/kaggle-api/r   )	r  _authenticate_with_oauth_creds_authenticate_with_access_token _authenticate_with_legacy_apikeyr   formatconfig_file
config_direxitr   s    r   authenticatezKaggleApi.authenticate  s      	!D!D!F!F 	F//11 	F0022 	F 		DEEE=>>>>9 :@@PRVRa9b9b	   	Qr   c                 P   i }d                     t          j        dd                   }|                     |          }| j        |vs	| j        |vrlt          j                            | j	                  r| 
                    |d          }n0|                     |          r| 
                    |d          }dS dS | j        | j        fD ]}||vrt          d|z            || _        t          j        | j        | j        <   | j                            d| j	                    dS )	aM  Authenticate the user with the Kaggle API using legacy API key.

        This method will generate a configuration, first checking the
        environment for credential variables, and falling back to looking
        for the .kaggle/kaggle.json configuration file.

        Returns:
            bool: True if auth succeeded.
         r   NT)quietFz#Error: Missing %s in configuration.z&Authenticated with legacy api key in: )r   sysargvread_config_environmentCONFIG_NAME_USERCONFIG_NAME_KEYr   r   r   configread_config_file_command_allows_logged_out
ValueErrorr1  r   r   CONFIG_NAME_AUTH_METHODloggerdebug)r   r1  api_commanditems       r   r  z*KaggleApi._authenticate_with_legacy_apikey  sF    )+ hhsx|,, 44]CC  559MUb9b9bw~~dk**  $ 5 5m4 5 P P00==  $ 5 5m4 5 P Ptu *D,@A 	O 	OD=(( !F!MNNN )*;E;T478P4;PPQQQtr   c                 d   t                      \  }}|sdS |                     |          }|s | j                            d| d           dS | j        || j        || j        t          j        i| _	        | j                            d|            t          j                            dd            dS )NFz*Ignoring invalid/expired access token in "z".z$Authenticated with access token in: KAGGLE_API_TOKENT)r   _introspect_tokenr  r  CONFIG_NAME_TOKENr  r  r   r   r1  r   environpop)r   access_tokensourcer'  s       r   r  z)KaggleApi._authenticate_with_access_token  s    !:!<!<v 	5)),77 	KU6UUUVVV5 "L!8(**A.

 	IIIJJJ

)4000tr   c                    |                                  5 }t          j        |          }|s	 d d d            dS 	 |                                }nW# t          $ rJ}|j        j        dk    r4t          d           |                                 Y d }~d d d            dS  d }~ww xY w| j	        || j
        |                                | j        t          j        i| _        t           j                            t          j                  }| j                            d|            	 d d d            dS # 1 swxY w Y   d S )NclientFi  zInvalid credentials!z)Authenticated with OAuth credentials in: T)build_kaggle_clientr   r   get_access_tokenrw   r  status_coder   deleter  r  get_usernamer  r   r   r1  r   r   r   DEFAULT_CREDENTIALS_FILEr  r  )r   r0  credsr  r   
creds_paths         r   r  z(KaggleApi._authenticate_with_oauth_creds  s   %%'' 	6%*&999E 	 	 	 	 	 	 	 	$5577   :)S000111LLNNN 555	 	 	 	 	 	 	 	  &%u'9'9';';,j.>2D
 ++,=,VWWJKV*VVWWW'	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sA   D4AD4
B%3B D4B  B%%BD44D8;D8r  c                    |                                  5 }t                      }||_        	 |j        j                            |          }|j        r|j        s	 d d d            d S |j        cd d d            S # t          $ r@}|j	        j
        dv r,| j                            d|           Y d }~d d d            d S  d }~ww xY w# 1 swxY w Y   d S )N)i  i    zAccess token invalid: %s)r  rr   r   securityoauth_clientintrospect_tokenrn  r'  rw   r  r  r  r  )r   r  r0  requestr  r   s         r   r  zKaggleApi._introspect_token   sk   %%'' 	6,..G(GM	!?7HHQQ  h.?  	 	 	 	 	 	 	 	  (	 	 	 	 	 	 	 	    :)_<<K%%&@!DDD444	 	 	 	 	 	 	 	 		 	 	 	 	 	 	 	 	 	s@   C-A:'A::
C)B?-C>B??CCCCr  c                     |                      |          p6t          t          j                  dk    o|                    | j                  S )Nrs   )_is_help_or_version_commandlenr  r  
startswith*command_prefixes_allowing_anonymous_accessr   r  s     r   r  z$KaggleApi._command_allows_logged_out  sC    //<< 
MMAi+"8"89h"i"i	
r   c                 ,    |                     d          S )a  Determines if the string command passed in is for a help or version command.

        Args:
            api_command (str): a string, 'datasets list', 'competitions files', 'models instances get', etc.

        Returns:
            bool: True if valid
        )z-hz--help-vz	--version)endswithr  s     r   r  z%KaggleApi._is_help_or_version_command  s     ##$GHHHr   config_datac                     |i }t           j                                        D ]H\  }}|                    d          r.|                    ddd                                          }|||<   I|S )a  Reads config values from environment variables.

        This method is the second effort to get a username and key to
        authenticate to the Kaggle API. The environment keys are equivalent to
        the kaggle.json file, but with "KAGGLE_" prefix to define a unique
        namespace.

        Args:
            config_data (Optional[Dict[str, str][): a partially loaded configuration dictionary (optional)

        Returns:
            Dict[str, str]:
        NKAGGLE_r  r   )r   r  itemsr  r   lower)r   r  r)  val
config_keys        r   r  z!KaggleApi.read_config_environment   sv    " K
((** 	. 	.HC~~i(( . [[B::@@BB
*-J'r   r  c                    |i }t           j                            | j                  r	 t           j        dk    rRt          j        | j                  j        }|dz  s|dz  r*t          dd                    | j                  z              t          | j                  5 }t          j        |          pi }ddd           n# 1 swxY w Y   n#  Y nxY w|st          d           |S )a  Reads config values from the config file.

        This method is the first effort to get a username and key to
        authenticate to the Kaggle API. Since we can get the username and password
        from the environment, it's not required.

        Args:
            config_data (Optional[Dict[str, str]]): the Configuration object to save a username and
            quiet (bool): suppress verbose print of output (default is False)

        Returns:
            Dict[str, str]:
        Nnt       zaWarning: Your Kaggle API key is readable by other users on this system! To fix this, you can run z'chmod 600 {}'z6No Kaggle API config file found, will use environment.)r   r   r   r  r   statst_moder   r  r   r   r   )r   r  r  permissionsr   s        r   r  zKaggleApi.read_config_file<  s<    K7>>$+&& 	P7d??"$'$+"6"6">K#a [2-= NP`PgPghlhsPtPtu  
 $+&& 5!"&)A,,"4"K5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
  PNOOOs0   A6C  C7C CC 
CC Cc                     	 t          | j        d          5 }t          j        |          }ddd           n# 1 swxY w Y   n# t          $ r i }Y nw xY w|S )z_Reads the config file.

        The config file is a json file defined at self.config.
        r   N)r   r  r   r   FileNotFoundError)r   r   r  s      r   _read_config_filezKaggleApi._read_config_filee  s    	dk3'' +1"ill+ + + + + + + + + + + + + + +  	 	 	KKK	 s-   A 8A <A < A AArs   c                     t          | j        d          5 }t          j        |||           ddd           dS # 1 swxY w Y   dS )zWrites config data to file.

        Args:
            config_data: the Configuration object to save a username and
                password, if defined
            indent: number of tab indentations to use when writing json
        r   r   N)r   r  r   r   )r   r  r   r   s       r   _write_config_filezKaggleApi._write_config_files  s     $+s## 	5qIk1V4444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s   ;??r   valuec                     |                                  }|?|||<   || j        |<   |                     |           |s|                     |d           dS dS dS )a  Sets a config value.

        A client helper function to set a configuration value, meaning reading
        in the configuration file (if it exists), saving a new config value, and
        then writing back.

        Args:
            name (str): the name of the value to set (key in dictionary)
            value (str): the value to set at the key
            quiet (bool): disable verbose output if True (default is False)

        Returns:
            None:
        N is now set to: 	separator)r
  r1  r  print_config_value)r   r   r  r  r  s        r   set_config_valuezKaggleApi.set_config_value~  s      ,,.. !&K (-Dt$ ##K000 L''8J'KKKKK L Lr   c                     |                                  }||v r3||= |                     |           |s|                     |d           dS dS dS )zRemoves a configuration value from the config file.

        Args:
            name: the name of the value to unset (remove key in dictionary)
            quiet: disable verbose output if True (default is False)
        r  r  N)r
  r  r  )r   r   r  r  s       r   unset_config_valuezKaggleApi.unset_config_value  sy     ,,..;D!##K000 L''8J'KKKKK L Lr   c                 6    | j                             |          S )zReturns a config value.

        Args:
            name (str): the config value key to get

        Returns:
            Optional[str]: The config value if it's in the config_values, otherwise None.
        )r1  r  r   r   s     r   get_config_valuezKaggleApi.get_config_value  s     !%%d+++r   subdirsc                     |                      | j                  }|t          j                    S t          j        j        |g|R  S )a!  Gets the download path for a file.

        If not set in the config file then return the current working directory.

        Args:
            subdirs: a single (or list of) subfolders under the basepath

        Returns:
            str: the configured path or current directory
        )r  CONFIG_NAME_PATHr   getcwdr   r   )r   r  r   s      r   get_default_download_dirz"KaggleApi.get_default_download_dir  sG     $$T%:;; <9;;w|D+7++++r   - : c                 ~    d}|| j         v r| j         |         | j         |         }t          | | | |            dS )zPrints a single configuration value.

        Args:
            name: the key of the config valur in self.config_values to print
            prefix: the prefix to print
            separator: the separator to use (default is : )
        NoneN)r1  r   )r   r   prefixr  	value_outs        r   r  zKaggleApi.print_config_value  sZ     	4%%%$*<T*B*N*40I55y5)5566666r   c                 ^   | j         sdS t          d| j         z              |                     | j        |           |                     | j        |           |                     | j        |           |                     | j        |           |                     | j        |           dS )zPrints all configuration values.

        Args:
            prefix: the character prefix to put before the printed config value,
                defaults to "- "
        NzConfiguration values from )r"  )r  r   r  r  r  r  CONFIG_NAME_PROXYCONFIG_NAME_COMPETITION)r   r"  s     r   print_config_valueszKaggleApi.print_config_values  s      	F*T_<=== 5fEEE <VLLL 5fEEE 6vFFF <VLLLLLr   no_launch_browserforcec                 l   dg}|                                  5 }t          j        |          }|E|sCt          d|                                 d           t          d           t          d           t          |          }|                    ||           ddd           dS # 1 swxY w Y   dS )	zLogs in to Kaggle.

        Args:
            no_launch_browser (bool): Don't launch a browser. Print a URL instead.
            force (bool): Force a new login, even if already logged in.
        zresources.admin:*r  Nz(You are already logged-in to Kaggle as [z].z(Please use the --force flag to override.r   )scopesr(  )r  r   r   r   r  r  r   r  )r   r(  r)  default_scopesr0  r  oAuths          r   auth_login_clizKaggleApi.auth_login_cli  s    ..%%'' 	[6%*&999E  YASASAUAUYYYZZZ@AAAQv...EnHYZZZ	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[s   BB))B-0B-expiration_durationc                    |r|                      |          nd}|                                 5 }t          j        |          }|-t	          d           t	          d           t          d           |                    |          }|t	          d           t          d           t	          |j                   ddd           dS # 1 swxY w Y   dS )a  Prints the current OAuth access token.

        If an expiration duration is provided, a new token will be generated with the specified
        expiration duration. Otherwise, the current token will be printed.

        The expiration duration should be in the format of a string with a number followed by a unit,
        e.g. "1h" for one hour, "2d" for two days, etc.

        Args:
            expiration_duration (str): The duration the generated token should be valid for. Defaults to None.
        Nr  z3You must log in to Kaggle to print an access token.r  r   zQUnable to generate an access token. Please run "kaggle auth login" and try again.)_parse_durationr  r   r   r   r  generate_access_tokenr   )r   r/  
expirationr0  r  r  s         r   auth_print_access_tokenz!KaggleApi.auth_print_access_token   s    CV_T))*=>>>[_
%%'' 
	"6%*&999E}KLLLABBBQ22:>>HijjjQ(.!!!
	" 
	" 
	" 
	" 
	" 
	" 
	" 
	" 
	" 
	" 
	" 
	" 
	" 
	" 
	" 
	" 
	" 
	"s   BC		CCduration_strc           
          	 t          di |d         t          |d d                   i}|S # t          $ r t          d          w xY w)NzVInvalid duration format. Please use one of the following formats: 1h, 30s, 2h30s, 2:30r   )r   r   r  )r   r5  deltas      r   r1  zKaggleApi._parse_duration  si    	w!OO\"%5s<;L7M7M$NOOEL 	w 	w 	wuvvv	ws	   *- Areasonc                     |                                  5 }t          j        |          }|t          d           t	          d           |                    |pd           ddd           dS # 1 swxY w Y   dS )a  Revokes the current OAuth access token.

        This command will revoke the current access token. If a reason is provided, it will be
        sent to the server as part of the revocation request. If no reason is provided, "Manually
        revoked by user with kaggle-cli" will be sent.

        Args:
            reason (str): The reason for revoking the token. Defaults to None.
        r  NzThere is no token to revoke.r   z(Manually revoked by user with kaggle-cli)r  r   r   r   r  revoke_token)r   r9  r0  r  s       r   auth_revoke_tokenzKaggleApi.auth_revoke_token   s     %%'' 	U6%*&999E}4555QvS)STTT	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	Us   AA//A36A3c                    t                               | j        | j                            | j                  | j                            | j                  | j                            | j                  |                                           S )zuBuilds a Kaggle client.

        Returns:
            kagglesdk.kaggle_client.KaggleClient: A Kaggle client.
        )r   r'  password	api_tokenresponse_processor)	r$  build_kaggle_client_with_paramsr   r1  r  r  r  r  get_response_processorr   s    r   r  zKaggleApi.build_kaggle_client1  sz     88'++D,ABB'++D,@AA(,,T-CDD#::<< 9 
 
 	
r   r>  r?  c                     d| v rt           j        n+d| v rt           j        nd| v rt           j        nt           j        }d| v pd| v }t          ||||||          S )a  Builds a Kaggle client with the given parameters.

        Args:
            args (List[str]): A list of arguments.
            username (str): The username to use for authentication.
            password (str): The password to use for authentication.
            api_token (str): The API token to use for authentication.
            response_processor: Callback used to process HTTP response.

        Returns:
            kagglesdk.kaggle_client.KaggleClient: A Kaggle client.
        z	--stagingz--adminr4  r;  r  )envverboser'  r>  r?  r@  )r   STAGINGADMINLOCALPRODr   )r   r'  r>  r?  r@  rD  rE  s          r   rA  z)KaggleApi.build_kaggle_client_with_params?  s    $ d"" %.$%6%6)//y\`O`O`IOOfoft 	
 %51
 
 
 	
r   c                 ~    t          j        dd|          }t          j        dd|                                          S )zConverts a camel case string to snake case.

        Args:
            name (str): The string in camel case.

        Returns:
            str: The string in snake case.
        z(.)([A-Z][a-z]+)z\1_\2z([a-z0-9])([A-Z]))resubr  r  s     r   camel_to_snakezKaggleApi.camel_to_snake^  s9     v((D99v)8T::@@BBBr   
enum_classsample	item_namec                    |                      |                                          }	 ||         S # t          $ r[ |                      |j                                                  }| d|                      |                                           }Y nw xY w	 ||         S # t          $ rP |                    dd          }t          |          D ](}|                    dd          |k    r||         c cY S ) w xY w)Nr   r  )rM  upperKeyErrorr   r   vars)r   rN  rO  rP  r  r"  	full_names          r   lookup_enumzKaggleApi.lookup_enumj  s3   ""9--3355	Md## 	M 	M 	M(()<==CCEEF!LLD$7$7	$B$B$H$H$J$JLLIII	M	i(( 	 	 	!))#r22IZ(( , ,<<R((I55%d++++++ 6	s#   1 A"BBB" "AC<9C<c                     t          |          }|                    d          }t          |                     |d                             dz   }|d         |d                                          S )N.r   r   )r   r   r  rM  r  )r   r  rU  names
prefix_lens        r   short_enum_namezKaggleApi.short_enum_name|  sa    JJ	$$,,U1X6677!;
Qx
$**,,,r   r      groupru  sort_bypagesearch	page_size
page_tokenc                 l   t           j        }|r\|| j        vr$t          dt	          | j                  z             |dk    rt           j        }n|                     t           ||          }t          j        }	|rR|| j        vr-|dk    rd}n$t          dt	          | j                  z             |                     t          |	|          }	t          j
        }
|rI|| j        vr$t          dt	          | j                  z             |                     t          |
|          }
|                                 5 }t                      }||_        |dk    r||_        |	|_        |pd|_        |
|_        ||_        ||_        |j        j                            |          cddd           S # 1 swxY w Y   dS )	a  Make a call to list competitions, format the response, and return a list of ApiCompetition instances.

        Args:
            group (Optional[str]): group to filter result to
            category (Optional[str]): category to filter result to; use 'all' to get closed competitions
            sort_by (Optional[str]): how to sort the result, see valid_competition_sort_by for options
            page (Optional[int]): the page to return (default is 1)
            search (Optional[str]): a search term to use (default is empty string)
            page_size (Optional[int]): the number of items to show on a page
            page_token (Optional[str]): the page token for pagination

        Returns:
            Union[ApiListCompetitionsResponse, None]:
        z+Invalid group specified. Valid options are rC  rW  z.Invalid category specified. Valid options are z-Invalid sort_by specified. Valid options are r7  r  N)r.   COMPETITION_LIST_TAB_EVERYTHINGvalid_competition_groupsr  r   rV  r/   HOST_SEGMENT_UNSPECIFIEDvalid_competition_categoriesr0   COMPETITION_SORT_BY_BESTvalid_competition_sort_byr  r   r]  r_  ru  r`  r^  ra  rb  competitionscompetition_api_clientlist_competitions)r   r]  ru  r^  r_  r`  ra  rb  	group_valcategory_valsort_by_valr0  r  s                r   competitions_listzKaggleApi.competitions_list  s    0 'F	 	SD999 !NQTUYUrQsQs!sttt~~.N		 ,,-?ERR	"; 	Qt@@@u$$,HH$H3tOpKqKqq    ++KxPPL'@ 	Td<<< !PSVW[WuSvSv!vwww**+<k7SSK%%'' 	Y6022G%GMrzz#+G#\rGN)GO )G!+G&=OOPWXX	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Ys   6A&F))F-0F-csv_displayc	           	      B   |                      |||||||          }	|	j        r't          d                    |	j                             |	j        }
|
r<|r|                     |
| j                   dS |                     |
| j                   dS t          d           dS )a  A wrapper for competitions_list for the client.

        Args:
            group (Optional[str]): group to filter result to
            category (Optional[str]): category to filter result to
            sort_by (Optional[str]): how to sort the result, see valid_sort_by for options
            page (Optional[int]): the page to return (default is 1)
            search (Optional[str]): a search term to use (default is empty string)
            csv_display (Optional[bool]): if True, print comma separated values
            page_size (Optional[int]): the number of items to show on a page
            page_token (Optional[str]): the page token for pagination

        Returns:
            None:
        )r]  ru  r^  r_  r`  ra  rb  Next Page Token = {}zNo competitions foundN)rp  r  r   r  rj  	print_csvcompetition_fieldsprint_table)r   r]  ru  r^  r_  r`  rq  ra  rb  r  rj  s              r   competitions_list_clizKaggleApi.competitions_list_cli  s    4 ))! * 
 
 # 	K(//0HIIJJJ, 	+ H|T-DEEEEE  t/FGGGGG)*****r   	file_namemessagekernelkernel_versionc                 `   |0|                      | j                  }||st          d|z              |t          d          |t          d          |                                 5 }|                    d          }t          |          dk    rt          d          t                      }	||	_        ||	_	        |d         |	_
        |d	         |	_        |rt          |          |	_        |r||	_        |j        j                            |	          }
|
cddd           S # 1 swxY w Y   dS )
a  Submit to a code competition.

        Args:
            file_name (str): the name of  the output file created by the kernel (not used for packages)
            message (str): the submission description
            competition (Optional[str]): the competition name; if not given use the 'competition' config value
            kernel (Optional[str]): the <owner>/<notebook> of the notebook to use for a code competition
            kernel_version (Optional[int]): the version number, returned by 'kaggle kernels push ...'
            quiet (bool): suppress verbose output (default is False)

        Returns:
            ApiCreateCodeSubmissionResponse:
        NUsing competition: No competition specifiedzNo kernel specified/rs   z2The kernel must be specified as <owner>/<notebook>r   r   )r  r&  r   r  r  r   r  r   rx  competition_name_kernel_ownerkernel_slugr   r{  submission_descriptionrj  rk  create_code_submission)r   rx  ry  r&  rz  r{  r  r0  r  submit_requestsubmit_responses              r   competition_submit_codez!KaggleApi.competition_submit_code  s   , //0LMMK&u&+k9:::7888>2333))++ 'vS))u::??$%YZZZ!?!A!A+4(2=//4Qx,-21X*! H474G4GN1 D<CN9"("5"L"c"cdr"s"s&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 's   )B-D##D'*D'c                    |0|                      | j                  }||st          d|z              |t          d          |t          d          |                                 5 }t                      }||_        t          j        	                    |          |_
        t          j                            |          |_        t          t          j                            |                    |_        |j        j                            |          }|                     ||j        |          }|t*          j        k    r#t/                      }	d|	_        |	cddd           S t3                      }
||
_        |j        |
_        |r||
_        |j        j                            |
          }|cddd           S # 1 swxY w Y   dS )aZ  Submits to a competition.

        Args:
            file_name (str): The competition metadata file.
            message (str): The submission description.
            competition (str): The competition name.
            quiet (bool): Suppress verbose output (default is False).

        Returns:
            ApiCreateSubmissionResponse:
        Nr}  r~  zNo file specifiedzCould not submit to competition)r  r&  r   r  r  r    r  r   r   basenamerx  getsizecontent_lengthr   getmtimelast_modified_epoch_secondsrj  rk  start_submission_uploadr   
create_urlr   COMPLETEr   ry  r!   r   blob_file_tokensr  create_submission)r   rx  ry  r&  r  r0  r  r  upload_statusrespr  r  s               r   competition_submitzKaggleApi.competition_submit!  s    //0LMMK&u&+k9:::7888  !4555))++ 'v9;;+6($&G$4$4Y$?$?!)+)C)C&69"':J:J9:U:U6V6V3!.E]]^eff $ 4 4Y@SUZ [ [ $9$BBB 788D#DDL' ' ' ' ' ' ' ' "<!=!=2=/2:./ D<CN9'>PPQ_``   '/' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 's   )C0F=&A
F==GGr  competition_optc                    |r|r|r|st          d          |p|}	 |rT|                     t          t          |          t          t          |          t          t          |          |||          }nQ|                     t          t          |          t          t          |          t          t          |          |          }n@# t
          $ r3}	|	j        r%|	j        j        dk    rt          d           Y d}	~	dS |	d}	~	ww xY w|j	        S )a  Submits a competition using the client.

        Args:
            file_name (Optional[str]): The competition metadata file.
            message (Optional[str]): The submission description.
            competition (Optional[str]): The competition name.
            kernel (Optional[str]): The name of the kernel to submit to a code competition.
            version (Optional[str]): The version of the kernel to submit to a code competition, e.g. '1'.
            competition_opt (Optional[str]): An alternative competition option provided by cli.
            quiet (bool): Suppress verbose output (default is False).

        Returns:
            str:
        zTCode competition submissions require both the output file name and the version labelr  zCould not find competition - please verify that you entered the correct competition ID and that the competition is still accepting submissions.Nr  )
r  r  rz   r   r  r
   r  r  r   ry  )
r   rx  ry  r&  rz  r  r  r  submit_resultr   s
             r   competition_submit_cliz KaggleApi.competition_submit_cliR  sA   0  	u' 	uW 	uV 	usttt!4_	  $ < <i(($sG*<*<d3>T>TV\^egl! ! !% 7 7i(($sG*<*<d3>T>TV[! !   		 		 		z aj4;;B  
 rrrrr		 $$s   B'C 
D&C=;C==Dr  sortc                    |                                  5 }t                      }||_        ||_        ||_        ||_        ||_        |j        j        	                    |          }|j
        }	|	cddd           S # 1 swxY w Y   dS )a  Gets the list of submissions for a competition.

        Args:
            competition (str): The name of the competition.
            group (SubmissionGroup): The submission group.
            sort (SubmissionSortBy): The sort-by option.
            page_token (str): The pageToken for pagination.
            page_size (int): The number of items per page.

        Returns:
            Union[listApiSubmission, None, None]:
        N)r  r#   r  rb  ra  r]  r^  rj  rk  list_submissionssubmissions)
r   r&  r]  r  rb  ra  r0  r  r  results
             r   competition_submissionsz!KaggleApi.competition_submissions  s    ( %%'' 		6/11G'2G$!+G )G!GM"GO*ARRSZ[[H8@8LF		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		s   AA;;A?A?r7  c                 `   |p|}|0|                      | j                  }||st          d|z              |t          d          |                     ||||          }|r<|r|                     || j                   dS |                     || j                   dS t          d           dS )a  A wrapper to competition_submission, will return either json or csv to the user.

        Args:
            competition: the name of the competition. If None, look to config
            competition_opt: an alternative competition option provided by cli
            csv_display: if True, print comma separated values
            page: page number
            page_token: token for pagination
            page_size: the number of items per page
            quiet: suppress verbose output (default is False)
        Nr}  r~  )page_numberrb  ra  zNo submissions found)r  r&  r   r  r  rt  submission_fieldsrv  )	r   r&  r  rq  r_  rb  ra  r  r  s	            r   competition_submissions_cliz%KaggleApi.competition_submissions_cli  s    * "4_//0LMMK&u&+k9:::788866*PY 7  K  . JNN;0FGGGGG$$[$2HIIIII,-----r   c                 t   |                                  5 }t                      }||_        t          t          |          |_        ||_        |j        j        	                    |          }t          t          t                   |j                  D ]}|j        |_        |cddd           S # 1 swxY w Y   dS )a,  Lists files for a competition.

        Args:
            competition (str): The name of the competition.
            page_token (Optional[str]): The page token for pagination.
            page_size (int): The number of items per page.

        Returns:
            ApiListDataFilesResponse:
        N)r  r%   r  rz   r   rb  ra  rj  rk  list_data_filesr   r+   r  r   rs  )r   r&  rb  ra  r0  r  r  files           r   competition_list_filesz KaggleApi.competition_list_files  s     %%'' 	6-//G'2G$!%c:!6!6G )G171D1[1k1kls1t1tHXk2HNCC % %9	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   BB--B14B1c                    |p|}|0|                      | j                  }||st          d|z              |t          d          |                     |||          }|j        }|r"t          d                    |                     |rR|r(|                     |j        | j	        | j
                   dS |                     |j        | j	        | j
                   dS t          d           dS )a  List files for a competition, if it exists.

        Args:
            competition: the name of the competition. If None, look to config
            competition_opt: an alternative competition option provided by cli
            csv_display: if True, print comma separated values
            page_token: the page token for pagination
            page_size: the number of items per page
            quiet: suppress verbose output (default is False)
        Nr}  r~  rs  No files found)r  r&  r   r  r  r  r  rt  r  competition_file_fieldscompetition_file_labelsrv  )	r   r&  r  rq  rb  ra  r  r  r  s	            r   competition_list_files_cliz$KaggleApi.competition_list_files_cli  s    "4_//0LMMK&u&+k9:::788800j)TTF$4O F,33ODDEEE ( oNN6<1MtOklllll$$V\43OQUQmnnnnn&'''''r   c           	      p   ||                      d|          }n|}|                                 5 }t                      }||_        ||_        |j        j                            |          }	ddd           n# 1 swxY w Y   |	j        j	        }
t          t          t          j                            ||
                    d          d                             d          d                             }|s|                     |	||          r)|                     |	| |j                    ||            dS dS )a  Downloads a competition file.

        Args:
            competition (str): The name of the competition.
            file_name (str): The configuration file name.
            path (Optional[str]): A path to download the file to.
            force (bool): Force the download if the file already exists (default False).
            quiet (bool): Suppress verbose output (default is False).

        Returns:
            None:
        Nrj  ?r   r  r7  )r  r  r&   r  rx  rj  rk  download_data_filer  urlrz   r   r   r   r   r   download_neededdownload_filehttp_client)r   r&  rx  r   r)  r  effective_pathr0  r  r  r  outfiles               r   competition_download_filez#KaggleApi.competition_download_file  s~    <!::>;WWNN!N%%'' 	^6022G'2G$ )G*ATTU\]]H		^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^
 "sBGLL39J9P9PQT9U9UVX9YZZ[[ 	ZD((7EBB 	Zx2D&2D2F2FSXyYYYYY	Z 	Zs   <A88A<?A<Tc                 <   ||                      d|          }n|}|                                 5 }t                      }||_        |j        j                            |          }|j                            d          d         }	t          j
                            ||dz   |	                    d          d         z             }
|s|                     ||
|          r'|                     ||
 |j                    ||            ddd           dS # 1 swxY w Y   dS )ax  Downloads all competition files.

        Args:
            competition (str): The name of the competition.
            path (Optional[str]): A path to download the file to.
            force (bool): Force the download if the file already exists (default False).
            quiet (bool): Suppress verbose output (default is True).

        Returns:
            None:
        Nrj  r  r   rX  r7  )r  r  r'   r  rj  rk  download_data_filesr  r   r   r   r   r  r  r  )r   r&  r   r)  r  r  r0  r  r  r  r  s              r   competition_download_filesz$KaggleApi.competition_download_files"  sq    <!::>;WWNN!N%%'' 	^6133G'2G$*AUUV]^^H,$$S))!,Cgll>;3DsyyQT~~VXGY3YZZG ^,,XwFF ^""8W6Hf6H6J6JEW\S\]]]	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^ 	^s   CDDDc                     |p|}|0|                      | j                  }||st          d|z              |t          d          ||                     ||||           dS |                     |||||           dS )a  Downloads competition files.

        Args:
            competition: The name of the competition.
            competition_opt: An alternative competition option provided by cli.
            file_name: The configuration file name.
            path: A path to download the file to.
            force: Force the download if the file already exists (default False).
            quiet: Suppress verbose output (default is False).
        Nr}  r~  )r  r&  r   r  r  r  )r   r&  r  rx  r   r)  r  s          r   competition_download_cliz"KaggleApi.competition_download_cli?  s     "4_//0LMMK&u&+k9:::7888 //T5%PPPPP..{ItUTYZZZZZr   c                    |                                  5 }t                      }||_        |j        j                            |          }ddd           n# 1 swxY w Y   ||                     d|          }n|}|dz   }t          j        	                    ||          }	| 
                    ||	 |j                    |           dS )a  Downloads a competition leaderboard.

        Args:
            competition (str): The name of the competition.
            path (str): A path to download the file to.
            quiet (bool): Suppress verbose output (default is True).

        Returns:
            None:
        Nrj  .zip)r  r(   r  rj  rk  download_leaderboardr  r   r   r   r  r  )
r   r&  r   r  r0  r  r  r  rx  r  s
             r    competition_leaderboard_downloadz*KaggleApi.competition_leaderboard_downloadZ  s    %%'' 	`6355G'2G$*AVVW^__H	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` 	` <!::>;WWNN!N&(	',,~y998W.@f.@.B.BEJJJJJs   5AAAc                 L   |                                  5 }t                      }||_        ||_        ||_        |j        j                            |          }ddd           n# 1 swxY w Y   |j        r't          d
                    |j                             |j        }|S )as  View a leaderboard based on a competition name.

        Args:
            competition (str): the competition name to view leadboard for
            page_size (Optional[int]): the number of items to show on a page
            page_token (Optional[str]): the page token for pagination

        Returns:
            Union[listApiLeaderboardSubmission, None, None]:
        Nrs  )r  r*   r  ra  rb  rj  rk  get_leaderboardr  r   r  r  )r   r&  ra  rb  r0  r  r  r  s           r   competition_leaderboard_viewz&KaggleApi.competition_leaderboard_viewr  s     %%'' 	[6.00G'2G$ )G!+G*AQQRYZZH	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[ # 	K(//0HIIJJJ?G?Ss   AA$$A(+A(c
                    |p|}|s|st          d          |0|                     | j                  }||st          d|z              |t          d          |r|                     |||           |rf|                     |||	          }
|
r<|r|                     |
| j                   dS |                     |
| j                   dS t          d           dS dS )a-  A wrapper for competition_leaderbord_view that will print the results as a table or comma separated values.

        Args:
            competition (str): the competition name to view leadboard for
            competition_opt (str): an alternative competition option provided by cli
            path (Any): a path to download to, if download is True
            view (bool): if True, show the results in the terminal as csv or table
            download (bool): if True, download the entire leaderboard
            csv_display (bool): if True, print comma separated values instead of table
            quiet (bool): suppress verbose output (default is False)
            page_size (Optional[int]): the number of items to show on a page
            page_token (Optional[str]): the page token for pagination
        z-Either --show or --download must be specifiedNr}  r~  zNo results found)	r  r  r&  r   r  r  rt  competition_leaderboard_fieldsrv  )r   r&  r  r   viewdownloadrq  r  ra  rb  resultss              r   competition_leaderboard_cliz%KaggleApi.competition_leaderboard_cli  s+   2 "4_ 	NH 	NLMMM//0LMMK&u&+k9:::7888 	L11+tUKKK 	*77YPZ[[G * SNN7D,OPPPPP$$Wd.QRRRRR()))))	* 	*r   r  	file_typelicense_nametag_idsuserminemax_sizemin_sizec                    t           j        }|rI|| j        vr$t          dt	          | j                  z             |                     t           ||          }|rt          d          t          j        }|rI|| j        vr$t          dt	          | j                  z             |                     t          ||          }t          j
        }|rI|| j        vr$t          dt	          | j                  z             |                     t          ||          }|	r"t          |	          dk    rt          d          |
r1|r/t          |
          t          |          k     rt          d          |
r"t          |
          dk    rt          d          |r"t          |          dk     rt          d	          t          j        }|rt          j        }|rt          d
          |rt          j        }|                                 5 }t%                      }||_        ||_        ||_        ||_        |pd|_        |pd|_        |pd|_        |	rt          |	          nd|_        |
rt          |
          nd|_        |rt          |          nd|_        |j        j                            |          }|j        }|cddd           S # 1 swxY w Y   dS )a  Return a list of datasets.

        Args:
            sort_by (Optional[str]): how to sort the result, see valid_dataset_sort_bys for options
            size (Optional[str]): Deprecated
            file_type (Optional[str]): the format, see valid_dataset_file_types for string options
            license_name (Optional[str]): string descriptor for license, see valid_dataset_license_names
            tag_ids (Optional[str]): tag identifiers to filter the search
            search (Optional[str]): a search term to use (default is empty string)
            user (Optional[str]): username to filter the search to
            mine (Optional[bool]): boolean if True, group is changed to "my" to return personal
            page (Optional[int]): the page to return (default is 1)
            max_size (Optional[str]): the maximum size of the dataset to return (bytes)
            min_size (Optional[str]): the minimum size of the dataset to return (bytes)

        Returns:
            Union[listApiDataset, None, None]:
        -Invalid sort by specified. Valid options are zgThe --size parameter has been deprecated. Please use --max-size and --min-size to filter dataset sizes.z/Invalid file type specified. Valid options are z-Invalid license specified. Valid options are r   Page number must be >= 1z%Max Size must be max_size >= min_sizezMax Size must be > 0zMin Size must be >= 0z#Cannot specify both mine and a userr  N) rD   DATASET_SORT_BY_HOTTESTvalid_dataset_sort_bysr  r   rV  rE   DATASET_FILE_TYPE_GROUP_ALLvalid_dataset_file_typesrF   DATASET_LICENSE_GROUP_ALLvalid_dataset_license_namesr   rC   DATASET_SELECTION_GROUP_PUBLICDATASET_SELECTION_GROUP_MYDATASET_SELECTION_GROUP_USERr  r3   r]  r^  r  licenser  r`  r  r_  r  r  datasetsdataset_api_clientlist_datasets)r   r^  r  r  r  r  r`  r  r  r_  r  r  ro  file_type_vallicense_name_valr]  r0  r  r  r  s                       r   dataset_listzKaggleApi.dataset_list  sH   @ $; 	Td999 !PSVW[WrSsSs!sttt"..}k7SS 	R  
 -H 	a === !RUXY]YvUwUw!wxxx $ 0 01E}V_ ` `.H 	i4#CCC Cc$JjFkFkk   $(#3#34GIY[g#h#h  	9CIINN7888 	J 	J8}}s8}},, !HIII 	6H**3444 	6#h--!++4555%D 	H)DE H !FGGG 	G)FE%%'' 	6,..G!GM)GO -G.GO%mGO#\rGN:2GL(,63t999$GL08Bs8}}}dG08Bs8}}}dG9GGPPH5=5FF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   B5KK	K	c                     |                      |||||||||	||          }|rH|
r#|                     || j        | j                   dS |                     || j        | j                   dS t          d           dS )aq  A wrapper to dataset_list for the client.

        Args:
            sort_by: how to sort the result, see valid_dataset_sort_bys for options
            size: DEPRECATED
            file_type: the format, see valid_dataset_file_types for string options
            license_name: string descriptor for license, see valid_dataset_license_names
            tag_ids: tag identifiers to filter the search
            search: a search term to use (default is empty string)
            user: username to filter the search to
            mine: boolean if True, group is changed to "my" to return personal
            page: the page to return (default is 1)
            csv_display: if True, print comma separated values instead of table
            max_size: the maximum size of the dataset to return (bytes)
            min_size: the minimum size of the dataset to return (bytes)
        zNo datasets foundN)r  rt  dataset_fieldsdataset_labelsrv  r   )r   r^  r  r  r  r  r`  r  r  r_  rq  r  r  r  s                 r   dataset_list_clizKaggleApi.dataset_list_cli  s    > $$T9lGVT4QUW_ai
 
  	' Ux)<d>QRRRRR  4+>@STTTTT%&&&&&r   c                    |t          d          d|v r;|                     |           |                    d          }|d         }|d         }n|                     | j                  }|}||                     d||          }n|}|||fS )z
        Prepare the dataset metadata for download.

        :param dataset: The dataset to prepare.
        :param path: The path to download the metadata to.
        :return: A tuple containing the owner slug, dataset slug, and effective path.
        NA dataset must be specifiedr  r   r   r  )r  validate_dataset_stringr   r  r  r  )r   datasetr   dataset_urls
owner_slugdataset_slugr  s          r   dataset_metadata_prepzKaggleApi.dataset_metadata_prepF  s     ?:;;;'>>((111"==--L%aJ'?LL..t/DEEJ"L<!:::zS_``NN!NL.99r   c                 ~                          ||          \  }}}                     |          }t          |d          5 }t          j        |          }|                    d          p|}t                      }	|                    d          pd|	_        |                    d          pd|	_        |                    d          pd|	_	        |                    d          pd|	_
        |                    d	          r fd
|d	         D             ng |	_        |                    d          |	_        |                    d          r fd|d         D             ng |	_        |                    d          |	_        t                      }
||
_        ||
_        |	|
_                                         5 }|j        j                            |
          }t/          |j                  dk    r d |j        D              t3          d           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )zUpdates the metadata for a dataset.

        Args:
            dataset: The dataset to update.
            path: The path to the metadata file.
        r   infor  r  r  r{  r  Flicensesc                 F    g | ]}                     |d                    S r   )_new_license)r  lr   s     r   r  z5KaggleApi.dataset_metadata_update.<locals>.<listcomp>r  s+    LLL!""1V9--LLLr   keywordscollaboratorsc                 T    g | ]$}                     |d          |d                   %S )r'  role)_new_collaborator)r  cr   s     r   r  z5KaggleApi.dataset_metadata_update.<locals>.<listcomp>v  s1    eeea''*qyAAeeer   rG  r   c                 8    g | ]}t          |d                    S )ry  )r   )r  r   s     r   r  z5KaggleApi.dataset_metadata_update.<locals>.<listcomp>  s$    BBBQU1Y<((BBBr   r   N)r  get_dataset_metadata_filer   r   r   r  rG   r  r  r{  
is_privater  r  r  rG  r<   r  r  settingsr  r  r  update_dataset_metadatar  errorsr  )r   r  r   r  r  r  	meta_filer   metadataupdate_settingsr  r0  r  s   `            r   dataset_metadata_updatez!KaggleApi.dataset_metadata_update`  s    6:5O5OPWY]5^5^2\>22>BB	)S!! 	Qy||H||F++7xH-//O$,LL$9$9$?RO!'/||J'?'?'E2O$*2,,}*E*E*KO')1k)B)B)KeO&PXP\P\]gPhPhpLLLLx
7KLLLLnp $ (0||J'?'?O$ <<00eeee8TcKdeeee )
 $,<<#7#7O 577G!+G#/G .G))++ v!?=UUV]^^x''!++BB(/BBBBGGG	              -	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s8   E5H26AHH2H	H2!H	"H22H69H6c                 0    t                      }| |_        |S r   )rH   r   )r   r  s     r   r  zKaggleApi._new_license  s    r   c                 >    t                      }| |_        ||_        |S r   )rI   r'  r  )r   r  us      r   r  zKaggleApi._new_collaborator  s     !!
r   c                    |                      ||          \  }}}t          j                            |          st          j        |           |                                 5 }t                      }||_        ||_        |j	        j
                            |          }|j        rt          |j                  	 ddd           n# 1 swxY w Y   t          j                            || j                  }	t!          |	d          5 }
|
                    |                    |j                             ddd           n# 1 swxY w Y   |	S )zDownloads the metadata for a dataset.

        Args:
            dataset: The dataset to download the metadata for.
            path: The path to download the metadata to.

        Returns:
            The path to the downloaded metadata file.
        Nr   )r  r   r   r   r   r  r=   r  r  r  r  get_dataset_metadatar  r   r   DATASET_METADATA_FILEr   writeto_jsonr  )r   r  r   r  r  r  r0  r  r  r  r   s              r   dataset_metadatazKaggleApi.dataset_metadata  s    6:5O5OPWY]5^5^2\>w~~n-- 	(K'''%%'' 	86244G!+G#/G 9NNwWWH% 8 67778	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 GLL1KLL	)S!! 	5QGGH$$X]33444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 s%   "ACC
C
.E  EEc                     |p|}|r6t          d           |                     ||           t          d           dS |                     ||          }t          d|z              dS )a:  Downloads or updates the metadata for a dataset.

        Args:
            dataset: The dataset to download the metadata for.
            path: The path to download the metadata to.
            update: Whether to update the metadata or not.
            dataset_opt: An alternative to providing a dataset.
        zupdating dataset metadataz%successfully updated dataset metadatazDownloaded metadata to N)r   r  r  )r   r  r   updatedataset_optr  s         r   dataset_metadata_clizKaggleApi.dataset_metadata_cli  s     ([ 	9-...(($7779:::::--gt<<I+i788888r   c                 x   |t          d          |                     |          \  }}}|                                 5 }t                      }||_        ||_        |rt          |          nd|_        ||_        ||_	        |j
        j                            |          }	|	cddd           S # 1 swxY w Y   dS )zLists files for a dataset.

        Args:
            dataset: The string identifier of the dataset, in the format [owner]/[dataset-name].
            page_token: The page token for pagination.
            page_size: The number of items per page.
        Nr  )r  split_dataset_stringr  r4   r  r  r   dataset_version_numberrb  ra  r  r  list_dataset_files)
r   r  rb  ra  r  r  r  r0  r  r  s
             r   dataset_list_fileszKaggleApi.dataset_list_files  s	    ?:;;;;?;T;TU\;];]8
L"8%%'' 	6022G!+G#/G Lb-lS1G-H-H-HhlG*!+G )G9LLWUUH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A#B//B36B3c                    |p|}|                      |||          }|r|j        rt          |j                   dS |j        }|r"t          d                    |                     g d}t
          j        t
          _        |r|                     |j	        |           dS | 
                    |j	        |           dS t          d           dS )a  A wrapper for dataset_list_files for the client.

        Args:
            dataset: The string identifier of the dataset, in the format [owner]/[dataset-name].
            dataset_opt: An alternative option to providing a dataset.
            csv_display: If True, print comma-separated values instead of a table.
            page_token: The page token for pagination.
            page_size: The number of items per page.
        rs  r  r  N)r  r  r   r  r  r>   r  r  rt  r  rv  )	r   r  r  rq  rb  ra  r  r  fieldss	            r   dataset_list_files_cliz KaggleApi.dataset_list_files_cli  s     ([((*iHH 	$# ;f*+++++"("8" J077HHIII999&4&@# ;NN6<88888$$V\6:::::"#####r   r  c                    |t          d          d|v r;|                     |           |                    d          }|d         }|d         }n|                     | j                  }|}|                                 5 }t                      }||_        ||_        |j	        j
                            |          }|j        j                                        cddd           S # 1 swxY w Y   dS )zGets the status of a dataset.

        Args:
            dataset (str): The string identifier of the dataset, in the format [owner]/[dataset-name].

        Returns:
            str: The status of the dataset.
        Nr  r  r   r   )r  r  r   r  r  r  r5   r  r  r  r  get_dataset_statusr|  r   r  )r   r  r  r  r  r0  r  r  s           r   dataset_statuszKaggleApi.dataset_status  s/    ?:;;;'>>((111"==--L%aJ'?LL..t/DEEJ"L%%'' 	06022G!+G#/G 9LLWUUH?'--//	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s   AC''C+.C+c                 4    |p|}|                      |          S )zA wrapper for client for dataset_status, with additional dataset_opt to
        get the status of a dataset from the API.

        Args:
            dataset_opt: an alternative to dataset
        )r  )r   r  r  s      r   dataset_status_clizKaggleApi.dataset_status_cli  s"     ([""7+++r   c                 \   d|v r/|                      |           |                     |          \  }}}	n|                     | j                  }|}d}	||                     d||          }
n|}
|                     |||	|           |                                 5 }t                      }||_        ||_	        |	rt          |	          nd|_        ||_        |j        j                            |          }ddd           n# 1 swxY w Y   |j        j        }t$          j                            |
|                    d          d                             d          d                   }|s|                     |||          r)|                     || |j                    ||            dS dS )	a  Download a single file for a dataset.

        Args:
            dataset: the string identifier of the dataset in format [owner]/[dataset-name]
            file_name: the dataset configuration file
            path: if defined, download to this location
            force: force the download if the file already exists (default False)
            quiet: suppress verbose output (default is True)
            licenses: a list of license names, e.g. ['CC0-1.0']
        r  Nr  r  r   r7  TF)r  r  r  r  r  _print_dataset_url_and_licenser  r6   r  r  r   r  rx  r  r  download_datasetr  r  r   r   r   r   r  r  r  )r   r  rx  r   r)  r  r  r  r  r  r  r0  r  r  r  r  s                   r   dataset_download_filezKaggleApi.dataset_download_file  s    '>>((111?C?X?XY`?a?a<J&<&<..t/DEEJ"L%)"<!:::zS_``NN!N++JF\^fggg%%'' 	T6/11G!+G#/G Lb-lS1G-H-H-HhlG* )G9JJ7SSH	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T "',,~syy~~a/@/F/Fs/K/KB/OPP 	D((7EBB 	x2D&2D2F2FSXyYYY45s   ADDDc                    |t          d          |                     |          \  }}}	||                     d||          }
n|}
|                     |||	|           |                                 5 }t                      }||_        ||_        |	rt          |	          nd|_	        |j
        j                            |          }ddd           n# 1 swxY w Y   t          j                            |
|dz             }|s|                     |||          r*|                     || |j                    ||            d}nd}|rt          j                            |
|dz             }|r	 t'          j        |          5 }|                    |
           ddd           n# 1 swxY w Y   nf# t&          j        $ r}t          d| d          d}~wt.          $ r t/          d| d	          t0          $ r}t3          d
| d          d}~ww xY w	 t          j        |           dS # t6          $ r}t9          d|z             Y d}~dS d}~ww xY wdS dS )a  Downloads all files for a dataset.

        Args:
            dataset: The string identifier of the dataset, in the format [owner]/[dataset-name].
            path: The path to download the dataset to.
            force: Force the download if the file already exists (default is False).
            quiet: Suppress verbose output (default is True).
            unzip: If True, unzip files upon download (default is False).
            licenses: A list of license names, e.g. ['CC-BY-SA-4.0'].
        Nr  r  r  TFz	The file zk is corrupted or not a valid zip file. Please report this issue at https://www.github.com/kaggle/kaggle-apizT was not found. Please report this issue at https://www.github.com/kaggle/kaggle-apizAn unexpected error occurred: zF. Please report this issue at https://www.github.com/kaggle/kaggle-apiz!Could not delete zip file, got %s)r  r  r  r   r  r6   r  r  r   r  r  r  r!  r   r   r   r  r  r  zipfileZipFile
extractall
BadZipFiler	  r   RuntimeErrorr   r   r   )r   r  r   r)  r  unzipr  r  r  r  r  r0  r  r  r  
downloadedzr   s                     r   dataset_download_filesz KaggleApi.dataset_download_filesC  s    ?:;;;;?;T;TU\;];]8
L"8<!:::zS_``NN!N++JF\^fggg%%'' 	T6/11G!+G#/G Lb-lS1G-H-H-HhlG*9JJ7SSH	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T ',,~|f/DEE 	D((7EBB 	x2D&2D2F2FSXyYYYJJJ 	Cgll><&3HIIG C 11 5Q^4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5)   $_G _ _ _   )   +_G _ _ _   !   &_ _ _ _  CIg&&&&& C C C=ABBBBBBBBBC1	C 	CC Css   3ACCC/F1 F%F1 %F))F1 ,F)-F1 1H G)H<HHH. .
I8IIc                     |t          d|d|           nt          d|d|d|           t          |          dk    r't          dd                    |          z             d S d S )Nz-Dataset URL: https://www.kaggle.com/datasets/r  z
/versions/r   zLicense(s): %s,)r   r  r   )r   r  r  r  r  s        r   r   z(KaggleApi._print_dataset_url_and_license  s    !)E***VbVbcddddE::|||-C-CE  
 x==1"chhx&8&89::::: r   c                    |p|}|                      |          \  }}	}
t                      }||_        |	|_        |                                 5 }|j        j                            |          }|j        rt          |j                  |j
        }ddd           n# 1 swxY w Y   |r|j        r|j        }d |D             }ndg}||                     ||||||           dS |                     ||||||           dS )a  A client wrapper for dataset_download_files and dataset_download_file.

        This method is a client wrapper for downloading either a specific file
        (when file_name is provided) or all files for a dataset.

        Args:
            dataset: The string identifier of the dataset, in the format [owner]/[dataset-name].
            dataset_opt: An alternative option to providing a dataset.
            file_name: The dataset configuration file.
            path: The path to download the dataset to.
            force: Force the download if the file already exists (default is False).
            quiet: Suppress verbose output (default is False).
            unzip: If True, unzip files upon download (default is False).
        Nc                 *    g | ]}|j         	|j         S r   r   )r  license_objs     r   r  z2KaggleApi.dataset_download_cli.<locals>.<listcomp>  s#    ]]][KL\](]]]r   zSError retrieving license. Please visit the Dataset URL to view license information.)r   r)  r)  r  r  )r   r)  r  r  )r  r=   r  r  r  r  r  r	  r  r   r  r  r,  r"  )r   r  r  rx  r   r)  r)  r  r  r  r   r  r0  r  r  license_objsr  s                    r   dataset_download_clizKaggleApi.dataset_download_cli  su   " ([&*&?&?&H&H#
L!.00'+%%'' 	%69NNwWWH% 8 6777}H		% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%  	o) 	o#,L]]L]]]HHmnH''d%u\alt'uuuuu&&w	EY^iq&rrrrrs   ABB #B 	blob_typeupload_contextc                    t           j                            |          }t           j                            |          }t	          t           j                            |                    }t                      }||_        ||_        ||_	        ||_
        |                    ||          }	t          d| j                  D ]}
|	j        r|	c S |	j        s|                                 5 }|j        j        j        } |                     |          |	j                  }|	                    t/          t0          |                     ddd           n# 1 swxY w Y   t/          t0          |	j                  }|                     ||j        ||	j                  }|t6          j        k    r|t6          j        k    r|	                                  |	                                }|S )a  Uploads a file.

        Args:
            path (str): The complete path to the file to upload.
            quiet (bool): Suppress verbose output (default is False).
            blob_type (ApiBlobType): The entity to which the file/blob refers.
            upload_context (ResumableUploadContext): The context for resumable uploads.

        Returns:
            Union[ResumableFileUpload, str, None]: A ResumableFileUpload object, a string, or None.
        r   N)resume) r   r   r  r  r   r  r   r  r   r  r  r   r  MAX_UPLOAD_RESUME_ATTEMPTSr   r   r  blobsblob_api_clientstart_blob_uploadr  r   r   rz   r   r   r  r   
INCOMPLETEr  r   r   )r   r   r  r4  r5  rx  r  r  r   r   r  r0  methodr   upload_responseupload_resultr  s                    r   _upload_blobzKaggleApi._upload_blob  s    G$$T**	..&)"'*:*:4*@*@&A&A#$=$?$?!)2!&)2!&3A!0@[!=$>>tE^__q$9:: 	 	A* #"""") o--// o6#\9KF1H1H1HIn1o1o.006PRl1m1mnnno o o o o o o o o o o o o o o
 ##={?effO 007QSXalaw0xxM 5 @@@ 5 >>>,,...!++--s   )AEE	E	skipfolderversion_notesconvert_to_csvdelete_old_versionsdir_modec                    t           j                            |          st          d|z             |                     |          }t          |          5 }t          j        |          }	ddd           n# 1 swxY w Y   |                     |	dd          }
|                     |	dd          }|
s|st          d          |
r(|
| j	        | j
                 dz   k    rt          d          |	                    d          }|r5t          |          d	k     st          |          d
k    rt          d          |	                    d          }|r|                     ||           |	                    d          }g }t          t          t                    |                     |	d|                    }t#                      }||_        ||_        ||_        g |_        ||_        ||_        |                                 5 }|rGt3                      }t5          t          t           |                    |_        |j        j        j        }n|t          t           |
          }|                     |           |                     d          }|d         }|d         }tC                      }||_"        ||_#        |j        j        j$        }||_%        tM                      5 }| '                    |||tP          j)        |||           t          tT           | +                    |          |                    }|cddd           cddd           S # 1 swxY w Y   	 ddd           dS # 1 swxY w Y   dS )a  Creates a new version of a dataset.

        Args:
            folder (str): The folder containing the dataset configuration and data files.
            version_notes (str): The notes to add for the version.
            quiet (bool): Suppress verbose output (default is False).
            convert_to_csv (bool): If True, convert data to CSV on upload.
            delete_old_versions (bool): If True, delete old versions of the dataset.
            dir_mode (str): What to do with directories: "skip" - ignore; "zip" - compress and upload.

        Returns:
            ApiCreateDatasetResponse: An ApiCreateDatasetResponse object.
        Invalid folder: Nr  id_no,ID or slug must be specified in the metadata/INSERT_SLUG_HERE<Default slug detected, please change values before uploadingr  r\  P   4Subtitle length must be between 20 and 80 characters	resourcesr{  r  r  r   r   ),r   r   isdirr  r  r   r   r   get_or_defaultr1  r  r  r  validate_resourcesrz   r|   r   r8   rC  r  r{  r  category_idsrE  r  r9   r   r  r  r  create_dataset_version_by_idr  r   r:   r  r  create_dataset_versionbodyr   upload_filesr   DATASETr@   r  )r   rB  rC  r  rD  rE  rF  r  r   	meta_datars  rI  r  rO  r{  defaultsr  rV  r0  r  ry  r  ref_listr  r  r5  r  s                              r   dataset_create_versionz KaggleApi.dataset_create_version  s   , w}}V$$ 	:/&8999226::	 )__ 	%	!I	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%!!)T488##Iw== 	]5 	]KLLL 	]SD.t/DEH[[[[[\\\==,, 	UX++s8}}r/A/ASTTTMM+..	 	7##FI666mmM22 S	4#6#6y*h#W#WXX133* &
$#6 %%'' 	 6 T688  !c5!1!122
 /<YsC..,,W555"==--%a[
'{8::%/"'3$ /<SGL'))  ^!!$	6;;NP^`egoppp 8:R$//':R:RSZ:[:[\\             %	  	  	  	  	  	  	  	 $                 %	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 sJ   A77A;>A;>CM#AM
1M#
M	M#M	M##M'*M'c                    |pt          j                    }|                     ||||||          }|t          d           dS |j        r&t          dt          |j                  z              dS |j                                        dk    rt          d|j        z              dS t          d|j	        z              dS )a  A client wrapper for creating a new version of a dataset.

        Args:
            folder: The folder containing the dataset configuration and data files.
            version_notes: The notes to add for the version.
            quiet: Suppress verbose output (default is False).
            convert_to_csv: If True, convert data to CSV on upload.
            delete_old_versions: If True, delete old versions of the dataset.
            dir_mode: What to do with directories: "skip" - ignore; "zip" - compress and upload.
        )r  rD  rE  rF  Nz3Dataset version creation error: See previous outputHThe following are not valid tags and could not be added to the dataset: okz;Dataset version is being created. Please check progress at z Dataset version creation error: )
r   r  r\  r   invalidTagsr   r|  r  r  error)r   rB  rC  r  rD  rE  rF  r  s           r   dataset_create_version_cliz$KaggleApi.dataset_create_version_cli6	  s     &29;;,,) 3 - 
 
 >GHHHHH 	E^f())*     ]  ""d**ORXR\\]]]]]4v|CDDDDDr   r  r  
no_confirmc                 j   |s|                      | j                  }|s,|                     d| d|           st          d           dS |                                 5 }t                      }||_        ||_        |j        j	        
                    |           ddd           dS # 1 swxY w Y   dS )a  Deletes a dataset.

        Args:
            owner_slug (str): The owner of the dataset.
            dataset_slug (str): The slug of the dataset.
            no_confirm (bool): If True, skip confirmation (default is False).

        Returns:
            None:
        zdelete the dataset: r  Deletion cancelledN)r  r  confirmationr   r  rB   r  r  r  r  delete_dataset)r   r  r  rc  r0  r  s         r   dataset_deletezKaggleApi.dataset_deleteY	  s      	F..t/DEEJ 	$$%WJ%W%W%W%WXX *+++%%'' 	G6-//G!+G#/G O.==gFFF		G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs   <B((B,/B,c                    |t          d          d|vrt          d          |                    d          \  }}|s)|                     d|           st          d           dS |                                 5 }t                      }||_        ||_        |j        j	        
                    |           t          d| d           ddd           dS # 1 swxY w Y   dS )	zDeletes a kernel.

        Args:
            kernel (str): The string identifier of the kernel, in the format [owner]/[kernel-name].
            no_confirm (bool): If True, skip confirmation (default is False).

        Returns:
            None:
        NA kernel must be specifiedr  z.Kernel must be in format [owner]/[kernel-name]zdelete the kernel: re  zKernel z deleted successfully)r  r   rf  r   r  rS   	user_namer  kernelskernels_api_clientdelete_kernel)r   rz  rc  r  r  r0  r  s          r   kernels_deletezKaggleApi.kernels_deletes	  sD    >9:::fMNNN"(,,s"3"3
K 	$$%C6%C%CDD *+++%%'' 	;6,..G *G"-GN-;;GDDD9F999:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   <ACCCc                 2    |                      ||           dS )a  A client wrapper for deleting a kernel.

        Args:
            kernel (str): The string identifier of the kernel, in the format [owner]/[kernel-name].
            no_confirm (bool): If True, skip confirmation (default is False).

        Returns:
            None:
        N)ro  )r   rz  rc  s      r   kernels_delete_clizKaggleApi.kernels_delete_cli	  s      	FJ/////r   c                     |t          d          |                     |          \  }}}|                     |||           t          d| d           dS )a*  A client wrapper for deleting a dataset.

        Args:
            dataset (str): The string identifier of the dataset, in the format [owner]/[dataset-name].
            no_confirm (bool): If True, automatically confirm the deletion (default is False).

        Returns:
            None:
        Nr  z	Dataset "z" deleted successfully.)r  r  rh  r   )r   r  rc  r  r  r   s         r   dataset_delete_clizKaggleApi.dataset_delete_cli	  sj     ?:;;;&*&?&?&H&H#
L!JjAAA:':::;;;;;r   c                    t           j                            |          st          d|z             | j        | j                 dz   }g }ddi}|                    |           d||d}t           j                            || j                  }t          |d          5 }t          j        ||d	           d
d
d
           n# 1 swxY w Y   t          d|z              |S )zInitializes a folder with a dataset configuration (metadata) file.

        Args:
            folder (str): The folder in which to initialize the metadata file.

        Returns:
            str: The path to the newly created metadata file.
        rH  rK  r   zCC0-1.0INSERT_TITLE_HERE)r  r  r  r   rs   r   Nz"Data package template written to: )r   r   rP  r  r1  r  r   r   r
  r   r   r   r   )r   rB  rs  r  default_licenserY  r  r   s           r   dataset_initializezKaggleApi.dataset_initialize	  s!    w}}V$$ 	:/&8999 !67:MM!9-(((1(SS	GLL)CDD	)S!! 	.QIi1----	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	2Y>???s   CCCc                 Z    |pt          j                    }|                     |           d S r   )r   r  rw  r   rB  s     r   dataset_initialize_cliz KaggleApi.dataset_initialize_cli	  s,    &29;;'''''r   publicc           
      v	   t           j                            |          st          d|z             |                     |          }t          |          5 }t          j        |          }ddd           n# 1 swxY w Y   t          t          | 
                    |d                    }	t          t          | 
                    |d                    }
t          t          t          t          t          f                  | 
                    |d                    }|	                    d          }|d         }|d         }|	| j        | j                 d	z   k    rt          d
          |
dk    rt          d          t!          |          dk    rt          d          t!          |          dk     st!          |          dk    rt          d          t!          |
          dk     st!          |
          dk    rt          d          |                    d          }|r|                     ||           | 
                    |d         d          }|                    d          }t          t          t                   |                     |dg                     }|                    d          }|r5t!          |          dk     st!          |          dk    rt          d          d}	 |                     |	           n# t*          $ r}d}Y d}~nd}~ww xY w|r"t-                      }d|_        d|
 d|_        |S t3                      }|
|_        ||_        ||_        ||_        ||_        ||_        g |_         | |_!        ||_"        tG                      5 }| $                    |||tJ          j&        |||           | '                                5 }t3                      }|
|_        ||_        ||_        ||_        ||_        ||_        |j         |_         | |_!        ||_"         | (                    |j)        j*        j+                  |          }t          t,          |          }|j        dk    rd|_        |cddd           cddd           S # 1 swxY w Y   	 ddd           dS # 1 swxY w Y   dS ) a  Creates a new dataset.

        This is similar to creating a new version of a dataset, but it also
        requires additional metadata such as the license and owner.

        Args:
            folder (str): The folder from which to get the metadata file.
            public (bool): Whether the dataset should be public.
            quiet (bool): Suppress verbose output (default is False).
            convert_to_csv (bool): If True, convert data to comma-separated values.
            dir_mode (str): What to do with directories: "skip" - ignore; "zip" - compress and upload.

        Returns:
            ApiCreateDatasetResponse: An ApiCreateDatasetResponse object.
        rH  Nr  r  r  r  r   r   rK  rL  ru  =Default title detected, please change values before uploadingz"Please specify exactly one license   2   z4The dataset slug must be between 6 and 50 charactersz5The dataset title must be between 6 and 50 charactersrO  r   r{  r  r  r\  rM  rN  TFra  zThe requested title "z>" is already in use by a dataset. Please choose another title.r  ),r   r   rP  r  r  r   r   r   rz   r   get_or_failr|   r{   r   r1  r  r  r  rR  rQ  r  rw   r@   r|  ra  r7   r  r  r  r  r  r{  r  r  rS  r   rW  r   rX  r  r  r  r  create_dataset)r   rB  r{  r  rD  rF  r  r   rY  rs  r  r  r[  r  r  rO  r  r{  r  r  foundr   r  r  r5  r0  retry_requestr  r  s                                r   dataset_create_newzKaggleApi.dataset_create_new	  s_   . w}}V$$ 	:/&8999226::	 )__ 	%	!I	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%3((D99::S$**9g>>??T#s(^,d.>.>y*.U.UVV99S>>a[
{ $$T%:;>QQQQ[\\\'''\]]]x==AABBB|q  C$5$5$:$:STTTu::>>SZZ"__TUUUMM+..	 	7##FI666''V<<mmM22S	4#6#6y*b#Q#QRR==,, 	UX++s8}}r/A/ASTTT	$$$$ 	 	 	EEEEEE	 	+--D!DKvvvvDJK)++#'+#)!'Z'#%% 	gy&+:M~_dfnooo))++ v 7 9 9&+#%1"+5(-9*)1&,7)&-m#/5:(-5*]4??6?+M+\]]^kll6AA<2%%#'FL      	 	 	 	 	 	 	 	        	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sa   A77A;>A;*L   
L
LL:R.B)R<R.R	R.R	R..R25R2c                    |pt          j                    }|                     |||||          }|j        r$t	          dt          |j                  z              |j                                        dk    r4|rt	          d|j        z              dS t	          d|j        z              dS t	          d|j	        z              dS )a  A client wrapper for creating a new dataset.

        Args:
            folder: The folder from which to get the metadata file.
            public: Whether the dataset should be public.
            quiet: Suppress verbose output (default is False).
            convert_to_csv: If True, convert data to comma-separated values.
            dir_mode: What to do with directories: "skip" - ignore; "zip" - compress and upload.
        r^  r_  z?Your public Dataset is being created. Please check progress at z@Your private Dataset is being created. Please check progress at zDataset creation error: N)
r   r  r  r`  r   r   r|  r  r  ra  )r   rB  r{  r  rD  rF  r  s          r   dataset_create_new_cliz KaggleApi.dataset_create_new_cli2
  s     &29;;((PXYY 	]`cdjdv`w`ww   =  D(( jZ]c]gghhhhh[^d^hhiiiii,v|;<<<<<r      c           	         t           j                            |          }t           j                            |          st          j        |           t          |j        d                   }d}	d}
|j                            d          }|t          j	                    }n t          j
        |j        d         d          }t          j        |                                          }|s5t          dt           j                            |          z   dz   |z              t           j                            |          }d	|j        v o|j        d	         d
k    }|rx|rv|rtt           j                            |          }	d}
|st          d|	||	z
  fz             |j        d         }t'          j        |j        j        |j        dd|	fz  id          }t/          ||	ddd|          5 }t1          ||
          5 }t3          |          j        dk    r	 |                    |          }|sni|                    |           t          j        ||dz
  |dz
  f           t=          ||	|z             }	|                    tA          |                     n|!                    |          D ]n}|s ni|                    |           t          j        ||dz
  |dz
  f           t=          ||	|z             }	|                    tA          |                     oddd           n# 1 swxY w Y   |st          dd           t          j        |||f           ddd           dS # 1 swxY w Y   dS )a  Downloads a file to an output file, streaming in chunks.

        Args:
            response: The response object to download.
            outfile: The output file to which to download.
            http_client: The Kaggle HTTP client to use.
            quiet: Suppress verbose output (default is True).
            chunk_size: The size of the chunk to stream.
            resume: Whether to resume an existing download.
        Content-Lengthr   wbLast-ModifiedN%a, %d %b %Y %H:%M:%S %ZzDownloading z to zAccept-Rangesbytesabz.... resuming from %d bytes (%d bytes left) ...Rangez	bytes=%d-T)headersstreamB   )totalinitialunit
unit_scaleunit_divisordisableHTTPResponser   )times
r  )end)"r   r   dirnamer   r   r   r  r  r   nowstrptimer   mktime	timetupler   r  isfiler  historyr  r  r=  r  r   r   r  r   readr  utimeminr  r  iter_content)r   r  r  r  r  r7  
chunk_sizeoutpathr  	size_read	open_modelast_modifiedremote_dateremote_date_timestampfile_exists	resumablerequest_historypbaroutrG  s                       r   r  zKaggleApi.download_fileJ
  s-    '//'**w~~g&& 	!K   8#$4566		 (,,_== ",..KK"+H,<_,MOijjK $K,A,A,C,C D D 	Q.27#3#3G#<#<<vEOPPPgnnW--#x'77hH<L_<]ah<h	 	i 	K 	00II D!y(   '.q1O''. +"<=	  H icdY]glmmm 	Tqugy)) /S>>*n<</'}}Z88# "!		$1F1JLadeLe0fgggg$'i*.D$E$E	CII.../ " !) 5 5j A A / /# "!E		$1F1JLadeLe0fgggg$'i*.D$E$E	CII....%/ / / / / / / / / / / / / / /&  $d####HW%:<Q$RSSSS/	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	Ts7   &M&7D L#M&#L'	'M&*L'	+.M&&M*-M*parent_kernellanguagekernel_typeoutput_typec                    t          |          dk    rt          d          t          |          }|dk    rt          d          |dk    rd}|	r-|	| j        vr$t          dt          | j                  z             |
r-|
| j        vr$t          dt          | j                  z             |r-|| j        vr$t          dt          | j                  z             |ro|| j        vr$t          dt          | j                  z             |d	k    r|d
k    rt          d          |                     t          t          j	        |          }nt          j	        }| 
                    |           |                     |           d}|rd}|                     t          t          j        |          }|                                 5 }t                      }||_        ||_        ||_        |pd
|_        |	pd|_        |
pd|_        |pd|_        ||_        |pd
|_        |pd
|_        |pd
|_        |pd
|_        |j        j                            |          j        }|cddd           S # 1 swxY w Y   dS )a  Lists kernels based on a set of search criteria.

        Args:
            page (int): The page of results to return (default is 1).
            page_size (int): The number of results per page (default is 20).
            dataset (Optional[str]): If defined, filter to this dataset (default is None).
            competition (Optional[str]): If defined, filter to this competition (default is None).
            parent_kernel (Optional[str]): If defined, filter to those with the specified parent.
            search (Optional[str]): A custom search string to pass to the list query.
            mine (bool): If True, return personal kernels.
            user (Optional[str]): Filter results to a specific user.
            language (Optional[str]): The programming language of the kernel.
            kernel_type (Optional[str]): The type of kernel, one of valid_list_kernel_types.
            output_type (Optional[str]): The output type, one of valid_list_output_types.
            sort_by (Optional[str]): How to sort the result, see valid_list_sort_by for options.

        Returns:
            Union[List[ApiKernelMetadata, None], None]: A list of ApiKernelMetadata objects.
        r   r  Page size must be >= 1d   z.Invalid language specified. Valid options are z1Invalid kernel type specified. Valid options are z1Invalid output type specified. Valid options are z2Invalid sort by type specified. Valid options are rL  r  z/Cannot sort by relevance without a search term.everyoneprofilerC  N)r   r  valid_list_languagesr   valid_list_kernel_typesvalid_list_output_typesvalid_list_sort_byrV  rT   HOTNESSr  validate_kernel_stringrU   EVERYONEr  rK   r_  ra  r]  r  r  r  r  r^  r  r&  r  r`  rl  rm  list_kernels)r   r_  ra  r  r&  r  r`  r  r  r  r  r  r^  ro  r]  rm  r0  r  r  s                      r   kernels_listzKaggleApi.kernels_list
  s   D t99>>7888	NN	>>5666s??I 	p(AAAMPSTXTmPnPnnooo 	v;d.JJJPSVW[WsStSttuuu 	v;d.JJJPSVW[WsStSttuuu 	6d555 !UX[\`\sXtXt!tuuu+%%&B,, !RSSS**+>@S@[]deeKK-5K$$W---##M222 	E$$%8:M:VX]^^	%%'' 	6+--GGL )G%GM:2GL'05G"-"6G"-"6G)GO%mGO"-"3G$1$7RG!#\rGN<BN<]<j<j= =  #	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   BI((I,/I,c                     |                      ||||||||	|
|||          }g d}|r2|r|                     ||           dS |                     ||           dS t          d           dS )ak  A client wrapper for kernels_list.

        This method is a client wrapper for the kernels_list function.
        Please see the kernels_list function for a description of the arguments.

        Args:
            mine: If True, return personal kernels.
            page: The page of results to return (default is 1).
            page_size: The number of results per page (default is 20).
            search: A custom search string to pass to the list query.
            csv_display: If True, print comma-separated values instead of a table.
            parent: If defined, filter to those with the specified parent.
            competition: If defined, filter to this competition (default is None).
            dataset: If defined, filter to this dataset (default is None).
            user: Filter results to a specific user.
            language: The programming language of the kernel.
            kernel_type: The type of kernel, one of valid_list_kernel_types.
            output_type: The output type, one of valid_list_output_types.
            sort_by: How to sort the result, see valid_list_sort_by for options.
        )r_  ra  r`  r  r  r&  r  r  r  r  r  r^  )rs  r  r  lastRunTime
totalVotesz	Not foundN)r  rt  rv  r   )r   r  r_  ra  r`  rq  parentr&  r  r  r  r  r  r^  rl  r  s                   r   kernels_list_clizKaggleApi.kernels_list_cli
  s    H ### ## $ 
 
 IHH 	 2w/////  &11111+r   c                 D   |t          d          |                     |          \  }}}|                                 5 }t                      }||_        ||_        ||_        ||_        |j        j	        
                    |          cddd           S # 1 swxY w Y   dS )zLists files for a kernel.

        Args:
            kernel: The string identifier of the kernel, in the format [owner]/[kernel-name].
            page_token: The page token for pagination.
            page_size: The number of items per page.
        Nrj  )r  r  r  rL   r  rk  rb  ra  rl  rm  list_kernel_files)	r   rz  rb  ra  rk  r  kernel_version_numberr0  r  s	            r   kernels_list_fileszKaggleApi.kernels_list_files*  s     >9:::8<8Q8QRX8Y8Y5	; 5%%'' 	P6/11G"-G )G!+G )G>4FFwOO	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	Ps   A	BBBc                 4   |p|}|                      |||          }|t          d           dS |j        }|r"t          d                    |                     g d}|r|                     |j        |           dS |                     |j        |           dS )a  A client wrapper for kernel_list_files.

        Args:
            kernel: The string identifier of the kernel, in the format [owner]/[kernel-name].
            kernel_opt: An alternative option to providing a kernel.
            csv_display: If True, print comma-separated values instead of a table.
            page_token: The page token for pagination.
            page_size: The number of items per page.
        Nr  rs  r  )r  r   r  r  rt  r  rv  )	r   rz  
kernel_optrq  rb  ra  r  r  r  s	            r   kernels_list_files_cliz KaggleApi.kernels_list_files_cli>  s     %:((YGG>"###F . 	B(//@@AAA111 	3NN6<00000V\622222r   c                    t           j                            |          st          d|z             g }ddi}|                    |           t          t          |                     | j                            }|dz   dddd	                    d	 | j
        D                       z   d
z   dd	                    d | j        D                       z   d
z   ddddg g g g d}t           j        	                    || j                  }t          |d          5 }t          j        ||d           ddd           n# 1 swxY w Y   |S )a  Initializes a new kernel in a specified folder from a template.

        This method creates a new kernel in a specified folder from a template,
        including JSON metadata that is populated with values from the configuration.

        Args:
            folder (str): The path to the folder.

        Returns:
            str: The path to the newly created metadata file.
        rH  r   INSERT_SCRIPT_PATH_HEREz/INSERT_KERNEL_SLUG_HEREru  INSERT_CODE_FILE_PATH_HEREzPick one of: {r.  c              3      K   | ]}|V  d S r   r   r  xs     r   	<genexpr>z/KaggleApi.kernels_initialize.<locals>.<genexpr>p  s"      3^3^!A3^3^3^3^3^3^r   }c              3      K   | ]}|V  d S r   r   r  s     r   r  z/KaggleApi.kernels_initialize.<locals>.<genexpr>q  s"      6_6_Qq6_6_6_6_6_6_r   r9  r7  )r  r  	code_filer  r  r  
enable_gpu
enable_tpuenable_internetdataset_sourcescompetition_sourceskernel_sourcesmodel_sourcesr   rs   r   N)r   r   rP  r  r   rz   r   r  r  r   valid_push_language_typesvalid_push_kernel_typesKERNEL_METADATA_FILEr   r   r   )r   rB  rO  resourcer'  rY  r  r   s           r   kernels_initializezKaggleApi.kernels_initializeX  s    w}}V$$ 	:/&8999	56"""T2243HIIJJ77(5(3883^3^t?]3^3^3^+^+^^add+chh6_6_$B^6_6_6_._.__bee !!%!#% 7
 7
	 GLL)BCC	)S!! 	.QIi1----	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. s   D66D:=D:c                 ~    |pt          j                    }|                     |          }t          d|z              dS )zA client wrapper for kernels_initialize.

        If the folder is not provided, it defaults to the current working directory.

        Args:
            folder: The path to the folder (defaults to the current working directory).
        z%Kernel metadata template written to: N)r   r  r  r   r   rB  r  s      r   kernels_initialize_cliz KaggleApi.kernels_initialize_cli  sA     &29;;++F33	5	ABBBBBr   timeoutc                 @   t           j                            |          st          d|z             t           j                            || j                  }t           j                            |          st          dt          |          z             t          |          5 }t          j
        |          }ddd           n# 1 swxY w Y   |                     |dd          }|r5t          t          t          |                    dk     rt          d          |                     |dd          }|st          d	          t           j                            |t          t          |                    }t           j                            |          st          d
t          |          z             |                    d          }	|                    d          }
|	s|
st          d          |	r|                     |	           d|	v r|	                    d          d         }n|	}|rLt#          t          t          |                    }|                                |k    rt'          ddz             |                     |dd          }|| j        vr$t          dt          | j                  z             |                     |dd          }|| j        vr$t          dt          | j                  z             |dk    r|dk    rd}t          t,          t                   |                     |dg                     }|D ]}|                     |           t          t,          t                   |                     |dg                     }|D ]}|                     |           t          t,          t                   |                     |dg                     }|D ]}|                     |           |                     |dd          }|-|| j        vr$t          dt          | j                  z             t          |          5 }|                                }ddd           n# 1 swxY w Y   |dk    rt          j        |          }d|v r]|d         D ]T}d|v r|d          d!k    rg |d<   d"|v r9t9          |d"         t:                    rd                    |d"                   |d"<   Ut          j        |          }|                                 5 }tA                      }|
|_!        |	|_"        |                     |dd          |_#        ||_$        ||_%        ||_&        | '                    |d#d$          |_(        | '                    |d%d&          |_)        | '                    |d'd&          |_*        | '                    |d(d$          |_+        ||_,        |                     |d)g           |_-        ||_.        ||_/        |                     |d*g           |_0        ||_1        |                     |d+d          |_2        |rtg          |          |_4        |j5        j6        7                    |          }|cddd           S # 1 swxY w Y   dS ),a  Pushes a kernel to Kaggle.

        This method reads the metadata file and kernel files from a notebook,
        validates both, and uses the Kernel API to push the kernel to Kaggle.

        Args:
            folder (str): The path to the folder.
            timeout (Optional[str]): The maximum run time in seconds.

        Returns:
            ApiSaveKernelResponse: An ApiSaveKernelResponse object.
        rH  Metadata file not found: Nr     z&Title must be at least five charactersr  r  z/A source file must be specified in the metadatazSource file not found: r  rI  rJ  r  r   zYour kernel title does not resolve to the specified id. This may result in surprising behavior. We suggest making your title something that resolves to the specified id. See %s for more information on how slugs are determined.z,https://en.wikipedia.org/wiki/Clean_URL#Slugr  zFA valid language must be specified in the metadata. Valid options are r  zIA valid kernel type must be specified in the metadata. Valid options are r>  r@  r   r  r  r  docker_image_pinning_typez;If specified, the docker_image_pinning_type must be one of cellsoutputs	cell_typecoder  r  Tr  Fr  r  r  r  docker_image)8r   r   rP  r  r   r  r  r   r   r   r   rQ  r  rz   r  r  r   r   r  r   r  r  r|   r  validate_model_stringvalid_push_pinning_typesr  loads
isinstancelistdumpsr  rM   r  r  	new_titletextr  r  get_boolr  r  r  r  dataset_data_sourcescompetition_data_sourceskernel_data_sourcesmodel_data_sourcesrS  r  r  r   session_timeout_secondsrl  rm  save_kernel)r   rB  r  r  r   rY  r  	code_pathr  r  rI  r  as_slugr  r  r  r  r  r  docker_pinning_typescript_body	json_bodycellr0  r  r  s                             r   kernels_pushzKaggleApi.kernels_push  s\    w}}V$$ 	:/&8999GLL)BCC	w~~i(( 	K83y>>IJJJ)__ 	%	!I	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% ##Iw== 	GSc5))**Q..EFFF''	;CC	 	PNOOOGLLc9)=)=>>	w~~i(( 	I6YGHHH}}T""g&& 	ME 	MKLLL 	''---d{{"jjooa0" 	!$sE"2"233$$&&'114 7e	e   &&y*bAA4999!$T%C!D!DE  
 )))]BGGd:::!$T%A!B!BC  
 *$$[)@)@HtCy$*=*=iIZ\^*_*_``% 	1 	1F((0000d3i)<)<YHXZ\)])]^^$ 	0 	0F''////T#Y(;(;IXZ([([\\# 	/ 	/F&&v...."11)=XZ^__*/B$Jg/g/gPSVW[WtSuSuu   )__ 	#&&((K	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# *$$
;//I)##%g. A AD D((T+->&-H-H*,Y  4''JtH~t,L,L')+h)@)@X*Y//K%%'' 	6*,,GGJGL $ 3 3Iw M MG&GL'G"-G!%y,!M!MG!%y,!N!NG!%y,!N!NG&*mmI?PRV&W&WG#+:G(/3/B/B9Nceg/h/hG,*8G')6G&#'#6#6y*b#Q#QG 0CG-#'#6#6y.RV#W#WG  ?25g,,/.4n.O.[.[\c.d.dH/	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s7   $CC	C	Q44Q8;Q8"E$ZZZc                    |pt          j                    }|                     ||          }|t          d           dS |j        s|j        r$t          dt          |j                  z              |j        r$t          dt          |j                  z              |j        r$t          dt          |j                  z              |j	        r$t          dt          |j	                  z              |j
        r!t          d|j
        d|j                   dS t          d	|j        z             dS t          d
|j        z              dS )zA client wrapper for kernels_push.

        Args:
            folder: The path to the folder.
            timeout: The maximum run time in seconds.
        Nz&Kernel push error: see previous outputzGThe following are not valid tags and could not be added to the kernel: zRThe following are not valid dataset sources and could not be added to the kernel: zVThe following are not valid competition sources and could not be added to the kernel: zQThe following are not valid kernel sources and could not be added to the kernel: zKernel version z0 successfully pushed.  Please check progress at z@Kernel version successfully pushed.  Please check progress at %szKernel push error: )r   r  r  r   ra  r`  r   invalidDatasetSourcesinvalidCompetitionSourcesinvalidKernelSourcesr  r  )r   rB  r  r  s       r   kernels_push_clizKaggleApi.kernels_push_cli  s    &29;;""6733>:;;;;; 	8! &(+F,>(?(?@   + /14V5Q1R1RS   / 3589Y5Z5Z[   * /14V5P1Q1QR  
 # j(.(<(<(<fjjJ     [^d^hhiiiii'&,677777r   c                 b
   d}||7t           j                            t          j                    | j                  }n%t           j                            || j                  }t           j                            |          rit          |          5 }t          j        |          }|d         }d|v rt          d          t          d|z              	 ddd           n# 1 swxY w Y   d|v r;|                     |           |                    d          }|d         }	|d         }
n|                     | j                  }	|}
||                     d	|	|
          }n|}t           j                            |          st          j        |           |                                 5 }t%                      }|	|_        |
|_        |j        j                            |          }ddd           n# 1 swxY w Y   |j        }t           j                            |          r t           j                            |          }n|}t           j                            || j                  }t           j                            |          sP|j                                        }|j                                        }d}|r	|d
         }n`t           j                            |          rAt          |          5 }t          j        |          d
         }ddd           n# 1 swxY w Y   |r|dk    r_d}|dk    r-|dk    rd}nD|dk    rd}n;|dk    rd}n2|dk    rd}n)|dk    rd}n |dk    r|dk    rd}n|dk    rd}n|dk    rd}|j        |z   }|'t          d|d|d           t          d           d}t           j                            ||          }n!|}t           j                            |          }t          |d d!"          5 }|                     |j!                   ddd           n# 1 swxY w Y   |ri }|j"        }|j#        |d<   |j$        |d#<   |j%        |d$<   ||d
<   |j        |d%<   |j        |d&<   |j&        |d'<   |j'        |d(<   |j(        |d)<   |j)        |d*<   |j*        |d+<   |j+        |d,<   |j,        |d-<   |j-        |d.<   |j.        |d/<   |j/        |d0<   |j0        |d1<   t          |d           5 }t          j1        ||d23           ddd           n# 1 swxY w Y   |S |S )4a  Pulls a kernel to a specified path.

        This method pulls a kernel, including a metadata file (if metadata is True)
        and associated files, to a specified path.

        Args:
            kernel: The kernel to pull.
            path: The path to which to pull the files.
            metadata: If True, also pull the metadata.
            quiet: Suppress verbose output (default is True).
        Nr  INSERT_KERNEL_SLUG_HERErj  zUsing kernel r  r   r   rl  r  r  r=  r?  z.pyr   z.Rr@  z.RmdrD  z.sqlrE  z.jlr>  z.ipynbz.irnbz.ijlnbzUnknown language z + kernel type z5 - please report this on the kaggle-api github issueszISaving as a python file, even though this may not be the correct languagez	script.pyr   utf-8)encodingrI  r  r  r  r  r  r  r  r  r  r  r  r  r  machine_shapers   r   )2r   r   r   r  r  r   r   r   r   r  r   r  r   r  r  r  r   r  rN   rk  r  rl  rm  
get_kernelblobr  r  r  r  r  r  r  r  r  r  rs  r  r  r  r  r  r  rS  r  r  r   r  r  r  r   )r   rz  r   r  r  existing_metadataexisting_metadata_pathr   kernel_url_listr  r  r  r0  r  r  r  effective_dirmetadata_pathr  r  rx  	extensionscript_pathrG  server_metadatas                            r   kernels_pullzKaggleApi.kernels_pull=  s    !>|)+bikk4C\)])]&&)+dD<U)V)V&w~~455 8011 8Q(,	!%.t4F0F::()EFFFo677778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 &==''///$ll3//O(+J)!,KK..t/DEEJ K<!::9jR]^^NN!Nw~~n-- 	(K'''%%'' 	M6)++G *G"-G~8CCGLLH		M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M }7>>.)) 	+GOON;;MM*M]D4MNNw~~n-- +	9}**,,H*0022KI  :-k:		.. :-(( :A $	![ 9I: : : : : : : : : : : : : : :  2	-I I I 	(**8++$)		!S$(		![00$*		!X--$*		!W,,$)	 J..8++$,		!S$+		!W,,$,	 I	1	 9A;;;P   deee'	',,~yAAKK(K((88I+sW555 	!GGDK   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!  	D&/O(,DJ+.DM+1DM )D.7D"1"=D!0!;D!0!;D!0!;D&5&ED"#.;D&5&JD"#%4%HD!"*9*RD&'$3$FD!#2#?D $3$AD!mS)) -Q	$!,,,,- - - - - - - - - - - - - - - ! s[   AC  C$'C$)<G11G58G56LL!$L!P33P7:P7>T""T&)T&c                     |p|}|                      |||d          }|rt          d|z              dS t          d|z              dS )z Client wrapper for kernels_pull.F)r   r  r  z'Source code and metadata downloaded to zSource code downloaded to N)r   r   )r   rz  r  r   r  r  s         r   kernels_pull_clizKaggleApi.kernels_pull_cli  sf    %:**6xW\*]] 	A;nLMMMMM.?@@@@@r   c                    |t          d          d|v r;|                     |           |                    d          }|d         }|d         }n/t          t          |                     | j                            }|}||                     d||d          }n|}t          j	        
                    |          st          j        |           t          j	                            |          st          d          d}	|                                 5 }
t                      }||_        ||_        |
j        j                            |          }|j        }	ddd           n# 1 swxY w Y   g }|j        D ] }t          j	                            ||j                  }|                    |           t3          j        |j        d	
          }|s|                     |||          rt          j        t          j	                            |          d         d	           t;          |d          5 }|                    |j                   ddd           n# 1 swxY w Y   |stA          d|z             |j!        }|rt          j	                            ||dz             }|                    |           t;          |d          5 }|                    |           ddd           n# 1 swxY w Y   |stA          d|z             ||	fS )a   Retrieves the output for a specified kernel.

        Args:
            kernel (str): The kernel for which to retrieve the output.
            path (str): The path to which to pull the files.
            force (bool): If True, force an overwrite if the output already exists (default is False).
            quiet (bool): Suppress verbose output (default is True).

        Returns:
            Tuple[List[str], str]: A tuple containing a list of output files and a string indicating the response status.
        Nrj  r  r   r   rl  outputz3You must specify a directory for the kernels outputT)r  )exist_okr  zOutput file downloaded to %sz.logr   zKernel log downloaded to %s )"r  r  r   rz   r   r  r  r  r   r   r   r   rP  r  rO   rk  r  rl  rm  list_kernel_session_outputr  r  r   rx  r   r  r  r  r  r   r  contentr   log)r   rz  r   r)  r  r  r  r  
target_dirr   r0  r  r  outfilesr  r  download_responser  r(  s                      r   kernels_outputzKaggleApi.kernels_output  s    >9:::&==''///$ll3//O(+J)!,KKc4#8#89N#O#OPPJ K<66y*k[cddJJJw~~j)) 	$K
###w}}Z(( 	TRSSS%%'' 	-6799G *G"-G~8SST[\\H,E	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- N 		D 		DDgll:t~>>GOOG$$$ (TXd C C C D,,->OO DBGMM'2215EEEE'4(( 9CII/78889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 D87BCCCl 	@gll:{V/CDDGOOG$$$gs## s		#               @4w>???s7   AE##E'*E'1II	I	
K,,K03K0c                 p    |p|}|                      ||||          \  }}|rt          d|            dS dS )a5  A client wrapper for kernels_output.

        This method is a client wrapper for the kernels_output function.
        Please see the kernels_output function for a description of the arguments.

        Args:
            kernel: The kernel for which to retrieve the output.
            kernel_opt: An alternative option to providing a kernel.
            path: The path to which to pull the files.
            force: If True, force an overwrite if the output already exists (default is False).
            quiet: Suppress verbose output (default is False).
        zNext page token: N)r,  r   )r   rz  r  r   r)  r  r   r   s           r   kernels_output_clizKaggleApi.kernels_output_cli  sZ     %:((ueDD
E 	/-e--.....	/ 	/r   c                    |t          d          d|v r;|                     |           |                    d          }|d         }|d         }n|                     | j                  }|}|                                 5 }t                      }||_        ||_        |j	        j
                            |          cddd           S # 1 swxY w Y   dS )zGets the status of a kernel.

        Args:
            kernel: The kernel for which to get the status.

        Returns:
            The status of the kernel.
        Nrj  r  r   r   )r  r  r   r  r  r  rP   rk  r  rl  rm  get_kernel_session_status)r   rz  r  r  r  r0  r  s          r   kernels_statuszKaggleApi.kernels_status  s.    >9:::&==''///$ll3//O(+J)!,KK..t/DEEJ K%%'' 	X6688G *G"-G>4NNwWW		X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	Xs   ;C		CCc                     |p|}|                      |          }|j        }|j        }|r)t          |d|d           t          d|z             dS t          |d|d           dS )zA client wrapper for kernel_status.

        Args:
            kernel: The kernel for which to get the status.
            kernel_opt: An additional option from the client, if the kernel is not defined.
        z has status ""zFailure message: "%s"N)r1  r|  failure_messager   )r   rz  r  r  r|  ry  s         r   kernels_status_clizKaggleApi.kernels_status_cli7  s     %:&&v..* 	;&&&&&&9:::)G344444&&&&&&9:::::r   modelc                 P   |                      |          \  }}|                                 5 }t                      }t          t          |          |_        ||_        t          t          |j        j	        
                    |                    cddd           S # 1 swxY w Y   dS )zGets a model.

        Args:
            model (str): The string identifier of the model, in the format [owner]/[model-name].

        Returns:
            ApiModel: An ApiModel object.
        N)split_model_stringr  rX   rz   r   r  
model_slugre   modelsmodel_api_client	get_model)r   r6  r  r9  r0  r  s         r   	model_getzKaggleApi.model_getH  s     "&!8!8!?!?
J%%'' 	U6(**G!%c:!6!6G!+G&-"@"J"J7"S"STT		U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	Us   A!BB"Bc                 J   |                      |          }||                     |           dS t          j                            || j                  }i }|j        |d<   |j                            d          }|d         |d<   |d         |d<   |j	        |d<   |j
        |d	<   |j        |d
<   |j        |d<   |j        |d<   t          |d          5 }t          j        ||d           ddd           n# 1 swxY w Y   t#          d                    |                     dS )ac  A client wrapper for model_get.

        This method is a client wrapper for the model_get function, with an
        additional option to get a model from the API.

        Args:
            model: The string identifier of the model, in the format [owner]/[model-name].
            folder: The folder in which to download the model metadata file.
        Nr  r  r   	ownerSlugr   r  r  r  r  r{  r  r   rs   r   Metadata file written to {})r=  	print_objr   r   r   MODEL_METADATA_FILEr  rs  r   r  r  r  r{  publish_timer   r   r   r   r  )r   r6  rB  r  rG  model_ref_splitr   s          r   model_get_clizKaggleApi.model_get_cliY  sd    u%%>NN5!!!!!VT-EFFIDDJ#iooc22O / 2D*1-DL!KDM$~D % 0D"'"3D"'"4Di%% -	$!,,,,- - - - - - - - - - - - - - -/66yAABBBBBs   C66C:=C:ownerc                 f   t           j        }|rI|| j        vr$t          dt	          | j                  z             |                     t           ||          }t          |          dk    rt          d          |                                 5 }t                      }||_	        |pd|_
        |pd|_        ||_        ||_        |j        j                            |          }	|	j        r't%          d                    |	j                             |	j        }
|
cddd           S # 1 swxY w Y   dS )a6  Returns a list of models.

        Args:
            sort_by (Optional[str]): How to sort the result, see valid_model_sort_bys for options.
            search (Optional[str]): A search term to use (default is empty string).
            owner (Optional[str]): The username or organization slug to which to filter the search.
            page_size (int): The page size to return (default is 20).
            page_token (Optional[str]): The page token for pagination.

        Returns:
            Union[List[ApiModel, None], None]: A list of ApiModel objects.
        r  r   r  r  rs  N)rn   LIST_MODELS_ORDER_BY_HOTNESSvalid_model_sort_bysr  r   rV  r   r  rV   r^  r`  rF  ra  rb  r:  r;  list_modelsr  r   r  )r   r^  r`  rF  ra  rb  ro  r0  r  r  r  s              r   
model_listzKaggleApi.model_listx  su   ( (D 	Td777 !PSVW[WpSqSq!qrrr**+<k7SSKy>>Q5666%%'' 	6*,,G)GO#\rGN!KRGM )G!+G}5AA'JJH' O,33H4LMMNNN3;?F	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   BD&&D*-D*c                     |                      |||||          }g d}|r2|r|                     ||           dS |                     ||           dS t          d           dS )a  A client wrapper for model_list.

        Args:
            sort_by: How to sort the result, see valid_model_sort_bys for options.
            search: A search term to use (default is empty string).
            owner: The username or organization slug to which to filter the search.
            page_size: The page size to return (default is 20).
            page_token: The page token for pagination.
            csv_display: If True, print comma-separated values instead of a table.
        r  zNo models foundN)rK  rt  rv  r   )	r   r^  r`  rF  ra  rb  rq  r:  r  s	            r   model_list_clizKaggleApi.model_list_cli  s     &%JOO=== 	% 1vv.....  00000#$$$$$r   c           	      j   t           j                            |          st          d|z             ddddddddd}t           j                            || j                  }t          |d	          5 }t          j        ||d
           ddd           n# 1 swxY w Y   t          d|z              |S )zInitializes a folder with a model configuration (metadata) file.

        Args:
            folder (str): The folder in which to initialize the metadata file.

        Returns:
            str: The path to the newly created metadata file.
        rH  INSERT_OWNER_SLUG_HEREru  INSERT_SLUG_HEREr  TzP# Model Summary

# Model Characteristics

# Data Overview

# Evaluation Results
)r?  r  r  r  r  r{  r  provenanceSourcesr   rs   r   NzModel template written to: )
r   r   rP  r  r   rB  r   r   r   r   r   rB  rY  r  r   s        r   model_initializezKaggleApi.model_initialize  s    w}}V$$ 	:/&8999 2(& !#
 
	" GLL)ABB	)S!! 	.QIi1----	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	+i7888s   2BBBc                 Z    |pt          j                    }|                     |           d S r   )r   r  rS  ry  s     r   model_initialize_clizKaggleApi.model_initialize_cli  s,    &29;;f%%%%%r   c           	      @   t           j                            |          st          d|z             |                     |          }t          |          5 }t          j        |          }ddd           n# 1 swxY w Y   |                     |d          }|                     |d          }|                     |d          }|	                    d          }|                     |d          }	| 
                    t          t          |                     |d                              }
|	                    d	          }|	                    d
          }|dk    rt          d          |dk    rt          d          |dk    rt          d          t          |	t                    st          d          |r|                     |           nd}|                                 5 }t#                      }t          t          |          |_        t          t          |          |_        t          t          |          |_        ||_        |	|_        |
|_        ||_        ||_        |j        j                            |          }|cddd           S # 1 swxY w Y   dS )zCreates a new model.

        Args:
            folder (str): The folder from which to get the metadata file.

        Returns:
            ApiCreateModelResponse: An ApiCreateModelResponse object.
        rH  Nr?  r  r  r  r  r{  r  rQ  rO  ADefault ownerSlug detected, please change values before uploadingru  r}  rP  rL  !model.isPrivate must be a boolean)r   r   rP  r  get_model_metadata_filer   r   r   r  r  sanitize_markdownrz   r   r  r   validate_dater  rW   r  r  r  r  r  r{  rC  provenance_sourcesr:  r;  create_model)r   rB  r  r   rY  r  r  r  r  r  r{  rC  r\  r0  r  r  s                   r   model_create_newzKaggleApi.model_create_new  s    w}}V$$ 	:/&89990088	 )__ 	%	!I	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%%%i==
	622  G44==,,%%i==
,,T#t7G7G	S`7a7a-b-bcc }}]33&]]+>?? 111`aaa'''\]]]%%%[\\\*d++ 	B@AAA 	 |,,,,L%%'' 	6+--G!%c:!6!6GT??GL e,,GM'G!+G"-G#/G );G&-3]-K-X-XY`-a-aF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s%   A77A;>A;&B JJJc                     |pt          j                    }|                     |          }|j        r/t	          d                    |j        |j                             dS t	          d|j        z              dS )zA client wrapper for creating a new model.

        Args:
            folder: The folder from which to get the metadata file.
        z%Your model was created. Id={}. Url={}zModel creation error: N)r   r  r^  r  r   r  r  ra  r   rB  r  s      r   model_create_new_clizKaggleApi.model_create_new_cli  sv     &29;;&&v..9 	;9@@FJWWXXXXX*V\9:::::r   c                    |                      |          \  }}|s5|                     d|           st          d           t                      S |                                 5 }t                      }t          t          |          |_        ||_	        |j
        j                            |          }|cddd           S # 1 swxY w Y   dS )a/  Deletes a model.

        Args:
            model (str): The string identifier of the model, in the format [owner]/[model-name].
            no_confirm (bool): If True, skip confirmation (default is False).

        Returns:
            ApiDeleteModelResponse: An ApiDeleteModelResponse object.
        zdelete the model re  N)r8  rf  r   rg   r  rY   rz   r   r  r9  r:  r;  delete_model)r   r6  rc  r  r9  r0  r  r  s           r   model_deletezKaggleApi.model_delete"  s    "&!8!8!?!?
J 	0$$%@%@%@AA 0*+++-///%%'' 	6+--G!%c:!6!6G!+G-3]-K-X-XY`-a-aF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   $ACCCc                     |                      ||          }|j        rt          d|j        z              dS t          d           dS )zA client wrapper for deleting a model.

        Args:
            model: The string identifier of the model, in the format [owner]/[model-name].
            no_confirm: If True, automatically confirm the deletion.
        zModel deletion error: zThe model was deleted.N)rd  ra  r   )r   r6  rc  r  s       r   model_delete_clizKaggleApi.model_delete_cli:  sT     ""5*55< 	,*V\9:::::*+++++r   c                 P   t           j                            |          st          d|z             |                     |          }t          |          5 }t          j        |          }ddd           n# 1 swxY w Y   |                     |d          }|                     |d          }| 	                    |dd          }| 	                    |dd          }| 	                    |dd          }	| 	                    |dd          }
| 	                    |d	d          }| 	                    |d
d          }|dk    rt          d          |dk    rt          d          |	dk    r$t          |	t                    st          d          |r|                     |           dg i}|dk    r|d                             d           |dk    r|d                             d           |	dk    r|d                             d           nd}	|
dk    r0|                     |
          }
|d                             d           |dk    r/t          |          dk    r|d                             d           nd}|dk    r/t          |          dk    r|d                             d           nd}|                                 5 }t#          j        |d                   }|                    t          j        |                    }t+                      }||_        ||_        ||_        ||_        |	|_        |
|_        ||_        ||_        t          |d                   dk    r|nd|_        |j        j         !                    |          cddd           S # 1 swxY w Y   dS )zlUpdates a model.

        Args:
            folder: The folder from which to get the metadata file.
        rH  Nr?  r  r  r  r  r{  r  rQ  rO  rW  rP  rL  rX  pathsTr   rC  r\  rh  )"r   r   rP  r  rY  r   r   r   r  rQ  r  r   r[  r   rZ  r  r  r   	FieldMaskFromJsonStringr  rZ   r  r9  r  r  r  r{  rC  r\  update_maskr:  r;  update_model)r   rB  r  r   rY  r  r  r  r  r  r{  rC  r\  rl  r0  fmr  s                    r   model_updatezKaggleApi.model_updateH  sS    w}}V$$ 	:/&89990088	 )__ 	%	!I	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%%%i==
	622##Iw==&&y*dCC((KFF
)))]DII**9mTJJ!00<OQUVV 111`aaa%%%[\\\jT&B&B@AAA 	-|,,, .5bMD== ''000t ''
333 ''4444J$00==K ''6664C$5$5$9$9 ''7777L%%#.@*A*AA*E*E ''(<====!%%%'' 	H6)G0DEEEB""4:k#:#:;;B+--G!+G!%G!GM'G!+G"-G#/G );G&(+K,@(A(AA(E(E""4G=1>>wGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hs%   A77A;>A;C	NN"Nc                     |pt          j                    }|                     |          }|j        r/t	          d                    |j        |j                             dS t	          d|j        z              dS )zA client wrapper for updating a model.

        Args:
            folder: The folder from which to get the metadata file.
        z%Your model was updated. Id={}. Url={}Model update error: N)r   r  ro  r  r   r  r  ra  r`  s      r   model_update_clizKaggleApi.model_update_cli  sv     &29;;""6**9 	99@@FJWWXXXXX(6<788888r   model_instancec                    |t          d          |                     |          \  }}}}|                                 5 }t                      }||_        ||_        |                     t          t          j        |          |_	        ||_
        |j        j                            |          }|cddd           S # 1 swxY w Y   dS )a	  Gets a model instance.

        Args:
            model_instance (str): The string identifier of the model instance, in the format [owner]/[model-name]/[framework]/[instance-slug].

        Returns:
            ApiModelInstance: An ApiModelInstance object.
        N"A model instance must be specified)r  split_model_instance_stringr  r[   r  r9  rV  rp   MODEL_FRAMEWORK_API	frameworkinstance_slugr:  r;  get_model_instance)	r   rs  r  r9  rx  ry  r0  r  r  s	            r   model_instance_getzKaggleApi.model_instance_get  s    !ABBB;?;[;[\j;k;k8
J	=%%'' 	6022G!+G!+G $ 0 0Acen o oG$1G!'-}'E'X'XY`'a'aF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s    A/B<<C C c                    |                      |          }||                     |           dS t          j                            || j                  }|                     |          \  }}}}|j        j        }|	                    d          sd|z   }|j
        j        }	|		                    d          sd|	z   }	|j        |||j        |                     |          |j        |j        |j        |j        |j        |j        |j        |                     |	          d}
|j        [d                    t/          t0          |j        j                  j        |j        j        |j        j        |j        j                  |
d<   |j        |
d<   t;          |d	          5 }t=          j        |
|d
           ddd           n# 1 swxY w Y   tA          d                    |                     dS )a&  A client wrapper for model_instance_get.

        Args:
            model_instance: The string identifier of the model instance, in the format
                [owner]/[model-name]/[framework]/[instance-slug].
            folder: The folder in which to download the model metadata file.
        NzModelFramework.ro   zModelInstanceType.)r  r?  	modelSluginstanceSlugrx  overviewusagelicenseNamefineTunabletrainingData	versionIdr  modelInstanceTypez{}/{}/{}/{}baseModelInstanceexternalBaseModelUrlr   rs   r   r@  )!r{  rA  r   r   r   MODEL_INSTANCE_METADATA_FILErv  rx  r   r  model_instance_typer  r  r[  r  r  r  fine_tunabletraining_data
version_idversion_numberbase_model_instance_informationr  rz   rq   rF  r9  ry  external_base_model_urlr   r   r   r   )r   rs  rB  mir  r  r9  rx  ry  	inst_typerG  r   s               r   model_instance_get_cliz KaggleApi.model_instance_get_cli  s&    $$^44>NN2VT-NOOI?C?_?_`n?o?o<J
I})I''(9:: :-	9	.3I''(;<< =09<	e'' "!11)<<K!! " 0]!#!2%)%9%9)%D%D D 1=,9,@,@ B HIIN6A6@6D	- -() ,.+ED'(i%% -	$!,,,,- - - - - - - - - - - - - - -/66yAABBBBBs   F==GGc                 r   t           j                            |          st          d|z             dddddddd	g d
ddd}t           j                            || j                  }t          |d          5 }t          j        ||d           ddd           n# 1 swxY w Y   t          d|z              |S )a   Initializes a folder with a model instance configuration (metadata) file.

        Args:
            folder (str): The folder in which to initialize the metadata file.

        Returns:
            str: The path to the newly created metadata file.
        rH  rO  INSERT_EXISTING_MODEL_SLUG_HEREINSERT_INSTANCE_SLUG_HEREINSERT_FRAMEWORK_HEREr  zl# Model Format

# Training Data

# Model Inputs

# Model Outputs

# Model Usage

# Fine-tuning

# Changelog

Apache 2.0FUnspecifiedr   )r?  r}  r~  rx  r  r  r  r  r  r  baseModelInstanceIdr  r   rs   r   Nz$Model Instance template written to: )
r   r   rP  r  r   r  r   r   r   r   rR  s        r   model_instance_initializez#KaggleApi.model_instance_initialize  s    w}}V$$ 	:/&8999 2:70 ( !.#$$&3
 
	6 GLL)JKK	)S!! 	.QIi1----	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	4y@AAAs   6BB!Bc                 Z    |pt          j                    }|                     |           d S r   )r   r  r  ry  s     r   model_instance_initialize_cliz'KaggleApi.model_instance_initialize_cli  s,    &29;;&&v.....r   c                    t           j                            |          st          d|z             |                     |          }t          |          5 }t          j        |          }ddd           n# 1 swxY w Y   |                     |d          }|                     |d          }|                     |d          }	|                     |d          }
| 	                    t          t          |                     |dd                              }| 	                    t          t          |                     |d	d                              }|                     |d
          }|                     |dd          }|                     |dg           }t          t          |                     |dd                    }t          t          |                     |dd                    }t          t          |                     |dd                    }|dk    rt          d          |dk    rt          d          |	dk    rt          d          |
dk    rt          d          |dk    rt          d          t          |t                    st          d          t          |t                    st          d          t!                      }|                     t$          t$          j        |
          |_        |	|_        ||_        ||_        ||_        ||_        ||_        |                     t6          t6          j        |          |_        ||_        ||_        g |_         | !                                5 }tE                      }||_#        ||_$        ||_%        |j&        j'        j(        }tS                      5 }| *                    |d|tV          j,        |||           t          tZ           | .                    |          |                    }|cddd           cddd           S # 1 swxY w Y   	 ddd           dS # 1 swxY w Y   dS )a  Creates a new model instance.

        Args:
            folder (str): The folder from which to get the metadata file.
            quiet (bool): Suppress verbose output (default is False).
            dir_mode (str): What to do with directories: "skip" - ignore; "zip" - compress and upload.

        Returns:
            ApiCreateModelResponse: An ApiCreateModelResponse object.
        rH  Nr?  r}  r~  rx  r  r  r  r  r  Fr  r  r  r  r  rO  rW  r  zADefault modelSlug detected, please change values before uploadingr  zDDefault instanceSlug detected, please change values before uploadingr  ADefault framework detected, please change values before uploadingzPlease specify a license+modelInstance.fineTunable must be a boolean)modelInstance.trainingData must be a list)/r   r   rP  r   get_model_instance_metadata_filer   r   r   r  rZ  rz   r   rQ  r  r   r  r]   rV  rp   rw  rx  ry  r  r  r  r  r  ro   MODEL_INSTANCE_TYPE_UNSPECIFIEDr  base_model_instancer  r  r  r\   r  r9  rV  r:  r;  create_model_instancer   rW  r   MODELrf   r  )r   rB  r  rF  r  r   rY  r  r9  ry  rx  r  r  r  r  r  r  r  r  rV  r0  r  ry  r5  r  s                            r   model_instance_createzKaggleApi.model_instance_create  s    w}}V$$ 	:/&899999&AA	 )__ 	%	!I	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%%%i==
%%i==
((NCC$$Y<<	))$sD4G4G	S]_a4b4b*c*cdd&&tC1D1DYPWY[1\1\']']^^''	=AA**9mUKK++I~rJJ"3(;(;IGZ\i(j(jkk"3(;(;IGZ\^(_(_``"&sD,?,?	Kace,f,f"g"g 111`aaa:::`aaa777cddd///`aaa27888,-- 	LJKKK-.. 	JHIII022))..:\^ghh* 
((*#'#3#30PRe$
 $
  $7 '>$
%%'' 		 6355G!+G!+GGLm4JG'))  ^!!$fk6GY^`hiii 68P8P8PQX8Y8YZZ             		  		  		  		  		  		  		  		                  		  		  		  		  		  		  		  		  		  		  		  		  		  		  		  		  		  		 sJ   A77A;>A;>AQAP2Q2P6	6Q9P6	:QQQc                     |pt          j                    }|                     |||          }|j        r/t	          d                    |j        |j                             dS t	          d|j        z              dS )a/  A client wrapper for creating a new model instance.

        Args:
            folder: The folder from which to get the metadata file.
            quiet: Suppress verbose output (default is False).
            dir_mode: What to do with directories: "skip" - ignore; "zip" - compress and upload.
        z.Your model instance was created. Id={}. Url={}zModel instance creation error: N)r   r  r  r  r   r  r  ra  )r   rB  r  rF  r  s        r   model_instance_create_cliz#KaggleApi.model_instance_create_clia  s}     &29;;++FE8DD9 	DBII&)U[U_``aaaaa3flBCCCCCr   c                     |t          d          |                     |          \  }}}}|s5|                     d|           st          d           t	                      S |                                 5 }t                      }||_        ||_        | 	                    t          t          j        |          |_        ||_        |j        j                            |          }	|	cddd           S # 1 swxY w Y   dS )af  Deletes a model instance.

        Args:
            model_instance (str): The string identifier of the model instance, in the format [owner]/[model-name]/[framework]/[instance-slug].
            no_confirm (bool): If True, skip confirmation (default is False).

        Returns:
            ApiDeleteModelResponse: An ApiDeleteModelResponse object.
        Nru  zdelete the variation re  )r  rv  rf  r   rg   r  r`   r  r9  rV  rp   rw  rx  ry  r:  r;  delete_model_instance)
r   rs  rc  r  r9  rx  ry  r0  r  r  s
             r   model_instance_deletezKaggleApi.model_instance_deleteq  sH    !ABBB;?;[;[\j;k;k8
J	= 	0$$%M^%M%MNN 0*+++-///%%'' 	6355G!+G!+G $ 0 0Acen o oG$1G!-3]-K-a-abi-j-jF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   7A/C33C7:C7c                     |                      ||          }t          |j                  dk    rt          d|j        z              dS t          d           dS )a!  A client wrapper for model_instance_delete.

        Args:
            model_instance: The string identifier of the model instance, in the format
                [owner]/[model-name]/[framework]/[instance-slug].
            no_confirm: If True, automatically confirm the deletion.
        r   zModel instance deletion error: zThe model instance was deleted.N)r  r  ra  r   )r   rs  rc  r  s       r   model_instance_delete_cliz#KaggleApi.model_instance_delete_cli  s_     ++NJGGv|q  3flBCCCCC344444r   c                    |t          d          |                     |           |                    d          }|\  }}}}	|                                 5 }
t	                      }||_        ||_        |                     t          t          j	        |          |_
        |	|_        ||_        ||_        |
j        j                            |          }|rQ|j        }|r"t%          d                    |                     t(                              |          cddd           S t%          d           t)          g dd          cddd           S # 1 swxY w Y   dS )a  Lists files for the current version of a model instance.

        Args:
            model_instance (str): The string identifier of the model instance, in the format [owner]/[model-name]/[framework]/[instance-slug].
            page_token (Union[str, None]): The token for pagination.
            page_size (int): The number of items per page.
            csv_display (bool): If True, print comma-separated values instead of a table.

        Returns:
            FileList: A FileList object.
        Nz"A model_instance must be specifiedr  rs  r  r  r  )r  validate_model_instance_stringr   r  r^   r  r9  rV  rp   rw  rx  ry  ra  rb  r:  r;  !list_model_instance_version_filesr  r   r  r  r!  )r   rs  rb  ra  rq  urlsr  r9  rx  ry  r0  r  r  r  s                 r   model_instance_fileszKaggleApi.model_instance_files  s    !ABBB++N;;;##C((=A:ZM%%'' 	D6=??G!+G!+G $ 0 0Acen o oG$1G! )G!+G}5WWX_``H D"*":" J077HHIII--h77	D 	D 	D 	D 	D 	D 	D 	D  &'''"r B BCC#	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds   CE& EEEc                     |                      ||||          }|rJ|j        E| j        }|r|                     |j        |           dS |                     |j        |           dS dS dS )a  A client wrapper for model_instance_files.

        Args:
            model_instance: The string identifier of the model instance, in the format
                [owner]/[model-name]/[framework]/[instance-slug].
            page_token: The token for pagination.
            page_size: The number of items per page.
            csv_display: If True, print comma-separated values instead of a table.
        rb  ra  rq  N)r  r  dataset_file_fieldsrt  rv  )r   rs  rb  ra  rq  r  r  s          r   model_instance_files_cliz"KaggleApi.model_instance_files_cli  s     **zYT_ + 
 
  	7fl.-F 7v|V44444  v66666	7 	7..r   c                     |                      |          \  }}|                                 5 }t                      }||_        ||_        ||_        ||_        |j        j        	                    |          cd d d            S # 1 swxY w Y   d S r   )
r8  r  rl   r  r9  ra  rb  r:  r;  list_model_instances)r   rs  ra  rb  r  r9  r0  r  s           r   model_instances_listzKaggleApi.model_instances_list  s    !%!8!8!H!H
J%%'' 	P6244G!+G!+G )G!+G=1FFwOO	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	Ps   A	BB
Bc                 P   |                      |||          }|j        r't          d                    |j                             |j        }|rH|r#|                     || j        | j                   d S |                     || j        | j                   d S t          d           d S )Nrs  zNo instances found)	r  r  r   r  	instancesrt  model_instance_fieldsmodel_instance_labelsrv  )r   rs  rq  ra  rb  r  r  s          r   model_instances_list_cliz"KaggleApi.model_instances_list_cli  s    ,,^Y
SS# 	K(//0HIIJJJ&	 	( dy$*DdF`aaaaa  D,FHbccccc&'''''r   c                 	   t           j                            |          st          d|z             |                     |          }t          |          5 }t          j        |          }ddd           n# 1 swxY w Y   |                     |d          }|                     |d          }|                     |d          }|                     |d          }t          t          |                     |dd                    }	t          t          |                     |d	d                    }
|                     |d
d          }|                     |dd          }|                     |dd          }|                     |dd          }|                     |dd          }|                     |dd          }|dk    rt          d          |dk    rt          d          |dk    rt          d          |dk    rt          d          |dk    r$t          |t                    st          d          |dk    r$t          |t                    st          d          |r&|                     t           t           j        |          }dg i}|	dk    r0|                     |	          }	|d                             d           |
dk    r0|                     |
          }
|d                             d	           |dk    r|d                             d
           nd}|dk    r|d                             d           |dk    r|d                             d           |dk    r|d                             d           |dk    r|d                             d           |dk    r|d                             d           |                                 5 }t+          j        |d                   }|                    t          j        |                    }t3                      }||_        ||_        |                     t8          t8          j        |          |_        ||_        |	|_         |
|_!        ||_"        ||_#        ||_$        ||_%        ||_&        ||_'        ||_(        tS          |d                   dk    r|nd|_(        |j*        j+        ,                    |          cddd           S # 1 swxY w Y   dS )zuUpdates a model instance.

        Args:
            folder: The folder from which to get the metadata file.
        rH  Nr?  r}  rx  r~  r  r  r  r  r  r  r  r  r  rO  rW  rP  zBDefault model slug detected, please change values before uploadingr  zEDefault instance slug detected, please change values before uploadingr  r  r  r  rh  r  ri  r   )-r   r   rP  r  r  r   r   r   r  rz   r   rQ  r  r   r  rV  ro   r  rZ  r   r  r   rj  rk  r  r_   r  r9  rp   rw  rx  ry  r  r  r  r  r  r  r  r  rl  r  r:  r;  update_model_instance)r   rB  r  r   rY  r  r9  rx  ry  r  r  r  r  r  r  r  r  rl  r0  rn  r  s                        r   model_instance_updatezKaggleApi.model_instance_update  s    w}}V$$ 	:/&899999&AA	 )__ 	%	!I	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%%%i==
%%i==
$$Y<<	((NCCT00JKKLLS$--i"EEFF**9mTJJ**9mTJJ++I~tLL"11)=PRVWW"11)=PRVWW"&"5"5iAWY]"^"^ 111`aaa+++abbb777deee///`aaa4
<(F(FJKKKD  M4)H)H HIII 	"&"2"2!#4#TVi# #
 .5bMt--h77H ''
333D==**511E ''0004 ''6666'L4 ''666D   ''777$&& ''(;<<<$&& ''(;<<<"d** ''(>???%%'' 	Q6)G0DEEEB""4:k#:#:;;B355G!+G!+G $ 0 0Acen o oG$1G!'G!GM#/G #/G $1G!*=G'*=G'.EG+"$G(+K,@(A(AA(E(E""4G=1GGPP%	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Qs%   A77A;>A;DS22S69S6c                    |pt          j                    }|                     |          }t          |j                  dk    r/t          d                    |j        |j                             dS t          d|j        z              dS )zA client wrapper for updating a model instance.

        Args:
            folder: The folder from which to get the metadata file.
        r   z.Your model instance was updated. Id={}. Url={}rq  N)	r   r  r  r  ra  r   r  r  r  r`  s      r   model_instance_update_cliz#KaggleApi.model_instance_update_cliG  s     &29;;++F33v|!!BII&)U[U_``aaaaa(6<788888r   c                    |                      |          \  }}}}	t                      }
||
_        ||
_        |                     t
          t
          j        |          |
_        |	|
_        t                      }||_
        ||
_        |                                 5 }|j        j        j        }t!                      5 }|                     |d|t$          j        |||           t)          t*           |                     |          |
                    }|cddd           cddd           S # 1 swxY w Y   	 ddd           dS # 1 swxY w Y   dS )an  Creates a new model instance version.

        Args:
            model_instance (str): The string identifier of the model instance, in the format [owner]/[model-name]/[framework]/[instance-slug].
            folder (str): The folder from which to get the metadata file.
            version_notes (str): The version notes to record for this new version.
            quiet (bool): Suppress verbose output (default is False).
            dir_mode (str): What to do with directories: "skip" - ignore; "zip" - compress and upload.

        Returns:
            ApiCreateModelResponse: An ApiCreateModelResponse object.
        N)rv  ra   r  r9  rV  rp   rw  rx  ry  rb   rC  rV  r  r:  r;  create_model_instance_versionr   rW  r   r  rz   rf   r  )r   rs  rB  rC  r  rF  r  r9  rx  ry  r  rV  r0  ry  r5  r  s                   r   model_instance_version_createz'KaggleApi.model_instance_version_createU  s    <@;[;[\j;k;k8
J	=688'' ,,^^=_ajkk -799*%%'' 	 6m4RG'))  ^!!$fk6GY^`hiii 68P8P8PQX8Y8YZZ             	  	  	  	  	  	  	  	                  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s7    E9AD*E*D.	.E1D.	2EE
Ec                     |                      |||||          }|j        dk    r)t          d                    |j                             dS t          d|j        z              dS )a"  A client wrapper for creating a new version of a model instance.

        Args:
            model_instance: The string identifier of the model instance, in the format
                [owner]/[model-name]/[framework]/[instance-slug].
            folder: The folder from which to get the metadata file.
            version_notes: The version notes to record for this new version.
            quiet: Suppress verbose output (default is False).
            dir_mode: What to do with directories: "skip" - ignore; "zip" - compress and upload.
        r   z/Your model instance version was created. Url={}z'Model instance version creation error: N)r  r  r   r  r  ra  )r   rs  rB  rC  r  rF  r  s          r   !model_instance_version_create_cliz+KaggleApi.model_instance_version_create_cliu  sm     33NFM[`bjkk9>>CJJ6:VVWWWWW;flJKKKKKr   model_instance_versionuntarc                    |t          d          |                     |           |                    d          }|d         }|d         }|d         }	|d         }
|d         }||                     d	|||	|
|          }n|}t	                      }||_        ||_        |                     t          t          j	        |	          |_
        |
|_        t          |          |_        |                                 5 }|j        j                            |          }ddd           n# 1 swxY w Y   t$          j                            ||d
z             }|s|                     |||          r*|                     || |j                    ||            d}nd}|r|r	 t1          j        |d          5 }|                    |           ddd           n# 1 swxY w Y   n"# t6          $ r}t          d|          d}~ww xY w	 t%          j        |           n)# t:          $ r}t=          d|z             Y d}~nd}~ww xY w|S )a  Downloads all files for a model instance version.

        Args:
            model_instance_version (str): The string identifier of the model instance version, in format [owner]/[model-name]/[framework]/[instance-slug]/[version-number].
            path (Optional[str]): The path to which to download the model instance version.
            force (bool): Force the download if the file already exists (default is False).
            quiet (bool): Suppress verbose output (default is True).
            untar (bool): If True, untar files upon download (default is False).

        Returns:
            str: The path to the downloaded file.
        N*A model_instance_version must be specifiedr  r   r   rs      r  r:  z.tar.gzTFzr:gz)modezSError extracting the tar.gz file, please report on www.github.com/kaggle/kaggle-apiz!Could not delete tar file, got %s)r  &validate_model_instance_version_stringr   r  rc   r  r9  rV  rp   rw  rx  ry  r   r  r  r:  r;  download_model_instance_versionr   r   r   r  r  r  tarfiler   r&  r   r   r   r   )r   r  r   r)  r  r  r  r  r9  rx  ry  r  r  r  r0  r  r  r*  tr   s                       r   model_instance_version_downloadz)KaggleApi.model_instance_version_download  s   ( ")IJJJ334JKKK%++C00!W
!W
G	Qa<!::*j)]N NN "N8::'' ,,^^=_ajkk -!$^!4!4%%'' 	_6}5UUV]^^H	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ 	_ ',,~zI/EFF 	D((7EBB 	x2D&2D2F2FSXyYYYJJJ 	C C gF;;; 5q^4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5    $prs  
CIg&&&& C C C=ABBBBBBBBCsf   9 D%%D),D)G! 3G	G! GG! GG! !
H +G;;H H 
H?#H::H?c                 6    |                      |||||          S )a1  A client wrapper for model_instance_version_download.

        Args:
            model_instance_version: The string identifier of the model instance version,
                in the format [owner]/[model-name]/[framework]/[instance-slug]/[version-number].
            path: The path to which to download the model instance version.
            force: Force the download if the file already exists (default is False).
            quiet: Suppress verbose output (default is False).
            untar: If True, untar files upon download (default is False).
        )r   r  r)  r  )r  )r   r  r   r  r)  r  s         r   #model_instance_version_download_cliz-KaggleApi.model_instance_version_download_cli  s,     33"U%u 4 
 
 	
r   c                    |t          d          |                     |           |                    d          }|\  }}}}	}
t                      }||_        ||_        |                     t          t          j        |          |_	        |	|_
        t          |
          |_        ||_        ||_        |                                 5 }|j        j                            |          }ddd           n# 1 swxY w Y   |r@|j        }|r"t)          d                    |                     t-          t.          |          S t)          d           dS )a\  Lists all files for a model instance version.

        Args:
            model_instance_version (str): The string identifier of the model instance version, in format [owner]/[model-name]/[framework]/[instance-slug]/[version-number].
            page_token (Union[str, None]): The token for pagination.
            page_size (int): The number of items per page.
            csv_display (bool): If True, print comma-separated values instead of a table.

        Returns:
            Union[ApiListModelInstanceVersionFilesResponse, None]: An ApiListModelInstanceVersionFilesResponse object or None.
        Nr  r  rs  r  )r  r  r   r^   r  r9  rV  rp   rw  rx  ry  r   r  ra  rb  r  r:  r;  r  r  r   r  rz   ri   )r   r  rb  ra  rq  r  r  r9  rx  ry  r  r  r0  r  r  s                  r   model_instance_version_filesz&KaggleApi.model_instance_version_files  s   $ ")IJJJ334JKKK%++C00MQJZM>9;;'' ,,^^=_ajkk -!$^!4!4%'%%'' 	a6}5WWX_``H	a 	a 	a 	a 	a 	a 	a 	a 	a 	a 	a 	a 	a 	a 	a  	&6O F,33ODDEEE@(KKK"###4s    C44C8;C8c                     |                      ||||          }|rM|j        Hg d}g d}|r|                     |j        ||           dS |                     |j        ||           dS dS dS )a  A client wrapper for model_instance_version_files.

        Args:
            model_instance_version: The string identifier of the model instance version,
                in the format [owner]/[model-name]/[framework]/[instance-slug]/[version-number].
            page_token: The token for pagination.
            page_size: The number of items per page.
            csv_display: If True, print comma-separated values instead of a table.
        r  N)r   r  creation_dater  )r  r  rt  rv  )r   r  rb  ra  rq  r  r  labelss           r    model_instance_version_files_cliz*KaggleApi.model_instance_version_files_cli  s     22"zY\g 3 
 
  	?fl.666F555F ?v|VV<<<<<  vv>>>>>	? 	?..r   c                    |                      |          \  }}}}|                                 5 }t                      }	||	_        ||	_        |                     t          t          j        |          |	_        ||	_	        ||	_
        ||	_        |j        j                            |	          cd d d            S # 1 swxY w Y   d S r   )rv  r  rj   r  r9  rV  rp   MODEL_FRAMEWORK_UNSPECIFIEDrx  ry  ra  rb  r:  r;  list_model_instance_versions)
r   rs  ra  rb  r  r9  rx  ry  r0  r  s
             r   model_instance_versions_listz&KaggleApi.model_instance_versions_list"  s    <@;[;[\j;k;k8
J	=%%'' 	X69;;G!+G!+G $ 0 0Akmv w wG$1G! )G!+G=1NNwWW	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	Xs   A;B77B;>B;c                 d   |                      |||          }|j        r't          d                    |j                             |j        }|rR|r(|                     |j        | j        | j                   d S | 	                    |j        | j        | j                   d S t          d           d S )Nrs  zNo versions found)
r  r  r   r  version_listrt  versionsmodel_instance_version_fieldsmodel_instance_version_labelsrv  )r   rs  rq  ra  rb  r  r  s          r    model_instance_versions_list_cliz*KaggleApi.model_instance_versions_list_cli0  s    44^YPZ[[# 	K(//0HIIJJJ( 
	' %t'I4Km       %t'I4Km     %&&&&&r   c                    |t          d          |                     |           |                    d          }|d         }|d         }|d         }|d         }|d         }|s5|                     d	|           st	          d
           t                      S t                      }	||	_        ||	_        | 	                    t          t          j        |          |	_        ||	_        t          |          |	_        |                                 5 }
|
j        j                            |	          }|}|cddd           S # 1 swxY w Y   dS )a  Deletes a model instance version.

        Args:
            model_instance_version (str): The string identifier of the model instance version, in format [owner]/[model-name]/[framework]/[instance-slug]/[version-number].
            no_confirm (bool): If True, skip confirmation (default is False).

        Returns:
            ApiDeleteModelResponse: An ApiDeleteModelResponse object.
        Nz*A model instance version must be specifiedr  r   r   rs   r  r  zdelete the version re  )r  r  r   rf  r   rg   rd   r  r9  rV  rp   rw  rx  ry  r   r  r  r:  r;  delete_model_instance_version)r   r  rc  r  r  r9  rx  ry  r  r  r0  r  r  s                r   model_instance_version_deletez'KaggleApi.model_instance_version_deleteA  s    ")IJJJ334JKKK%++C00!W
!W
G	Qa 	0$$%S;Q%S%STT 0*+++-///688'' ,,^^=_ajkk -!$^!4!4%%'' 	6}5SST[\\H-5F	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   #EEEc                     |                      ||          }t          |j                  dk    rt          d|j        z              dS t          d           dS )aJ  A client wrapper for model_instance_version_delete.

        Args:
            model_instance_version: The string identifier of the model instance version,
                in the format [owner]/[model-name]/[framework]/[instance-slug]/[version-number].
            no_confirm: If True, automatically confirm the deletion.
        r   z'Model instance version deletion error: z'The model instance version was deleted.N)r  r  ra  r   )r   r  rc  r  s       r   !model_instance_version_delete_cliz+KaggleApi.model_instance_version_delete_clih  s`     334JJWWv|q  ;flJKKKKK;<<<<<r   c                 Z   t          |          | j        k    rt          d| j        z             d S g }t          |          5 }|D ]X}|                     ||||          \  }}	| t                      }
||
_        |j        |
_        |	                    |
|	f           Y| 
                                5 }|j        j        j        }|D ]3\  }
}	 |                     |          |
           t          d|	           4	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nz!Cannot upload more than %d files!zInbox file created:)r  MAX_NUM_INBOX_FILES_TO_UPLOADr   r   file_upload_clir   virtual_directoryr   blob_file_tokenr   r  admininbox_file_clientcreate_inbox_filer  )r   local_paths
inbox_pathr   no_compressfiles_to_creater5  
local_pathupload_filerx  create_inbox_file_requestr0  r  s                r   files_upload_clizKaggleApi.files_upload_cliw  s   {d@@@58ZZ[[[F#I.. 	<.) O O
+/+?+?
JXces+t+t(i&,B,D,D)>H);<G<M)9&&(A9'MNNNN))++ <v$*L$B$T!<K < <8-y6DOO$5667PQQQ/;;;;<< < < < < < < < < < < < < < <	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s8   A0D 3AD<D D	D D	D  D$'D$c                    t           j                            |          }t           j                            |          }t           j                            |          }|rdnd}|                     ||t          j        ||          }	|	|fS )Ntarzip)r   r   abspathr  r  _upload_file_or_folderr   INBOX)
r   r  r  r  r5  	full_pathparent_pathfile_or_folder_namerF  r  s
             r   r  zKaggleApi.file_upload_cli  s    GOOJ//	gooi00 g..y99'255U11,k.?QY
 
 ///r   c                 P    t          j        ||          }t          |           d S )Nr   )r   r  r   )r   objr   prettys       r   rA  zKaggleApi.print_obj  s%    C///fr   r  r  c                 P   	 |j                             d          }|t          j                    }n t          j        |j         d         d          }t
          j                            |          }|rt          j        t
          j        	                    |                    }t          |j         d                   }t
          j                            |          }	|	|k     rdS ||k    r3|s/t          t
          j                            |          dz              dS n#  Y nxY wdS )av  Determines if a download is needed based on the timestamp.

        Args:
            response (Response): The response from the API.
            outfile (str): The output file to which to write.
            quiet (bool): Suppress verbose output (default is True).

        Returns:
            bool: True if a download is needed (remote is newer), False otherwise.
        r  Nr  r  TzS: Skipping, found more recently modified local copy (use --force to force download)F)r  r  r   r  r  r   r   r  fromtimestampr  r   r  r   r  )
r   r  r  r  r  r  r  
local_dateremote_size
local_sizes
             r   r  zKaggleApi.download_needed  s   	$,00AAM$&lnn&/0@0QSmnn'..11K !%3BG4D4DW4M4MNN
!("23C"DEEW__W55
++4*,,  G,,W55 9C C   !5	Dts   C!D %7D D#c           	      ^    ||}g }g }t          |          dk    rdS |D ]Ԋt          t                    t           fd|D                                 }t          t          |d                                                  t
                    sdk    sdk    rdnd}|                    d|z                        |d	z             z   d
z              |                    d|z  dz              d                    |          }d |D             }	t           |j
        |	            t           |j
        |            |D ]c fd|D             }
	 t           |j
        |
            *# t          $ r- t           |j
        |
                     d                     Y `w xY wdS )zPrints a table of items for a defined set of fields.

        Args:
            items: A list of items to print.
            fields: A list of fields to select from the items.
            labels: The labels for the fields (defaults to fields).
        Nr   c                     g | ]E}t                              t          |                                                            FS r   )r  stringgetattrrM  )r  r  r   r   s     r   r  z)KaggleApi.print_table.<locals>.<listcomp>  sG    %j%j%j_`c$++gaATATUVAWAW6X6X*Y*Y&Z&Z%j%j%jr   r  rv  ><z{:rs   r  -  r  c                     g | ]}|d z   S r  r   r  s     r   r  z)KaggleApi.print_table.<locals>.<listcomp>  s    ,,,1t8,,,r   c           
          g | ];}                     t                              |                              d z   <S r  r  r  rM  r  r   r  r   s     r   r  z)KaggleApi.print_table.<locals>.<listcomp>  sC    ___STGAt/B/B1/E/E$F$FGG$N___r   r  )r  maxr  r  rM  r   r   r  r   r   r  UnicodeEncodeErrorencode)r   r  r  r  formatsborderslengthjustify
row_formatr  i_fieldsr   r  s   `          @@r   rv  zKaggleApi.print_table  s    >Fu::??F 	0 	0AQ%j%j%j%j%jdi%j%j%j!k!kllF geAh0C0CA0F0FGGMMQRV\Q\Q\`aem`m`m  
 NN4'>DKK
,C,CCcIJJJNN3<$.////WWW%%
,,V,,,j)***j)*** 	D 	DA_____X^___HD'j'23333% D D D'j'299'BBCCCCCD		D 	Ds   E334F*)F*c                      ||}t          j        t          j                  }|                    |           |D ]& fd|D             }|                    |           'dS )a  Prints a set of fields from a set of items using a CSV writer.

        Args:
            items: A list of items to print.
            fields: A list of fields to select from the items.
            labels: The labels for the fields (defaults to fields).
        Nc           
      |    g | ]8}                     t                              |                              9S r   r  r  s     r   r  z'KaggleApi.print_csv.<locals>.<listcomp>  s=    XXXAGAt/B/B1/E/E$F$FGGXXXr   )re  writerr  stdoutwriterow)r   r  r  r  r$  r!  r  s   `     @r   rt  zKaggleApi.print_csv  s~     >FCJ'' 	& 	&AXXXXXQWXXXHOOH%%%%	& 	&r   c                 N    t          |t                    r|nt          |          S r   )r  r   )r   r  s     r   r  zKaggleApi.string  s!    !$,,;tt#d));r   rG  c                 D    ||v r||         S t          d|z   dz             )NzKey z not found in data)r  )r   rG  r)  s      r   r  zKaggleApi.get_or_fail  s-    $;;9#(<<===r   defaultc                     ||v r||         S |S r   r   )r   rG  r)  r)  s       r   rQ  zKaggleApi.get_or_default  s    $;;9r   c                    ||v r|||         }t          |t                    r6|                                }|dk    rdS |dk    rdS t          d|z             t          |t                    r|S t          d|z             |S )Nr9  Tr7  FzInvalid boolean value: )r  r   r  r  r   )r   rG  r)  r)  r  s        r   r  zKaggleApi.get_bool  s    $;;s)C#s## Fiikk&==4G^^ 5$%>%DEEE#t$$ 
6<===r   c                 D   t           j                            || j                  }t           j                            |          s[t           j                            || j                  }t           j                            |          st          d| j        z             |S Nr  )r   r   r   r
  r  OLD_DATASET_METADATA_FILEr  r  s      r   r  z#KaggleApi.get_dataset_metadata_file  s}    GLL)CDD	w~~i(( 	[VT-KLLI7>>),, [ !<t?Y!YZZZr   c                     t           j                            || j                  }t           j                            |          st          d| j        z             |S r-  )r   r   r   rB  r  r  r  s      r   rY  z!KaggleApi.get_model_metadata_file  sN    GLL)ABB	w~~i(( 	U84;SSTTTr   c                     t           j                            || j                  }t           j                            |          st          d| j        z             |S r-  )r   r   r   r  r  r  r  s      r   r  z*KaggleApi.get_model_instance_metadata_file  sN    GLL)JKK	w~~i(( 	^84;\\]]]r   c                    t           j                            d          }t          |          }|                    d          }t          |          }t	          ||          D ]}|                    d           t	          ||          D ]}|                    d           t	          d|          D ]U}d||         v s
d||         v r dS t          ||                   }t          ||                   }||k     r dS ||k     r dS VdS )zDetermines if the client is up to date with the server.

        Args:
            server_version: The server version string to compare to the client.

        Returns:
            True if the client is up to date, False otherwise.
        rX  0r   abTF)r0  __version__r   r  r  r   r   )	r   server_versionclient_split
client_lenserver_split
server_lenr  r  servers	            r   is_up_to_datezKaggleApi.is_up_to_date#  s4    )//44&&
%++C00&&
 z:.. 	% 	%A$$$$z:.. 	% 	%A$$$$q*%% 		 		Al1o%%Q)?)?tta))Fa))Fuu&tt ! tr   r  rO  c           
         t          j        |          D ]s}|| j        | j        | j        | j        | j        fv r%|                     |||||||          }	|	1|j        }
|
(|
	                    | 
                    |	                     tdS )a  Uploads files in a folder.

        Args:
            request (Union[ApiCreateDatasetVersionRequestBody, ApiCreateModelInstanceRequestBody, ApiCreateDatasetRequest, ApiCreateModelInstanceVersionRequestBody]): The prepared request.
            resources (Optional[List[Dict[str, Union[str, Dict[str, List[Dict[str, str]]]]]]]): The files to upload.
            folder (str): The folder from which to upload.
            blob_type (ApiBlobType): The entity to which the file/blob refers.
            upload_context (ResumableUploadContext): The context for resumable uploads.
            quiet (bool): Suppress verbose output (default is False).
            dir_mode (str): What to do with directories: "skip" - ignore; "zip" - compress and upload.

        Returns:
            None:
        N)r   listdirr
  r.  r  rB  r  r  r  r   	_new_file)r   r  rO  rB  r4  r5  r  rF  rx  r  r  s              r   rW  zKaggleApi.upload_filesD  s    : F++ 	> 	>I*.)(1   55	9nhy K &$LL!<!<===	> 	>r   r  c                     t                      }|j        |_        |j        |_        |j        rd |j        D             |_        |S )Nc                 Z    g | ](}t          j        |                                          )S r   )rA   r   r   )r  r  s     r   r  z'KaggleApi._new_file.<locals>.<listcomp>w  s,    dddt 0 :4<<>> J Jdddr   )r;   r   r{  columns)r   r  new_files      r   r?  zKaggleApi._new_filer  sK    $&&#/< 	eddW[WcdddHr   r  r  c           	         t           j                            ||          }d }	t           j                            |          r|                     ||||||          }	nt           j                            |          ri|dv rMt          ||          5 }
|                     |
j        |
j        ||||          }	d d d            n# 1 swxY w Y   n,|st          d|z   dz              n|st          d|z              |	S )N)r  r  zSkipping folder: z$; use '--dir-mode' to upload foldersz
Skipping: )	r   r   r   r  _upload_filerP  r   r   r   )r   r  r  r4  r5  rF  r  rO  r  r  archives              r   r  z KaggleApi._upload_file_or_folderz  sL    GLL.ABB	7>>)$$ 	:++,?IWeglnwxxKKW]]9%% 
	:>))%i:: g"&"3"3glI~uV_# #K                j),??Bhhiii :l%88999s   %CCCr  c           	         |st          d|z              t          j                            |          }|                     ||||          }||st          d|z              dS |s-t          d|z   dz   t          j        |          z   dz              t                      }	||	_        |r|D ]}
||
	                    d          k    r|
	                    d          |	_
        d	|
v rt          t          t          t          f         |
d	                   }t          t          |                     |d
g                     }g }d}|D ]<}|                    |                     |                     |||         _        |dz  }=||	_        |	S )a  A helper function to upload a single file.

        Args:
            file_name (str): The name of the file to upload.
            full_path (str): The path to the file to upload.
            blob_type (ApiBlobType): The entity to which the file/blob refers.
            upload_context (ResumableUploadContext): The context for resumable uploads.
            quiet (bool): Suppress verbose output.
            resources (Optional[List[Dict[str, Union[str, Dict[str, List[Dict[str, str]]]]]]]): Optional file metadata.

        Returns:
            Union[UploadFile, None]: An UploadFile object if the upload was successful, otherwise None.
        zStarting upload for file NzUpload unsuccessful: zUpload successful: z ()r   r{  schemar  r   r   )r   r   r   r  r@  r   get_sizeru   r   r  r{  rz   dictr   r  rQ  r   process_columnorderrB  )r   rx  r  r4  r5  r  rO  r  r   r  r  rI  r  	processedcountfields                   r   rE  zKaggleApi._upload_file  s   .  	;-	9:::33!!)UI~NN= ;-	9:::4 	b')3d:T]>=Z=ZZ]``aaa ll! 	8! 8 8 0 000.2hh}.E.EK+4''!%d39otH~!F!F!%dD,?,?RT,U,U!V!V$&	 !%+ ' 'E%,,T-@-@-G-GHHH5:Ie,2!QJEE.7+r   c                    t          |                     |d          |                     |dd                    }d|v r|d                                         }||_        |dk    s$|dk    s|dk    s|d	k    s|d
k    s|dk    s|dk    rd|_        n=|dk    s|dk    s|dk    rd|_        n#|dk    rd|_        n|dk    rd|_        n||_        |S )zProcesses a column, checks for the type, and returns the processed column.

        Args:
            column: A list of values in a column to be processed.

        Returns:
            A DatasetColumn object.
        r   r{  r  )r   r{  r  r  rz  r   	yearmonthdurationgeopointgeojsonnumericnumberyearbooleanr   )rt   r  rQ  r  original_typer  )r   columnprocessed_columnrZ  s       r   rL  zKaggleApi.process_column  s2    )!!&&11t?R?RSY[hjl?m?m
 
 
 V"6N0022M-:*)) F** F** K// J.. J.. I--(0 %%)++}/H/HM]cLcLc(1 %%)++(1 %%*,,(2 %% )6 %r   c           	         t           j                            |          }t          j                    }	 |r4|                     ||||          }|j        t          j        k    r|j        S |j        }||z
  }t          |ddd|          5 }	t          j        |dd          5 }
t          j                    }|dk    r>|
                    |           |j                            d|z  d	||d
z
  |fz  d           t#          |
|	          }t%          dd          }t'          |          }|                    d|           |                    d|           |                    ||          }|                     |          r$t          j        cddd           cddd           S |j        dk    r$t          j        cddd           cddd           S t          j        cddd           cddd           S # 1 swxY w Y   	 ddd           dS # 1 swxY w Y   dS # t4          $ r%}t7          |           t          j        cY d}~S d}~ww xY w)a:  Completes an upload to retrieve a path from a URL.

        Args:
            path: The path for the upload that is read in.
            url: The URL to which to send the POST request.
            quiet: Suppress verbose output (default is False).
            resume: Whether to resume an existing upload.
        r  Tr  )r  r  r  r  r  rbr   )	bufferingz%dzbytes %d-%d/%dr   r  zContent-Ranger+  r  )r  backoff_factor)r  zhttp://zhttps://)rG  Ni  )r   r   r  r   
Incomplete_resume_uploadr  r<  start_atr   r   r   r  Sessionseekr  r  TqdmBufferedReaderr   r   mountput_is_upload_successfulr  r  FAILEDr   r   )r   r   r  r  r7  	file_sizeresumable_upload_resultrd  upload_sizeprogress_barfpsessionreaderretriesadapterr  ra  s                    r   r   zKaggleApi.upload_complete  s~    GOOD))	"7"B"D"D$	4 :*.*=*=dCTY*Z*Z'*15J5UUU299.7H#h.KKcdQU_deee 8iuWT41555 8&.00G!||)))..262D1AXy[\}^gDh1h    0LAAF#"SAAAG)g>>>GMM)W555MM*g666&{{3V{<<H11(;; >4=#8 8 8 8 8 8 88 8 8 8 8 8 8 8&  +s224?'8 8 8 8 8 8 88 8 8 8 8 8 8 8, 17+8 8 8 8 8 8 88 8 8 8 8 8 8 88 8 8 8 8 8 8 8 88 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8.  	4 	4 	4%LLL )3333333		4s   5H  * H  
H"C,G:HH  'G:=H	H  G:!H-H  :G>	>HG>	HH  HH  HH   
I*I
I
Ic                 v   t          j                    }|j                            dd|z  d           |                    |          }|                     |          rt          j                    S |j        dk    r'|st          d|z             t          j
                    S |j        dk    ra|                     ||          }|t          j
                    S t          j        |          }|st          d|j        |j        fz             |S |st          d|j        z             t          j
                    S )	Nr2  z
bytes */%dr`  r  z'Upload of %s expired. Please try again.i4  z4Already uploaded %d bytes. Will resume upload at %d.z%Server returned %d. Please try again.)r  re  r  r  ri  rj  r   Completer  r   Failed_get_bytes_already_uploadedrb  bytes_uploadedrd  )	r   r   r  r  r  rq  r  ry  r  s	            r   rc  zKaggleApi._resume_upload   sW   "$$"%!-!> 	
 	
 	
 ;;s##%%h// 	4(13333&& H?$FGGG(/1113&&!==hNNN%,3555*5nEEF yLPVPegmgvOwwxxxM V=@TTUUU(/111r   c                 .    |j         dk    p
|j         dk    S )N      )r  )r   r  s     r   rj  zKaggleApi._is_upload_successfulA  s    #s*Ih.Bc.IIr   c                 4   |j                             d          }|dS |                    d          }t          |          dk    r|st	          d|z             d S |d         }	 t          |          S # t          $ r |st	          d|z             Y d S w xY w)Nr  r   r  rs   z0Invalid Range header format: %s. Will try again.r7  )r  r  r   r  r   r   r  )r   r  r  	range_valr  bytes_uploaded_strs         r   rx  z%KaggleApi._get_bytes_already_uploadedD  s    $((11	1$$u::?? VH9TUUU4"2Y	)*** 	 	 	 VH9TUUU44	s   &A5 5BBc                     |r]d|vrt          d          |                    d          }|d         r|d         rt          |          dk    rt          d|z             dS dS )a%  Validates a dataset string.

        A dataset string is valid if it is in the format
        {username}/{dataset-slug} or {username}/{dataset-slug}/{version-number}.

        Args:
            dataset (Optional[str]): The dataset name to validate.

        Returns:
            None:
        r  zDDataset must be specified in the form of '{username}/{dataset-slug}'r   r   r  zInvalid dataset specification Nr  r   r  )r   r  r   s      r   r  z!KaggleApi.validate_dataset_stringU  s      	M'!! !jkkkMM#&&E8 M58 Ms5zzA~~ !AG!KLLL	M 	M
 0>~r   c                    d|v re|                      |           |                    d          }t          |          dk    r|d         |d         |d         fS |d         |d         dfS |                     | j                  |dfS )a  Splits a dataset string into owner_slug, dataset_slug, and an optional version_number.

        Args:
            dataset: The dataset name to split.

        Returns:
            A tuple containing the owner_slug, dataset_slug, and an optional version_number.
        r  r  r   r   rs   N)r  r   r  r  r  )r   r  r  s      r   r  zKaggleApi.split_dataset_stringi  s     '>>((111==%%D4yyA~~AwQa00AwQ--(()>??$NNr   c                     |r_|                     d          dk    rt          d          |                    d          }|d         r|d         st          d|z             dS dS )zValidates a model string.

        A model string is valid if it is in the format {owner}/{model-slug}.

        Args:
            model (str): The model name to validate.

        Returns:
            None:
        r  r   z=Model must be specified in the form of '{owner}/{model-slug}'r   zInvalid model specification NrO  r  r   )r   r6  r   s      r   r  zKaggleApi.validate_model_string|  s      	I{{31$$ !cdddKK$$E8 I58 I !?%!GHHH	I 	I
I Ir   c                     d|v r:|                      |           |                    d          }|d         |d         fS |                     | j                  |fS )zSplits a model string into owner_slug and model_slug.

        Args:
            model (str): The model name to split.

        Returns:
            Tuple[Union[str, None], str]: A tuple containing the owner_slug and model_slug.
        r  r   r   )r  r   r  r  )r   r6  
model_urlss      r   r8  zKaggleApi.split_model_string  sa     %<<&&u---S))Ja=*Q-//(()>??FFr   c                     |ro|                     d          dk    rt          d          |                    d          }|d         r|d         r|d         r|d         st          d|z             dS dS )	a   Validates a model instance string.

        A model instance string is valid if it is in the format
        {owner}/{model-slug}/{framework}/{instance-slug}.

        Args:
            model_instance (str): The model instance name to validate.

        Returns:
            None:
        r  r  zbModel instance must be specified in the form of '{owner}/{model-slug}/{framework}/{instance-slug}'r   r   rs   z%Invalid model instance specification Nr  )r   rs  r   s      r   r  z(KaggleApi.validate_model_instance_string  s      		[##C((A-- I  
 #((--E8 [58 [58 [58 [ !H>!YZZZ		[ 		[[ [r   c                     |                      |           |                    d          }|d         |d         |d         |d         fS )a  Splits a model instance string into its components.

        Args:
            model_instance (str): The model instance name to validate.

        Returns:
            Tuple[str, str, str, str]: A tuple containing the owner_slug, model_slug, framework, and instance_slug.
        r  r   r   rs   r  )r  r   )r   rs  r  s      r   rv  z%KaggleApi.split_model_instance_string  sJ     	++N;;;##C((AwQa$q'11r   c                 P   |r|                     d          dk    rt          d          |                    d          }|d         r |d         r|d         r|d         r|d         st          d|z             	 t          |d                   }d
S #  t          d	          xY wd
S )aQ  Validates a model instance version string.

        A model instance version string is valid if it is in the format
        {owner}/{model-slug}/{framework}/{instance-slug}/{version-number}.

        Args:
            model_instance_version (str): The model instance version name to validate.

        Returns:
            None:
        r  r  z{Model instance version must be specified in the form of '{owner}/{model-slug}/{framework}/{instance-slug}/{version-number}'r   r   rs   r  z-Invalid model instance version specification z:Model instance version's version-number must be an integerN)rO  r  r   r   )r   r  r   r  s       r   r  z0KaggleApi.validate_model_instance_version_string  s     " 	_%++C00A55 Z  
 +0055E8 k58 k58 k58 kSXYZS[ k !PSi!ijjj_!$U1X_ !]^^^	_ 	_s   ;B B#c                     |rod|vrt          d          |                    d          }|d         r|d         st          d          t          |d                   dk     rt          d          dS dS )zValidates a kernel string.

        A kernel string is valid if it is in the format {username}/{kernel-slug}.

        Args:
            kernel (Optional[str]): The kernel name to validate.

        Returns:
            None:
        r  zBKernel must be specified in the form of '{username}/{kernel-slug}'r   r   r  z,Kernel slug must be at least five charactersNr  )r   rz  r   s      r   r  z KaggleApi.validate_kernel_string  s      		Q&   !hiiiLL%%E8 j58 j !hiii58}}q   !OPPP		Q 		Q ! r   c                 \    |                      ||           |                     |           dS )a  Validates the existence and uniqueness of resource files in a folder.

        This method is a wrapper that validates the existence of files and ensures
        that there are no duplicates for a given folder and set of resources.

        Args:
            folder (str): The folder to validate.
            resources (List[Dict[str, Union[str, Dict[str, List[Dict[str, str]]]]]]): One or more resources to validate within the folder.

        Returns:
            None:
        N)validate_files_existvalidate_no_duplicate_paths)r   rB  rO  s      r   rR  zKaggleApi.validate_resources  s4     	!!&)444((33333r   c                    |D ]{}t          t          |                    d                    }t          j                            ||          }t          j                            |          st          d|z            |dS )a3  Ensures that one or more resource files exist in a folder.

        Args:
            folder (str): The folder to validate.
            resources (List[Dict[str, Union[str, Dict[str, List[Dict[str, str]]]]]]): One or more resources to validate within the folder.

        Returns:
            None:
        r   z%s does not existN)rz   r   r  r   r   r   r  r  )r   rB  rO  r  rx  r  s         r   r  zKaggleApi.validate_files_exist  s      	B 	BDS$((6"2"233IVY77I7>>),, B !4y!@AAAB	B 	Br   c                     t                      }|D ]U}|                    d          }||v rt          d|z            |                    t	          t
          |                     VdS )a  Ensures that the user has not provided duplicate paths in a list of resources.

        Args:
            resources (List[Dict[str, Union[str, Dict[str, List[Dict[str, str]]]]]]): One or more resources to validate for duplicate paths.

        Returns:
            None:
        r   z4%s path was specified more than once in the metadataN)setr  r  addrz   r   )r   rO  rh  r  rx  s        r   r  z%KaggleApi.validate_no_duplicate_paths  sv      	, 	,D((IE!! !WZc!cdddIId3	**++++		, 	,r   c                     t           j                            ||d                   |d         d}i }g }|d         D ]/}|d         |d         |d         d}|                    |           0||d<   ||d<   |S )	a  Converts a set of file_data to a metadata file at a given path.

        Args:
            file_data: A dictionary of file data to write to the file.
            path: The path to which to write the metadata.

        Returns:
            A dictionary representing the metadata.
        r   r{  )r   r{  rB  r  )r   r  r  r  rI  )r   r   r   r   )r   	file_datar   as_metadatarI  r  r[  rP  s           r    convert_to_dataset_file_metadataz*KaggleApi.convert_to_dataset_file_metadata+  s      "w||D)F2CDDU^_lUmnn	* 	! 	!F#F^f]6KU[\bUcddEMM%    !x &Hr   c                 0    t          j        |d           d S )Nz%Y-%m-%d)r   r  )r   rz  s     r   r[  zKaggleApi.validate_dateA  s    $
+++++r   markdownc                 *    t          j        |          S r   )bleachclean)r   r  s     r   rZ  zKaggleApi.sanitize_markdownD  s    |H%%%r   actionc                 F   t          |          rd| d}nd}d}ddddd}	 t          j                            d                    ||                     t                                                      }||v r||         S t          j                            d	           dS )
NzAre you sure you want to r  zAre you sure?z[yes/no]TF)r:  ynonz{} {} z#Please respond with 'yes' or 'no'.
)r  r  r%  r  r  inputr  )r   r  questionpromptoptionschoices         r   rf  zKaggleApi.confirmationG  s    v;; 	'<6<<<HH&HTUCC	JX__Xv>>???WW]]__F  v&
  !GHHHur   c                     | j         rd S |j                            d          }|rFt          t          j                  }t          |          }||k    rt          d           d| _         d S d S d S )NzX-Kaggle-APIVersionzWarning: Looks like you're using an outdated `kaggle`` version (installed: {current_version}), please consider upgrading to the latest version ({latest_version_str})T)already_printed_version_warningr  r  r   r0  r5  r   )r   r  latest_version_strcurrent_versionlatest_versions        r   _check_response_versionz!KaggleApi._check_response_versionW  s    / 	F%-112GHH 		<#F$677O"#566N//M  
 8<444		< 		< 0/r   c                     | j         S r   )r  r   s    r   rB  z KaggleApi.get_response_processorf  s    ++r   r   )r+  r  r  r  r   r   r   )rs   )r  r  )r  )FF)NNNN)NNNr   Nr\  N)NNNr   NFr\  N)NNNF)NNNNNNF)NNFr7  r  r\  F)Nr\  )NFNr\  F)NFF)NFT)NNNFF)T)r\  N)NNFFFFr\  N)NNNNNNNFr   NN)NNNNNNNFr   FNN)NFNr\  )NNNFFF)FTFrA  )FFTrA  )NFFTrA  )TFr  )r   r\  NNNNFNNNNN)Fr   r\  NFNNNNNNNN)FT)NNF)NNFF)NNNr\  N)NNNr\  NF)FrA  )Nr\  F)Fr\  N)r  FrA  )NFTF)NFFF)FN)r  ($  r   r   r   r   r%  r&  r  r  r  r  r  CONFIG_NAME_SSL_CA_CERTHEADER_API_VERSIONr
  r.  r  rB  r  r  r8  r   r  r  r  r   r   r   r  platformr  r   r   r  r  r1  r{   r   __annotations__r  r   r|   r   r  rE  loggingbasicConfigDEBUG	getLoggerr  r  r  r  r  r  r  r  re  rg  ri  r  r  r  rI  r  ru  r  r  r  r  r  r  r  model_fieldsmodel_all_fieldsmodel_file_fieldsr  r  r  r  r   r   rw   r  r  ry   rJ   r   floatr  r  r  r  r  r  r  r  r~   r  r  r
  r  r  r  r  r  r  r'  r.  r4  r   r1  r<  	kagglesdkkaggle_clientr   r  r
  rA  rM  rv   r   rV  r[  r-   rp  rw  r,   r  r   r  r  r1   SUBMISSION_GROUP_ALLr2   SUBMISSION_SORT_BY_DATEr  r"   r  r  r$   r  r  r  r  r  r  r)   r  r  r?   r  r  r  r  r  r  r  r  r  r  r  r  r"  r,  r   r3  r   r   r   r@  r@   r\  rb  rh  ro  rq  rs  rw  rz  r  r  r  rR   r  r  r  r  r  r  rQ   r  r  r   r"  r   r,  r.  r1  r5  re   r=  rE  rK  rM  rS  rU  rf   r^  ra  rg   rd  rf  ro  rr  rh   r{  r  r  r  r  r  r  r  r   r  r  r  rm   r  r  r  r  r  r  r  r  ri   r  r  rk   r  r  r  r  r  r  rA  rx   r  rv  rt  r  r}   r  rQ  r  r  rY  r  r<  r8   r]   r7   rb   rW  ru   r;   r?  r  rE  rL  r   rc  rj  rx  r  r  r  r8  r  rv  r  r  rR  r  r  r  r[  rZ  rf  r  rB  r   r   r   r$  r$    sW"         ,  +!+O+.3 21/#A $(!!# 344J W\\**S//9==
 <""7++ 	BGNN:4N4N 	 122^bgll::c??T]6^6^ai J 7>>*%%  JKW\\*k22F$&M4S>&&&&+#D$s)	z~~.//;>>Iz~~i((WBJNN;K,L,LWPW^^``G&&&K   '-0000Wx((F  (4 < < < *H5DDD;;;>>>
 
 
  srr$ $ $ 	! 	! 	!  WVV"F"F"FSSS dcc 2g. baadddDDD>>>%V%V%V"sssNmmmNAAA???Lvvv888iiiCCC$a$a$a!$P$P$P!) )T ) ) ) )
y 
T 
 
 
 
   $'"%#& ~|34  "	
   ! 
<.,.	/   8   0%$ % % % %N  &    ,c c    
c 
d 
 
 
 
	Is 	It 	I 	I 	I 	I 8DcN3K W[\_ad\dWe    8' 'HT#s(^,D 'TX 'eijmorjres ' ' ' 'R  	5 	5 	5 	5L LS L LT Ld L L L L@L L L L&	,S 	,Xc] 	, 	, 	, 	,, , , , , ,(7 7 7 7M M M M [ [ [T [ [ [ [$" "3 " " " "2wC wM w w w wU U U U U"
Y%<%I 
 
 
 
 os
 
3i
#&
9<
PS
		 	-
 
 
 \
<
C3 
C3 
C 
C 
C 
Ch  c a    $-S -S - - - -  $"&!% $#%$(=Y =Y}=Y 3-=Y #	=Y
 sm=Y =Y C==Y SM=Y 
%t	+=Y =Y =Y =YB  $"&!% $&+#%$(,+ ,+},+ 3-,+ #	,+
 sm,+ ,+ d^,+ C=,+ SM,+ 
,+ ,+ ,+ ,+d &* $(,.' .'.' .' c]	.'
 .' !.' .' 
).' .' .' .'b MR/' /'/''*/'9</'EI/'	$/' /' /' /'f $(!%%) $!%)-.% .%C=.% #.% c]	.%
 .% #.% "#.% .% 
.% .% .% .%f "1!E!1!I   	
   
md"	#d	*   B '. '. '. '.T TV ,4SMMP	!   0 jo (  (  (  (F puZ ZZ+.Z6>smZSWZhlZ	Z Z Z Z@ `d^ ^^&.sm^CG^X\^	^ ^ ^ ^< `e[ [ [ [6K KC Ks KSW Kcg K K K K2 \` +3C=KSTW=	&-	.	5   6 #%$(0* 0* C=0* SM0* 0* 0* 0*h "&"#'&*!% $"$"&"&^ ^#^ sm^ C=	^
 sm^ #^ ^ sm^ tn^ sm^ 3-^ 3-^ 
j4	 4	'^ ^ ^ ^D (' (' (' ('T: : :4# # #J   \
   \  :9 9 9 9$   ,$ $ $ $:0c 0c 0 0 0 06, , , , >BVZeg ( ( ( (T 48uDX]hj <C <C <C <C|
; 
; 
; ej's 's 's 'sR// $/1</Nd/	s	"T	)/ / / /j #$)M  M M  M  	M 
 M  "M  M  
"M  M  M  M ` lr!E !E !E !EFG G GC GT G^b G G G G4; ;S ;d ;t ; ; ; ;:
0 
0 
0$ 
04 
0 
0 
0 
0< <# <4 <D < < < <"     2( ( ( ( #f ff f 	f
 f f 
"f f f fP= = = =0KT KT KT KT^ !%%)'+ $""&%)%)!%V VV V #	V
 c]V  }V V V smV 3-V c]V c]V #V 
$&	'$	.V V V Vt 9 9 9 9vP P P P(3 3 3 34' ' ' ' ' 'R
C 
C 
C 
CA A3 A# AJ_ A A A AF+8 +8 +8ZC C C CJA A A A? ?S ? ?D ?QU ?afgklogpruguav ? ? ? ?B/ / / /$X X X2; ; ; ;"Us Ux U U U U"C C C CB "& $#$(( (#( ( }	(
 ( SM( 
ho		%( ( ( (T% % % %*"s "s " " " "H& & & &3s 3/E 3 3 3 3j; ; ; ;# 4 <R    0, , ,DH DH DHL9 9 9 9 9I    ,1C 1C 1C 1Cf, , , , , ,\/ / /H  H C H  H PS H aw H  H  H  H TD D D D  C T Vl    85 5 5  rw&D &D!&D/4S$Y/?&DSV&Djn&D	&D &D &D &DP7 7 7 7(P PUr P P P P( ( ( (VQ VQ VQp9 9 9 9 ou   ! +. ?B PT hk 	       @L L L L* #D D #D smD 	D
 D D 
D D D DN RW
 
 
 
( (,!+ + #+ #t)$+ 	+
 + 
7=	>+ + + +\ RW? ? ? ?0 8<X X	-X X X X' ' ' '$ ?D% %&)%7;%	% % % %N= = =< < <.	0 	0 	0   ! ! !3 !t !W[ ! ! ! !F D  D  D  DD& & & & < < <>Q >c >a > > > >
4Q< c HQK T\]^T_    
T#uS$Y'7"78 s T VZ          c c    s s      Z ,> ,>.-#46
,> Dc5d3T#s(^@T;T6U1U+V&V!WXY,> ,> ,> /,> ,> ,> 
,> ,> ,> ,>\j ->     \`  ! 	
 /   Dc5d3T#s(^@T;T6U1U+V&V!WXY 
z4	    622 2 	2
 /2 2 Dc5d3T#s(^@T;T6U1U+V&V!WXY2 
z4	 2 2 2 2h#  #  # J04 04 04 04d2 2 2BJ J J  "Mx} M M M M M(O O O&I3 I4 I I I I&G GeCI6F6K0L G G G G [S [T [ [ [ [.2# 2%SRUWZHZB[ 2 2 2 2_S _UY _ _ _ _8QXc] Qt Q Q Q Q,44&*4U3S$tTWY\T\~J^E^@_;_5`0`+a&b4	4 4 4 4$BB&*4U3S$tTWY\T\~J^E^@_;_5`0`+a&bB	B B B B$,d3c4T$sCx.=Q8Q3R.R(S#STU,	, , , ,$  ,, , ,&# &# & & & & 3     < < < < <, , , , ,r   r$  c                        e Zd Zd Zd Zd ZdS )rg  c                 T    t           j                            | |           || _        dS )a  Initializes a new instance of the TqdmBufferedReader class.

        This is a helper class to implement an io.BufferedReader.

        Args:
            raw: The raw bytes data to pass to the buffered reader.
            progress_bar: The progress bar to initialize the reader.
        N)r   BufferedReaderr   ro  )r   rawro  s      r   r   zTqdmBufferedReader.__init__l  s+     	""4---(r   c                 ~    t          j        j        | g|R i |}|                     t	          |                     |S )zYRead the buffer, passing named and non named arguments to the io.BufferedReader function.)r   r  r  	incrementr  )r   r   kwargsbufs       r   r  zTqdmBufferedReader.readx  sB    $T;D;;;F;;s3xx   
r   c                 :    | j                             |           dS )zIncrements the reader by a given length.

        Args:
            length: The number of bytes by which to increment the reader.
        N)ro  r  )r   r  s     r   r  zTqdmBufferedReader.increment~  s!     	  (((((r   N)r   r   r   r   r  r  r   r   r   rg  rg  j  sA        
) 
) 
)  ) ) ) ) )r   rg  )pprint)
getmembers)FunctionTypec                      d t          t                               D              fdt                     D             S )Nc                 B    h | ]\  }}t          |t                    |S r   )r  r  )r  r   r  s      r   	<setcomp>zattributes.<locals>.<setcomp>  s-    iiiuTY[gIhIhiiiir   c                 r    i | ]3}|d          dk    |vt          |          "|t          |          4S )r   r   )hasattrr  )r  r   disallowed_namesr  s     r   
<dictcomp>zattributes.<locals>.<dictcomp>  sV       7c>>d*:::wsD?Q?Q: 	gc4  :::r   )r  r  dir)r  r  s   `@r   
attributesr    s\    ii
4990E0Eiii    HH   r   c                 >    t          t          |                      d S r   )r  r  )r  s    r   print_attributesr    s    
:c??r   )
__future__r   re  r   r   enumr   r   r   r  r   rK  r   r  r  r   r   r$  dateutil.relativedeltar   os.pathr   r	   r  r  urllib3.exceptionsr  r  r
   $kaggle.models.kaggle_models_extendedr   r   requests.adaptersr   r   r   urllib3.util.retryr   google.protobufr   packaging.versionr   r0  r  r   r   r   r   r   (kagglesdk.admin.types.inbox_file_servicer   &kagglesdk.blobs.types.blob_api_servicer   r   r   4kagglesdk.competitions.types.competition_api_servicer   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   .kagglesdk.competitions.types.competition_enumsr.   r/   r0   r1   r2   ,kagglesdk.datasets.types.dataset_api_servicer3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   &kagglesdk.datasets.types.dataset_enumsrC   rD   rE   rF   &kagglesdk.datasets.types.dataset_typesrG   rH   rI   kagglesdk.kaggle_objectrJ   +kagglesdk.kernels.types.kernels_api_servicerK   rL   rM   rN   rO   rP   rQ   rR   rS   %kagglesdk.kernels.types.kernels_enumsrT   rU   (kagglesdk.models.types.model_api_servicerV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   "kagglesdk.models.types.model_enumsrn   ro   rp   "kagglesdk.models.types.model_typesrq   &kagglesdk.security.types.oauth_servicerr   models.dataset_columnrt   models.upload_fileru   kagglesdk.kaggle_clientrv   requests.exceptionsrw   requests.modelsrx   typingry   rz   r{   r|   r}   r~   r   r   r   r   r   r   objectr   r   r   r  r$  r  rg  r  inspectr  typesr  r  r  r   r   r   <module>r     se  $ & % % % % % 



 ( ( ( ( ( ( ( (       				   				 				  



     0 0 0 0 0 0               / / / / / / % % % % % % L L L L L L L L ) ) ) ) ) )             $ $ $ $ $ $ * * * * * * # # # # # #  h h h h h h h h h h h h h h K K K K K K u u u u u u u u u u                                       (                                                $            i h h h h h h h h h 0 0 0 0 0 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 [ Z Z Z Z Z Z Z                                                   4 d c c c c c c c c c 4 4 4 4 4 4 I I I I I I 1 1 1 1 1 1 + + + + + +           ) ) ) ) ) ) $ $ $ $ $ $ a a a a a a a a a a a a a a a a a a a a a a a aGCLL       & & & & &v & & &25 5 5 5 5V 5 5 5pj j j j j& j j jZ1 1 1 1 1v 1 1 1hHJ, HJ, HJ, HJ, HJ, HJ, HJ, HJ,VT) ) ) ) )* ) ) )@                        r   