
    h                         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m	Z	 d dl
Ze	d             Zd Zd Zej        fdZd Zd	 Zd
 Zd ZddZdS )    )print_functionN)contextmanagerc               #   (  K   t          j        t           j                  } t          j         t           j        t           j                   	 d V  t          j         t           j        |            d S # t          j         t           j        |            w xY wN)signal	getsignalSIGINTSIG_DFL)original_sigint_handlers    l/home/visionen/pythonvenv/lib/python3.11/site-packages/youtube_upload-0.8.0-py3.11.egg/youtube_upload/lib.pydefault_sigintr      ss      $.v}==
M&-000>fm%<=====fm%<====s   A0 0!Bc                  (    t          j                    S r   )localegetpreferredencoding     r   get_encodingr      s    &(((r   c                    t          j                    }t          | d          r2| r.|dk    r(|                     |                              d          n| S t          | t                    rt                              |           S | S )z;Re-encode string from the default system encoding to UTF-8.decodezUTF-8)r   r   hasattrr   encode
isinstancebytes)scurrents     r   to_utf8r      s~    )++Gq( 56T7g;M;M!!((111STU	Au		 ||Ar   c                 (    t          | |           dS )zWrite obj to standard error.)fileN)print)objfds     r   debugr"   "   s    	#Br   c                     	  ||i | dS # t          |                                           $ rD}t          d                    |j        j        |                     | |j                 cY d}~S d}~ww xY w)z
    Catch exceptions on fun(*args, **kwargs) and return the exit code specified
    in the exit_codes dictionary. Return 0 if no exception is raised.
    r   z	[{0}] {1}N)tuplekeysr"   format	__class____name__)
exit_codesfunargskwargsexcs        r   catch_exceptionsr.   &   s    
)TVq""## ) ) )k  !7==>>>#-((((((()s    $A49A/)A4/A4c                 *    |                                  S )z!Return first element in iterable.)next)its    r   firstr2   2   s    7799r   c                 z    | r8d |                      d          D             }t          d |D                       S dS )z9Return dictionary from string "key1=value1, key2=value2".c                 6    g | ]}|                                 S r   )strip).0r   s     r   
<listcomp>z"string_to_dict.<locals>.<listcomp>9   s     666q666r   ,c              3   @   K   | ]}|                     d           V  dS )=N)split)r6   pairs     r   	<genexpr>z!string_to_dict.<locals>.<genexpr>:   s,      66DJJsOO666666r   N)r;   dict)stringpairss     r   string_to_dictrA   6   sP     766FLL$5$5666666666667 7r   c                     | D ]E}t           j                            ||          }t           j                            |          r|c S FdS )zQGet the first existing filename of relative_path seeking on prefixes directories.N)ospathjoinexists)prefixesrelative_pathprefixrD   s       r   get_first_existing_filenamerJ   <   sT      w||FM227>>$ 	KKK	 r   c           	          d}	 	  |             S # t          |          $ r}|dz  }t          |          |vr|t          |          t          j        j        k    r|j        j        dk     r||||k    rt          d           |t          j	        dd|z            }d
                    ||pdt          |          j        t          |          pdd	|z  
          }t          |           t          j        |           Y d}~nd}~ww xY w)zERun function and retry on some exceptions (with exponential backoff).r      i  Nz&[Retryable errors] Retry limit reached   zf[Retryable error {current_retry}/{total_retries}] {error_type} ({error_msg}). Wait {wait_time} seconds-z%.1f)current_retrytotal_retries
error_type	error_msg	wait_time)r$   typegoogleapiclienterrors	HttpErrorrespstatusr"   randomuniformr&   r(   strtimesleep)r*   retriable_exceptionsmax_retriesretryr-   secondsmessages          r   r_   r_   C   sH   E$	$355L)** 	$ 	$ 	$QJECyy 444	co4>>>38?UXCXCX	(U[-@-@>???	 .AuH55KLRF"'"-"4#Cyy1!#hho#$w. MS M M  g
7########+	$$s   	 DC DDr   )
__future__r   rC   sysr   rZ   r]   r   
contextlibr   googleapiclient.errorsrU   r   r   r   stderrr"   r.   r2   rA   rJ   r_   r   r   r   <module>ri      s   % % % % % % 				 



     % % % % % %    > > >) ) )   *    
) 
) 
)  7 7 7  $ $ $ $ $ $r   