Ë
    rPêjAB  ã                   óª  — d 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mZ ddlmZ ddlmZmZ d	d
lmZmZmZmZmZmZmZmZ d	dlmZmZ d	dlmZm Z   G d„ de!ejD                  «      Z# G d„ de!ejD                  «      Z$ddhZ%ee& edd	¬«      f   Z'de!dz  dedz  de!dz  fd„Z(ee)e!   dz   edd¬«      f   Z* ejV                  d«      Z,dede!de!de!fd „Z-d!ede!d"e)e!   dz  de!fd#„Z. ed$¬«      Z/e/ja                  d%g d&¢¬'«      e#jb                  e$jd                  dd(ejf                  dfd)ed*ee# ed+d,d-¬«      f   d.ee$ ed/d0d1¬«      f   d2ed3ed4ed5eddfd6„«       Z4e/ja                  d7d8d9g¬'«      ejf                  dfd)ed:e'd4ed5eddf
d;„«       Z5e/ja                  d<g d=¢¬'«      ddd>dejf                  dfd)ed?ee! ed@dA¬«      f   dee!dz   edBdC¬«      f   deedz   edDdE¬«      f   dFee6 edGdHdI¬«      f   d"e*d4ed5eddfdJ„«       Z7e/ja                  dKg dL¢¬'«      dddejf                  dfd)ed:e'dee!dz   edBdM¬«      f   deedz   edDdN¬«      f   d"e*d4ed5eddfdO„«       Z8e/ja                  dPg dQ¢¬'«      dddejf                  dfd)ed:e'dRee! edS¬«      f   dee!dz   edBdT¬«      f   deedz   edDdU¬«      f   d"e*d4ed5eddfdV„«       Z9e/ja                  dWdXdYg¬'«      dd>ejf                  dfd)ed:e'dKee!dz   edZd[¬«      f   d\ee6 ed]d^d_¬«      f   d4ed5eddfd`„«       Z:e/ja                  dadbdcg¬'«      dd>ejf                  dfd)ed:e'dKee!dz   edZdd¬«      f   d\ee6 ed]d^d_¬«      f   d4ed5eddfde„«       Z;e/ja                  dfdgg¬'«      ejf                  dfd)ed:e'dhee! edi¬«      f   d4ed5eddfdj„«       Z<e/ja                  dkdldmg¬'«      dd>ejf                  dfd)ed:e'dKee!dz   edZdn¬«      f   d\ee6 ed]d^d_¬«      f   d4ed5eddfdo„«       Z=e/ja                  dpdqg¬'«      ejf                  dfd)ed:e'd4ed5eddf
dr„«       Z>y)szYContains commands to interact with discussions and pull requests on the Hugging Face Hub.é    N)ÚPath)Ú	Annotated)Úunquote)Ú	constants)ÚCLIError)Ú_ATTACHMENT_CONTENT_TYPESÚHfApié   )Ú	AuthorOptÚLimitOptÚ	RepoIdArgÚRepoTypeÚRepoTypeOptÚTokenOptÚ
get_hf_apiÚtyper_factory)ÚArgumentÚOption)Ú_dataclass_to_dictÚoutc                   ó    — e Zd ZdZdZdZdZdZy)ÚDiscussionStatusÚopenÚclosedÚmergedÚdraftÚallN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   © ó    úd/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/huggingface_hub/cli/discussions.pyr   r   +   s   „ Ø€DØ€FØ€FØ€EØ
�Cr"   r   c                   ó   — e Zd ZdZdZdZy)ÚDiscussionKindr   Ú
discussionÚpull_requestN)r   r   r    r   r&   r'   r!   r"   r#   r%   r%   3   s   „ Ø
€CØ€JØ!�Lr"   r%   r   r   z&The discussion or pull request number.)ÚhelpÚminÚbodyÚ	body_fileÚreturnc                 ó¸   — | �|�t        j                  d«      ‚|�>t        |«      dk(  rt        j                  j                  «       S |j                  d¬«      S | S )zFResolve body text from --body or --body-file (supports '-' for stdin).z'Cannot use both --body and --body-file.ú-zutf-8)Úencoding)ÚclickÚBadParameterÚstrÚsysÚstdinÚreadÚ	read_text)r*   r+   s     r#   Ú
_read_bodyr7   I   s[   € àÐ˜IÐ1Ü× Ñ Ð!JÓKÐKØÐÜˆy‹>˜SÒ Ü—9‘9—>‘>Ó#Ð#Ø×"Ñ"¨GÐ"Ó4Ð4Ø€Kr"   z--attachzÂAttach an image, video or audio file, as 'FILE' or 'FILE#alt text'. A '![alt](FILE)' reference in the body is replaced by the uploaded file, other files are appended. Can be used multiple times.)r(   zD!\[([^\]]*)\]\(<?((?:[^()<>\n]|\([^()<>\n]*\))+?)>?(?:\s+"[^"]*")?\)ÚpathÚurlÚaltc                 óž   — t         | j                  j                  «          j                  d«      d   xdk(  r
 d|› d|› d�S dk(  rd|› d	�S 	 |S )
z=Markdown inserted by the Hub web editor for an uploaded file.ú/r   Úimagez![z](ú)Úaudioz<audio controls src="z
"></audio>)r   ÚsuffixÚlowerÚ	partition)r8   r9   r:   s      r#   Ú_media_markdownrC   b   sY   € ä
# D§K¡K×$5Ñ$5Ó$7Ñ
8×
BÑ
BÀ3Ó
GÈÑ
JÝØ˜�u˜B˜s˜e 1Ð%Ð%ÛØ*¨3¨%¨zÐ:Ð:ØàˆJr"   ÚapiÚattachc           
      óD  ‡‡— |s|S i }|D ]Å  }t        |«      j                  «       r|ddfn|j                  d«      \  }}}t        |«      j                  «       }|j                  «       st	        d|› d�«      ‚|j
                  j                  «       t        vr%t	        d|› ddj                  t        «      › d�«      ‚|xs |j                  ||<   ŒÇ |D �ci c]  }|| j                  |«      “Œ c}Št        «       Šd	t        j                  t           d
