
    gj                        U d Z ddlZddlmZ ddlmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZ dedefdZde
defdZdedefd	Zdedefd
ZdedefdZdedefdZdedefdZdedefdZi ed e
eeeeeeeed ed ed eeeee	d ed ed ed eeeeZee e!         edef         f         e"d<   de!dedz  fdZ#dS )zCLI error handling utilities.    N)Callable)BucketNotFoundErrorCLIErrorCLIExtensionInstallErrorDeviceCodeErrorEntryNotFoundErrorGatedRepoErrorHfHubHTTPError
HfUriErrorLocalEntryNotFoundErrorLocalTokenNotFoundErrorOfflineModeIsEnabled	OIDCErrorRemoteEntryNotFoundErrorRepositoryNotFoundErrorRevisionNotFoundErrorerrorreturnc                    | j         r| j                                         nd}| j        r| d| j         d}n| d}|dz  }|dz  }| j        .| j         r| j         dk    r
d| j          nd	}|d
| j         | z  }n|dz  }|S )N
Repository '' not found.z not found.ze
If the repo is private, make sure you are authenticated and your token has the required permissions.z-
If the repo does not exist, create it with: modelz --type  zhf repos create zhf repos create <repo_id>)	repo_type
capitalizerepo_id)r   labelmsg	type_flags       _/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/huggingface_hub/cli/_errors.py_format_repo_not_foundr"   &   s    ,1OMEO&&(((E} $55%-555###ssC;;C} 49Oj[bHbHb0u000hj	<%-<<<<**J    c                 |    | j         r| j         nd}| j        r d|                                 d| j         dS d| dS )N
repositoryzAccess denied. r   z' requires approval.zAccess denied. This z requires approval.)r   r   r   r   r   s     r!   _format_gated_repor'   8   sW    $@EOOLE} [Z!1!1!3!3ZZu}ZZZZ<%<<<<r#   c                 b    | j         rd| j          d}d| j          }nd}d}|dz  }|d| z  }|S )NzBucket 'r   zhf buckets create zBucket not found.zhf buckets create <bucket_id>zg
If the bucket is private, make sure you are authenticated and your token has the required permissions.z/
If the bucket does not exist, create it with: )	bucket_id)r   r   cmds      r!   _format_bucket_not_foundr+   ?   s\     .666645?44!-uuCCcCCCCJr#   c                     | j         r| j         nd}| j        rt          | j        j                  nd }| j        rd| d| j         d}nd| d}|r|d| z  }|S )Nr%   zFile not found in r   '..z
URL: )r   responsestrurlr   )r   r   r1   r   s       r!   _format_entry_not_foundr2   K   s    $@EOOLE%*^
=#en 
!
!
!C} ,=5==EM===+5+++
 Jr#   c                 (    | j         }|d| S d|  S )NzLocal entry not found. )	__cause__)r   causes     r!   _format_local_entry_not_foundr6   W   s+    OE0000,U,,,r#   c                 X    | j         r| j         nd}| j        rd| d| j         dS d| dS )Nr%   zRevision not found in r   r-   z. Check the revision parameter.)r   r   r&   s     r!   _format_revision_not_foundr8   ^   sK    $@EOOLE} CBBBBBBBJEJJJJr#   c                      t          |           S )z%No traceback, just the error message.r0   r   s    r!   _format_cli_errorr<   e   s    u::r#   c                     | j         Jd                    t          j        t	          | j                   | j         | j         j                            nd}| d|  S )a0  Format a CLI extension installation error.

    The error is likely to be a tricky subprocess error to investigate. In this specific case we want to format the
    traceback of the root cause while keeping the "nicely formatted" error message of the CLIExtensionInstallError
    as a 1-line message.
    Nr   
)r4   join	tracebackformat_exceptiontype__traceback__)r   cause_tbs     r!   #_format_cli_extension_install_errorrE   j   s`     ?& 		*4+@+@%/SXSbSpqqrrr 
 !!%!!!r#   c                      t          |           S Nr:   r;   s    r!   <lambda>rH   z   s    E

 r#   c                     dS )Nz)Not logged in. Run 'hf auth login' first. )_s    r!   rH   rH      s    'R r#   c                     d|  S )NzOIDC Exchange failed. rJ   r;   s    r!   rH   rH      s    =e== r#   c                     d|  S )NzLogin failed: rJ   r;   s    r!   rH   rH      s    #;E#;#; r#   c                      t          |           S rG   r:   r;   s    r!   rH   rH      s    c%jj r#   c                      t          |           S rG   r:   r;   s    r!   rH   rH      s    #e** r#   c                 &    d| j          d| j         S )NzInvalid HF URI: z. )urir   r;   s    r!   rH   rH      s    IIIeiII r#   c                     d|  S )NzInvalid value. rJ   r;   s    r!   rH   rH      s    777 r#   .CLI_ERROR_MAPPINGSc                 ~    t                                           D ]"\  }}t          | |          r ||           c S #d S rG   )rS   items
isinstance)r   exc_type	formatters      r!   format_known_exceptionrY      sT    17799 $ $)eX&& 	$9U#####	$4r#   )$__doc__r@   collections.abcr   huggingface_hub.errorsr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r0   r"   r'   r+   r2   r6   r8   r<   rE   
ValueErrorrS   dictrB   	Exception__annotations__rY   rJ   r#   r!   <module>ra      sK   $ # #     $ $ $ $ $ $                                 &"9 c    $=n = = = = =	$7 	C 	 	 	 		#; 	 	 	 	 	-)@ -S - - - -K&; K K K K KX #    
"/G "C " " " "A22A &A 1	A
 3A 5A RRA ==A ;;A 5A :A 00A ,,A IIA 77A  A!A" #A Di(38*<<=   *) d
      r#   