t        fˆˆfd„}	t        j!                  |	|«      j#                  «       g}
|
|j%                  «       D ��cg c]  \  }}|‰vsŒt'        |‰|   |«      ‘Œ c}}z  }
dj                  d„ |
D «       «      S c c}w c c}}w )zgUpload --attach files and embed them in the body: replace `![alt](FILE)` references, append the others.Ú ú#zAttachment not found: 'z'.zCannot attach 'z': supported formats are z, ú.Úmatchr,   c                 óò   •— t        t        | j                  d«      «      «      j                  «       }|‰vr| j                  d«      S ‰j	                  |«       t        |‰|   | j                  d«      ¬«      S )Né   r   r
   )r:   )r   r   ÚgroupÚresolveÚaddrC   )rJ   r8   Ú
referencedÚurlss     €€r#   Ú_replacez_attach_files.<locals>._replace   s`   ø€ Ü”G˜EŸK™K¨›NÓ+Ó,×4Ñ4Ó6ˆØ�tÑØ—;‘;˜q“>Ð!Ø�‰�tÔÜ˜t T¨$¡Z°U·[±[À³^ÔDÐDr"   z

c              3   ó&   K  — | ]	  }|sŒ|–— Œ y ­w)Nr!   )Ú.0Úparts     r#   ú	<genexpr>z _attach_files.<locals>.<genexpr>ˆ   s   è ø€ Ò6 ²”tÑ6ùs   ‚Š)r   Úis_filerB   rN   r   r@   rA   r   ÚjoinÚstemÚupload_attachmentÚsetÚreÚMatchr2   Ú_IMAGE_EMBED_REGEXÚsubÚstripÚitemsrC   )rD   r*   rE   ÚaltsÚvalueÚfileÚ_r:   r8   rR   ÚpartsrP   rQ   s              @@r#   Ú_attach_filesrg   n   s‡  ù€ áØˆØ€DØò &ˆÜ*.¨u«+×*=Ñ*=Ô*?˜˜r 2‘ÀUÇ_Á_ÐUXÓEY‰ˆˆa�Ü�D‹z×!Ñ!Ó#ˆØ�|‰|Œ~ÜÐ4°T°F¸"Ð=Ó>Ð>Ø�;‰;×ÑÓÔ&?Ñ?Ü˜_¨T¨FÐ2KÈDÏIÉIÔVoÓLpÐKqÐqrÐsÓtÐtØÒ%˜DŸI™IˆˆTŠ
ð&ð ;?Ö?°$ˆD�#×'Ñ'¨Ó-Ñ-Ò?€Dä“€JðEœŸ™¤™ð E¬#ö Eô  ×#Ñ# H¨dÓ3×9Ñ9Ó;Ð<€EØ	ÀdÇjÁjÃl×m¹¸¸sÐVZÐblÒVlŒo˜d D¨¡J°Õ4ÓmÑm€EØ�;‰;Ñ6¨Ô6Ó6Ð6ùò @ùó ns   ÃFÅFÅ'Fz0Manage discussions and pull requests on the Hub.z	list | ls)z%hf discussions list username/my-modelzIhf discussions list username/my-model --kind pull_request --status mergedzFhf discussions list username/my-dataset --type dataset --status closedzBhf discussions list username/my-model --author alice --format json)Úexamplesé   Úrepo_idÚstatusz-sz--statusz4Filter by status (open, closed, merged, draft, all).Úkindz-kz--kindz/Filter by kind (discussion, pull_request, all).ÚauthorÚlimitÚ	repo_typeÚtokenc                 ó  — t        |¬«      }|t        j                  k(  rd}n|t        j                  k(  rd}nd}|t        j
                  k(  rd}	n|j                  }	g }
|j                  | ||	||j                  ¬«      D ]O  }|j                  t        v r|j                  |j                  k7  rŒ/|
j                  |«       t        |
«      |k\  sŒO n |
D �cg c]  }t        |«      ‘Œ }}t        j                  |g d¢d¬«       yc c}w )	z-List discussions and pull requests on a repo.©rp   r   r   N)rj   rm   Údiscussion_typeÚdiscussion_statusro   )ÚnumÚtitleÚis_pull_requestrk   rm   Ú
created_atru   )ÚheadersÚid_key)r   r   r   r   r%   r   rc   Úget_repo_discussionsÚ_CLIENT_SIDE_STATUSESrk   ÚappendÚlenr   r   Útable)rj   rk   rl   rm   rn   ro   rp   rD   Ú
api_statusÚapi_discussion_typeÚdiscussionsÚdra   s                r#   Údiscussion_listr„   Ž   s	  € ôB ˜5Ô
!€Cð Ô!×&Ñ&Ò&Ø‰
Ø	Ô#×*Ñ*Ò	*Ø‰
àˆ
ð Œ~×!Ñ!Ò!Ø"Ñà"Ÿj™jÐà€KØ×%Ñ%ØØØ+Ø$Ø—/‘/ð &ó ò ˆð �<‰<Ô0Ñ0°Q·X±XÀÇÁÒ5MØØ×Ñ˜1ÔÜˆ{Ó˜uÓ$Ùðð -8Ö8 qÔ Õ"Ð8€EÐ8Ü‡I�IØÚUØöùò 9s   ÃDÚinfoz'hf discussions info username/my-model 5z5hf discussions info username/my-model 5 --format jsonru   c                 ó‚   — t        |¬«      }|j                  | ||j                  ¬«      }t        j                  |«       y)z,Get info about a discussion or pull request.rr   ©rj   Údiscussion_numro   N)r   Úget_discussion_detailsrc   r   Údict©rj   ru   ro   rp   rD   Údetailss         r#   Údiscussion_infor�   Õ   s>   € ô ˜5Ô
!€CØ×(Ñ(ØØØ—/‘/ð )ó €Gô
 ‡H�HˆWÕr"   Úcreate)z<hf discussions create username/my-model --title "Bug report"zWhf discussions create username/my-model --title "Feature request" --body "Please add X"zIhf discussions create username/my-model --title "Fix typo" --pull-requestzUhf discussions create username/my-dataset --type dataset --title "Data quality issue"z€hf discussions create username/my-model --title "Fix rendering" --pr --attach "./before.png#Before the fix" --attach ./after.pngFrv   z--titlez,The title of the discussion or pull request.z--bodyz$The description (supports Markdown).z--body-filez4Read the description from a file. Use '-' for stdin.r'   z--pull-requestz--prz.Create a pull request instead of a discussion.c                 óD  — t        |¬«      }t        |t        ||«      xs d|«      }	|j                  | ||	|j                  |¬«      }
|rdnd}|rd|
j
                  › �nd}t        j                  d|› d	|
j
                  › d
| › �|
j
                  |
j                  |¬«       y)z2Create a new discussion or pull request on a repo.rr   rG   )rj   rv   Údescriptionro   r'   zpull requestr&   zrefs/pr/NzCreated z #z on )ru   r9   Úref)	r   rg   r7   Úcreate_discussionrc   ru   r   Úresultr9   )rj   rv   r*   r+   r'   rE   ro   rp   rD   r�   r&   rl   r‘   s                r#   Údiscussion_creater”   ì   s§   € ô\ ˜5Ô
!€CÜ ¤Z°°iÓ%@Ò%FÀBÈÓO€KØ×&Ñ&ØØØØ—/‘/Ø!ð 'ó €Jñ *‰>¨|€DÙ)5ˆH�Z—^‘^Ð$Ñ
%¸4€CÜ‡J�J�˜$˜˜r *§.¡.Ð!1°°g°YÐ?ÀZÇ^Á^ÐYc×YgÑYgÐmpÖqr"   Úcomment)zIhf discussions comment username/my-model 5 --body "Thanks for reporting!"z9hf discussions comment username/my-model 5 --body "LGTM!"zUhf discussions comment username/my-model 5 --body "Here is a demo:" --attach demo.mp4z%The comment text (supports Markdown).z0Read the comment from a file. Use '-' for stdin.c                 óú   — t        |¬«      }t        |t        ||«      xs d|«      }|st        j                  d«      ‚|j                  | |||j                  ¬«       t        j                  d|› d| › �|| ¬«       y)	z(Comment on a discussion or pull request.rr   rG   z3Either --body, --body-file or --attach is required.©rj   rˆ   r•   ro   zCommented on #ú in ©ru   ÚrepoN)	r   rg   r7   r0   r1   Úcomment_discussionrc   r   r“   )	rj   ru   r*   r+   rE   ro   rp   rD   r•   s	            r#   Údiscussion_commentrœ   (  s   € ô< ˜5Ô
!€CÜ˜C¤¨D°)Ó!<Ò!BÀÀFÓK€GÙÜ× Ñ Ð!VÓWÐWØ×ÑØØØØ—/‘/ð	 ô ô ‡J�J� ˜u D¨¨	Ð2¸À'ÖJr"   Úedit)zHhf discussions edit username/my-model 5 abc123 --body "Updated comment."zChf discussions edit username/my-model 5 abc123 --body-file fixed.mdzjhf discussions edit username/my-model 5 abc123 --body "Fixed: ![result](./after.png)" --attach ./after.pngÚ
comment_idzLThe ID of the comment to edit (see 'hf discussions info ... --format json').z)The new comment text (supports Markdown).z4Read the new comment from a file. Use '-' for stdin.c                 ó   — t        ||«      }|€t        j                  d«      ‚t        |¬«      }	t	        |	||«      }|	j                  | ||||j                  ¬«       t        j                  d|› d|› d| › �|| |¬«       y)	z9Edit an existing comment on a discussion or pull request.Nz)Either --body or --body-file is required.rr   )rj   rˆ   rž   Únew_contentro   zEdited comment z on #r˜   )ru   rš   rž   )	r7   r0   r1   r   rg   Úedit_discussion_commentrc   r   r“   )
rj   ru   rž   r*   r+   rE   ro   rp   r    rD   s
             r#   Údiscussion_editr¢   S  s�   € ôH ˜T 9Ó-€KØÐÜ× Ñ Ð!LÓMÐMÜ
˜5Ô
!€CÜ  [°&Ó9€KØ×ÑØØØØØ—/‘/ð  ô ô ‡J�J�  ¨E°#°°d¸7¸)ÐDÈ#ÐT[ÐhrÖsr"   Úclosez(hf discussions close username/my-model 5zIhf discussions close username/my-model 5 --comment "Closing as resolved."z	--commentz)An optional comment to post when closing.Úyesz--yesz-yzSkip confirmation prompt.c                 óÔ   — t        j                  d|› d| › d�|¬«       t        |¬«      }|j                  | |d||j                  ¬«       t        j
                  d|› d	| › �|| ¬
«       y)z#Close a discussion or pull request.zClose #ú on 'ú'?©r¤   rr   r   ©rj   rˆ   Ú
new_statusr•   ro   zClosed #r˜   r™   N©r   Úconfirmr   Úchange_discussion_statusrc   r“   ©rj   ru   r•   r¤   ro   rp   rD   s          r#   Údiscussion_closer¯   †  sp   € ô: ‡K�K�'˜#˜˜e G 9¨BÐ/°SÕ9Ü
˜5Ô
!€CØ× Ñ ØØØØØ—/‘/ð !ô ô ‡J�J�˜#˜˜d 7 )Ð,°#¸GÖDr"   Úreopenz)hf discussions reopen username/my-model 5zZhf discussions reopen username/my-model 5 --comment "Reopening for further investigation."z+An optional comment to post when reopening.c                 óÔ   — t        j                  d|› d| › d�|¬«       t        |¬«      }|j                  | |d||j                  ¬«       t        j
                  d|› d	| › �|| ¬
«       y)z+Reopen a closed discussion or pull request.zReopen #r¦   r§   r¨   rr   r   r©   z
Reopened #r˜   r™   Nr«   r®   s          r#   Údiscussion_reopenr²   ¯  sp   € ô: ‡K�K�(˜3˜%˜u W I¨RÐ0°cÕ:Ü
˜5Ô
!€CØ× Ñ ØØØØØ—/‘/ð !ô ô ‡J�J�˜C˜5  W IÐ.°C¸gÖFr"   Úrenamez9hf discussions rename username/my-model 5 "Updated title"Ú	new_titlezThe new title.c                 ó˜   — t        |¬«      }|j                  | |||j                  ¬«       t        j                  d|› d| › �|| |¬«       y)z$Rename a discussion or pull request.rr   )rj   rˆ   r´   ro   z	Renamed #r˜   )ru   rš   rv   N)r   Úrename_discussionrc   r   r“   )rj   ru   r´   ro   rp   rD   s         r#   Údiscussion_renamer·   Ø  sR   € ô& ˜5Ô
!€CØ×ÑØØØØ—/‘/ð	 ô ô ‡J�J�˜3˜%˜t G 9Ð-°3¸WÈIÖVr"   Úmergez(hf discussions merge username/my-model 5zEhf discussions merge username/my-model 5 --comment "Merging, thanks!"z)An optional comment to post when merging.c                 óÒ   — t        j                  d|› d| › d�|¬«       t        |¬«      }|j                  | |||j                  ¬«       t        j
                  d|› d| › �|| ¬	«       y
)zMerge a pull request.zMerge #r¦   r§   r¨   rr   r—   zMerged #r˜   r™   N)r   r¬   r   Úmerge_pull_requestrc   r“   r®   s          r#   Údiscussion_merger»   õ  sm   € ô: ‡K�K�'˜#˜˜e G 9¨BÐ/°SÕ9Ü
˜5Ô
!€CØ×ÑØØØØ—/‘/ð	 ô ô ‡J�J�˜#˜˜d 7 )Ð,°#¸GÖDr"   Údiffz'hf discussions diff username/my-model 5c                 óÚ   — t        |¬«      }|j                  | ||j                  ¬«      }|j                  r t	        j
                  |j                  «       yt	        j
                  d«       y)z Show the diff of a pull request.rr   r‡   zNo diff available.N)r   r‰   rc   r¼   r   Útextr‹   s         r#   Údiscussion_diffr¿     sV   € ô ˜5Ô
!€CØ×(Ñ(ØØØ—/‘/ð )ó €Gð
 ‡|‚|Ü�‰�—‘Õä�‰Ð%Õ&r"   )?Ú__doc__Úenumr\   r3   Úpathlibr   Útypingr   Úurllib.parser   r0   Úhuggingface_hubr   Úhuggingface_hub.errorsr   Úhuggingface_hub.hf_apir   r	   Ú
_cli_utilsr   r   r   r   r   r   r   r   Ú
_frameworkr   r   Ú_outputr   r   r2   ÚEnumr   r%   r|   ÚintÚDiscussionNumArgr7   ÚlistÚ	AttachOptÚcompiler^   rC   rg   Údiscussions_cliÚcommandr   r   Úmodelr„   r�   Úboolr”   rœ   r¢   r¯   r²   r·   r»   r¿   r!   r"   r#   ú<module>rÕ      sÿ  ðñ `ã Û 	Û 
Ý Ý Ý  ã å %Ý +ß C÷	÷ 	ó 	÷ )ß ,ô�s˜DŸI™Iô ô"�S˜$Ÿ)™)ô "ð " 7Ð+Ð ð ØÙØ5ØôðñÐ ð�S˜4‘Zð ¨D°4©Kð ¸CÀ$¹Jó ð Øˆ�I�ÑÙ
Øðlôðñ	€	ð  �R—Z‘ZÐ gÓhÐ ð	˜$ð 	 Sð 	¨sð 	°só 	ð7�uð 7 Cð 7°°c±¸TÑ1Að 7Àcó 7ñ:  Ð%WÔX€ð ×ÑØòð ó ð$ 	×Ñð 	×ÑØØØ%Ÿ^™^Øñ+;Øð;àØÙØØØGô	
ð	ñð;ð ØÙØØØBô	
ð	ñð;ð$ ð%;ð& ð';ð( ð);ð* ð+;ð, 
ò-;óð;ð| ×ÑØ
à1Ø?ðð ó ð &Ÿ^™^Øñ	Øðà	ðð ðð ð	ð
 
òóðð  ×ÑØòð ó 	ð2 	ð 	ð 	ØØ%Ÿ^™^ØñC/rØð/ràØÙØØ?ô	
ð	ñð/rð Øˆd‰
ÙØØ7ô	
ð	ñð/rð  Øˆt‰ÙØØGô	
ð	ñð!/rð. ØÙØØØAô	
ð	ñð//rð> ð?/rð@ ðA/rðB ðC/rðD 
òE/ró	ð/rðd ×ÑØòð ó ð" 	ð 	ØØ%Ÿ^™^Øñ' KØð Kà	ð Kð Øˆd‰
ÙØØ8ô	
ð	ñð Kð Øˆt‰ÙØØCô	
ð	ñð Kð" ð# Kð$ ð% Kð& ð' Kð( 
ò) Kóð KðF ×ÑØ
òð ó ð. 	ð 	ØØ%Ÿ^™^Øñ3(tØð(tà	ð(tð ØÙØ_ô	
ð	ñð(tð Øˆd‰
ÙØØ<ô	
ð	ñð(tð  Øˆt‰ÙØØGô	
ð	ñð!(tð. ð/(tð0 ð1(tð2 ð3(tð4 
ò5(tóð(tðV ×ÑØà2ØSðð ó ð  	ð 	Ø%Ÿ^™^Øñ'EØðEà	ðEð Øˆd‰
ÙØØ<ô	
ð	ñðEð 
ØÙØØØ,ô	
ð	ñ
ðEð$ ð%Eð& ð'Eð( 
ò)EóðEðD ×ÑØà3Ødðð ó ð  	ð 	Ø%Ÿ^™^Øñ'GØðGà	ðGð Øˆd‰
ÙØØ>ô	
ð	ñðGð 
ØÙØØØ,ô	
ð	ñ
ðGð$ ð%Gð& ð'Gð( 
ò)GóðGðD ×ÑØàCðð ó ð &Ÿ^™^ØñWØðWà	ðWð ØÙØ!ô	
ð	ñðWð ðWð ðWð 
òWóðWð. ×ÑØà2ØOðð ó ð  	ð 	Ø%Ÿ^™^Øñ'EØðEà	ðEð Øˆd‰
ÙØØ<ô	
ð	ñðEð 
ØÙØØØ,ô	
ð	ñ
ðEð$ ð%Eð& ð'Eð( 
ò)EóðEðB ×ÑØ
à1ðð ó ð &Ÿ^™^Øñ	'Øð'à	ð'ð ð'ð ð	'ð
 
ò'óñ'r"   