
    Mh                       U d 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
mZ ddlmZ ddlmZmZmZmZmZ ddlZddlmZ ej        j        Zej        d	k    s%ej        d
k    rej                            d          sdZndZ eedd          ZedQdRd            Z edSd            Z dQdTdZ dUdZ!dVdZ"i Z#de$d<   dWd Z%dUd!Z&dXd"Z'dVd#Z(dVd$Z)dVd%Z* e d&          Z+de$d'<   dZ,d(e$d)<   ej-        d*k    re+rej.        /                    d+d          Z, e!            rVej-        d*k    re+s e0 eej        d,d                    gZ1ns ej2        edd-.          3                    ej4                  Z1nG ed/           ej-        d*k    r-e,r ee,d          gZ1n! e0 eej        d,d                    gZ1nd0d1gZ1 e0 eej        d,d                    gZ5d2e$d3<   dYd5Z6 e0 eej        d6d                    gZ7d2e$d7<    e!            rDej-        d*k    re+se7dd         Z8n_ ej9        edd-.          3                    ej4                  Z8n3ej-        d*k    r$e,r e0 ee,d                    gZ8ne7dd         Z8nd8d9gZ8dZd:Z:dWd;Z;d[d\d?Z<d[d\d@Z=ej        d	k    re<Z>ne=Z>d]d^dCZ?d_dFZ@d_dGZAd`dIZB ejC        dJdK          D                                dLv ZEedQdadO            ZFdbdPZGdS )czPath utility functions.    )annotationsN)contextmanager)Path)AnyIteratorLiteralOptionaloverload   )deprecationwin32darwinz/opt/homebrewJupyterjupyter	UF_HIDDENi   Fnamestrdefaultboolreturnc                    d S N r   r   s     R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jupyter_core/paths.pyenvsetr   )   s    69c    Literal[None]Optional[bool]c                    d S r   r   r   s     r   r   r   -   s    ADr   c                n    | t           j        vr|S t           j        |                                          dvS )a%  Return the boolean value of a given environment variable.

    An environment variable is considered set if it is assigned to a value
    other than 'no', 'n', 'false', 'off', '0', or '0.0' (case insensitive)

    If the environment variable is not defined, the default value is returned.
    )nonfalseoff0z0.0)osenvironlowerr   s     r   r   r   1   s5     2::d!!##+RRRr   c                 "    t          dd          S )zDetermine if platformdirs should be used for system-specific paths.

    We plan for this to default to False in jupyter_core version 5 and to True
    in jupyter_core version 6.
    JUPYTER_PLATFORM_DIRSF)r   r   r   r   use_platform_dirsr,   ?   s     )5111r   c                     t          d                                          } t          t          |                                                     S )z'Get the real path of the home directory~)r   
expanduserr   resolve)homedirs    r   get_home_dirr2   H   s;    3ii""$$G tG}}$$&&'''r   zdict[str, str]_dtempspathc                :   t          |                                           }|                                s1||j        k    r&|j        }|                                s||j        k    &	 |                                t          j                    k    S # t          $ r Y nw xY wt          t
          d          rH	 |	                                }|j
        t          j                    k    S # t          t          f$ r Y nw xY wt          j        |t
          j                  S )z3Return whether the current user owns the given pathgeteuid)r   r0   existsparentownerr'   getlogin	Exceptionhasattrstatst_uidr6   NotImplementedErrorOSErroraccessW_OK)r4   psts      r   	_do_i_ownrE   S   s
   T

A hhjj Q!(]]H hhjj Q!(]]
wwyyBKMM))    r9 	B9
,,#W- 	 	 	D	
 9Q   s$   ((B 
BB7/C' 'C;:C;c                    dt           j        v rt          d          S t          j        t          j        k    rt          t          j                  rdS dt           j        v rnt          j                            t           j        d                   r?t           j                            dd          dk    rt          t          j                  rdS dS )zRDetermine if environment-level paths should take precedence over user-level paths.JUPYTER_PREFER_ENV_PATHTCONDA_PREFIXCONDA_DEFAULT_ENVbaseF)	r'   r(   r   sysprefixbase_prefixrE   
startswithgetr   r   r   prefer_environment_over_userrP   n   s     !BJ../000 zS_$$3:)>)>$t 	"*$$J!!"*^"<== 	%JNN.776AAcj!! B t5r   c                    	 t           |          S # t          $ r' t          j        | dz             x}t           | <   |cY S w xY w)zMake or reuse a temporary directory.

    If this is called with the same name in the same process, it will return
    the same directory.
    -)rL   )r3   KeyErrortempfilemkdtemp)r   ds     r   _mkdtemp_oncerW      sU    t}   $,D3J????GDMs    .A A c                 *   t           j        } |                     d          rt          d          S |                     d          r| d         S t	                      rt          j        t          d          S t                      }t          |d          S )zGet the Jupyter config directory for this platform and user.

    Returns JUPYTER_CONFIG_DIR if defined, otherwise the appropriate
    directory for the platform.
    JUPYTER_NO_CONFIGzjupyter-clean-cfgJUPYTER_CONFIG_DIRF	appauthorz.jupyter)
r'   r(   rO   rW   r,   platformdirsuser_config_dirAPPNAMEr2   pjoin)envhome_dirs     r   jupyter_config_dirrc      s     *C
ww"## 20111
ww#$$ )'(( F+GuEEEE~~H:&&&r   c                    t           j        } |                     d          r| d         S t                      rt	          j        t          d          S t                      }t          j	        dk    rt          t          |dd                    S t          j	        dk    rmt           j                            dd	          }|r/t          t          |d
                                                    S t          t                      d          S |                     dd	          }|st          |dd          }t          |d
          S )zGet the config directory for Jupyter data files for this platform and user.

    These are non-transient, non-configuration files.

    Returns JUPYTER_DATA_DIR if defined, else a platform-appropriate path.
    JUPYTER_DATA_DIRFr[   r   Libraryr   r   APPDATANr   dataXDG_DATA_HOMEz.localshare)r'   r(   rO   r,   r]   user_data_dirr_   r2   rK   platformr   r   r0   r`   rc   )ra   homeappdataxdgs       r   jupyter_data_dirrp      s"    *C
ww!"" '%&& D)'UCCCC>>D
|x4i33444
|w*..D11 	;tGY//7799:::'))6222
''/4
(
(C -D(G,,i   r   c                     t           j        } |                     d          r| d         S t          t	                      d          S )zReturn the runtime dir for transient jupyter files.

    Returns JUPYTER_RUNTIME_DIR if defined.

    The default is now (data_dir)/runtime on all platforms;
    we no longer use XDG_RUNTIME_DIR after various problems.
    JUPYTER_RUNTIME_DIRruntime)r'   r(   rO   r`   rp   )ra   s    r   jupyter_runtime_dirrt      sC     *C
ww$%% *())!##Y///r   JUPYTER_USE_PROGRAMDATA_use_programdataz
str | None_win_programdatantPROGRAMDATArj   T)r\   	multipatha7  Jupyter is migrating its paths to use standard platformdirs
given by the platformdirs library.  To remove this warning and
see the appropriate new directories, set the environment variable
`JUPYTER_PLATFORM_DIRS=1` and then run `jupyter --paths`.
The use of platformdirs will be the default in `jupyter_core` v6z/usr/local/share/jupyterz/usr/share/jupyter	list[str]ENV_JUPYTER_PATHsubdirsc                 p    g }t           j                            d          rL|                    d t           j        d                             t           j                  D                        t                      g}t          j        rmt          t          d          rt          j
                    nt          j        }|r7t          t          |dd                    }||vr|                    |           t          t           k    rt          }nd t          D             }t#                      r+|                    |           |                    |           n*|                    |           |                    |           t           D ]}||vr|                    |            r fd|D             }|S )ay  Return a list of directories to search for data files.

    There are four sources of paths to search:

    - $JUPYTER_PATH environment variable (always highest priority)
    - user directories (e.g. ~/.local/share/jupyter)
    - environment directories (e.g. {sys.prefix}/share/jupyter)
    - system-wide paths (e.g. /usr/local/share/jupyter)

    JUPYTER_PATH environment variable has highest priority, if defined,
    and is purely additive.

    If the JUPYTER_PREFER_ENV_PATH environment variable is set, the environment-level
    directories will have priority over user-level directories.
    You can also set JUPYTER_PREFER_ENV_PATH=0 to explicitly prefer user directories.
    If Jupyter detects that you are in a virtualenv or conda environment,
    environment paths are also preferred to user paths,
    otherwise user paths are preferred to environment paths.

    If the Python site.ENABLE_USER_SITE variable is True, we also add the
    appropriate Python user site subdirectory to the user-level directories.

    Finally, system-wide directories, such as `/usr/local/share/jupyter` are searched.

    If ``*subdirs`` are given, that subdirectory will be added to each element.


    .. versionchanged:: 5.8

        On Windows, %PROGRAMDATA% will be used as a system-wide path only if
        the JUPYTER_USE_PROGRAMDATA env is set.
        By default, there is no default system-wide path on Windows and the env path
        is used instead.

    Examples:

    >>> jupyter_path()
    ['~/.local/jupyter', '/usr/local/share/jupyter']
    >>> jupyter_path('kernels')
    ['~/.local/jupyter/kernels', '/usr/local/share/jupyter/kernels']
    JUPYTER_PATHc              3  T   K   | ]#}|                     t          j                  V  $d S r   rstripr'   sep.0rC   s     r   	<genexpr>zjupyter_path.<locals>.<genexpr>+  s0      \\!QXXbf%%\\\\\\r   getuserbaserj   r   c                $    g | ]}|t           v|S r   )SYSTEM_JUPYTER_PATHr   s     r   
<listcomp>z jupyter_path.<locals>.<listcomp>@  s#    KKKQa7J.J.Jq.J.J.Jr   c                *    g | ]}t          |gR  S r   )r`   )r   rC   r}   s     r   r   z jupyter_path.<locals>.<listcomp>P  s)    333q#7###333r   )r'   r(   rO   extendsplitpathseprp   siteENABLE_USER_SITEr<   r   	USER_BASEr   r   appendr|   r   rP   )r}   pathsuseruserbaseuserdirra   _paths   `      r   jupyter_pathr      s   V E 
z~~n%% ]\\rz./I/O/OPRPZ/[/[\\\\\\ D 	% *1})E)EY4#%%%4> 	%$x)<<==Gd""G$$$
 ...KK*KKK#%% STTS %    LL  43333U333Lr   etcENV_CONFIG_PATHz/usr/local/etc/jupyterz/etc/jupyterc                    t           j                            d          rt                      gS g } t           j                            d          rL|                     d t           j        d                             t           j                  D                        t                      g}t          j        rmt          t          d          rt          j
                    nt          j        }|r7t          t          |dd                    }||vr|                    |           t          t           k    rt          }nd t          D             }t#                      r+|                     |           |                     |           n*|                     |           |                     |           t          t           k    r|                     t                      | S )a+  Return the search path for Jupyter config files as a list.

    If the JUPYTER_PREFER_ENV_PATH environment variable is set, the
    environment-level directories will have priority over user-level
    directories.

    If the Python site.ENABLE_USER_SITE variable is True, we also add the
    appropriate Python user site subdirectory to the user-level directories.

    Finally, system-wide directories such as `/usr/local/etc/jupyter` are searched.


    .. versionchanged:: 5.8

        On Windows, %PROGRAMDATA% will be used as a system-wide path only if
        the JUPYTER_USE_PROGRAMDATA env is set.
        By default, there is no system-wide config path on Windows.

    Examples:

    >>> jupyter_config_path()
    ['~/.jupyter', '~/.local/etc/jupyter', '/usr/local/etc/jupyter', '/etc/jupyter']

    rY   JUPYTER_CONFIG_PATHc              3  T   K   | ]#}|                     t          j                  V  $d S r   r   r   s     r   r   z&jupyter_config_path.<locals>.<genexpr>  s0      cc!QXXbf%%ccccccr   r   r   r   c                $    g | ]}|t           v|S r   )SYSTEM_CONFIG_PATHr   s     r   r   z'jupyter_config_path.<locals>.<listcomp>  s#    IIIQQ6H-H-Hq-H-H-Hr   )r'   r(   rO   rc   r   r   r   r   r   r<   r   r   r   r   r   r   r   rP   )r   r   r   r   ra   s        r   jupyter_config_pathr   m  s   2 
z~~)** &"$$%%E 
z~~+,, dccrz:O/P/V/VWYWa/b/bcccccc   !D 	% *1})E)EY4#%%%4> 	%$x	::;;Gd""G$$$
 ,,,II/III#%% STTS ,,,'(((Lr   c                T    	 t          j        |            n# t          $ r Y dS w xY wdS )zcReplacement for `os.path.exists` which works for host mapped volumes
    on Windows containers
    FT)r'   lstatr@   )r4   s    r   r7   r7     s=    
   uu4s    
%%abs_pathstat_resOptional[Any]c                z   t          |           j                            d          rdS |Q	 t          |                                           }n.# t          $ r!}|j        t
          j        k    rY d}~dS  d}~ww xY w	 |j        t          j        z  rdS n&# t          $ r t          j        dd           Y nw xY wdS )  Is a file hidden?

    This only checks the file itself; it should be called in combination with
    checking the directory containing the file.

    Use is_hidden() instead to check the file and its parent directories.

    Parameters
    ----------
    abs_path : unicode
        The absolute path to check.
    stat_res : os.stat_result, optional
        The result of calling stat() on abs_path. If not passed, this function
        will call stat() internally.
    .TNFzThidden files are not detectable on this system, so no file will be marked as hidden.   
stacklevel)r   r   rN   r=   r@   errnoENOENTst_file_attributesFILE_ATTRIBUTE_HIDDENAttributeErrorwarningswarnr   r   es      r   is_file_hidden_winr     s      H~~%%c** t	H~~**,,HH 	 	 	w%,&&uuuuu	

'()	 4		
  
 
 
 	b	
 	
 	
 	
 	
 	
	
 5s/   !A 
A:A54A55A:>B  B87B8c                   t          |           j                            d          rdS |t          j        |j                  rQ	 t          |                                           }n.# t          $ r!}|j        t          j        k    rY d}~dS  d}~ww xY wt          j	        |j                  r.t          j        | t          j        t          j        z            sdS t          |dd          t          z  rdS dS )r   r   TNFst_flagsr   )r   r   rN   r=   S_ISLNKst_moder@   r   r   S_ISDIRr'   rA   X_OKR_OKgetattrr   r   s      r   is_file_hidden_posixr     s      H~~%%c** t4<(899	H~~**,,HH 	 	 	w%,&&uuuuu	 |H$%% y27RW#455 	4 xQ'')3 t5s   !A( (
B2BBB abs_rootc                   t           j                            |           } t           j                            |          }| |k    rdS t          |           rdS |s3|                     t           j        d          d         t           j        z   }| t          |          d         }t          d t          |          j	        D                       rdS t          t          |           j                  }|r|                    |          r||k    rt          |                                          s"t          t          |          j                  }`	 t          j        |          }n# t          $ r Y dS w xY wt!          |dd          t"          z  rdS t          t          |          j                  }|r|                    |          r||k    dS )a  Is a file hidden or contained in a hidden directory?

    This will start with the rightmost path element and work backwards to the
    given root to see if a path is hidden or in a hidden directory. Hidden is
    determined by either name starting with '.' or the UF_HIDDEN flag as
    reported by stat.

    If abs_path is the same directory as abs_root, it will be visible even if
    that is a hidden folder. This only checks the visibility of files
    and directories *within* abs_root.

    Parameters
    ----------
    abs_path : unicode
        The absolute path to check for hidden directories.
    abs_root : unicode
        The absolute path of the root directory in which hidden directories
        should be checked for.
    FTr   r   Nc              3  @   K   | ]}|                     d           V  dS )r   N)rN   )r   parts     r   r   zis_hidden.<locals>.<genexpr>8  s.      
D
DD4??3
D
D
D
D
D
Dr   r   )r'   r4   normpathis_file_hiddenr   r   lenanyr   partsr   r8   rN   r7   r   r@   r   r   )r   r   inside_rootr4   rD   s        r   	is_hiddenr     s   ( w))Hw))H8uh t 9>>"&!,,Q/"&83x==??+K

D
DD,=,=,C
D
D
DDD t tH~~$%%D
 &4??8,, &1A1ADzz  "" 	tDzz())D	$BB 	 	 	44	2z1%%	1 	44::$%%  &4??8,, &1A1A 5s   E( (
E65E6fnameNonec                `   	 ddl }n# t          $ r t          |           cY S w xY wddl}ddl}|                    |j                  }|                    d|                    |j	                            \  }}}|
                    | |j                  }|                                }	|	                    |j        |j        |j        z  |j        z  |           |	                    |j        |j        |           |                    d|	d           |                    | |j        |           dS )a  Secure a windows file to read-only access for the user.
    Follows guidance from win32 library creator:
    http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html

    This method should be executed against an already generated file which
    has no secrets written to it yet.

    Parameters
    ----------

    fname : unicode
        The path to the file to secure
    r   Nr   r   )win32apiImportError#_win32_restrict_file_to_user_ctypesntsecurityconwin32securityCreateWellKnownSidWinBuiltinAdministratorsSidLookupAccountNameGetUserNameExNameSamCompatibleGetFileSecurityDACL_SECURITY_INFORMATIONACLAddAccessAllowedAceACL_REVISIONFILE_GENERIC_READFILE_GENERIC_WRITEDELETEFILE_ALL_ACCESSSetSecurityDescriptorDaclSetFileSecurity)
r   r   conr   adminsr   _domain_typesddacls
             r   win32_restrict_file_to_userr   N  s_   : : : :2599999:   --m.WXXF(::
H""8#=>> D'5 
	&	&um.U	V	VBD" 66C  
 	]79LfUUU  D!,,,!!%)PRTUUU4s    ##c                6  %&'()*+,- ddl +ddl m- +                    dd          *+                    dd          ,d}d	}d
}d%d&d'd}d}d}d}d}d}	d}
d}d}d
}d}d}||z  dz  }||	z  |z  |
z  |z  }||z  |z  |z  |z  |z  } G -fdd+j                  }+j        )+                    |          (+                    -j                  }d;+fd}|,j        _        -j	        ,j        _
        +j        -j        -j        f,j        _        |*j        _        -j	        *j        _
        -j        ))-j        f*j        _        |*j        _        -j	        *j        _
        -j        -j        )-j        -j        -j        -j        f*j        _        |*j        _        -j	        *j        _
        (-j        -j        )f*j        _        |*j        _        -j	        *j        _
        |-j	        (-j	        f*j        _        |*j        _        -j	        *j        _
        -j        -j        |-j        -j        f*j        _        |*j        _        -j	        *j        _
        -j        -j        |f*j        _        |*j        _        -j	        *j        _
        ||-j        (-j        (-j        )-j        )-j        f*j        _        |*j        _        -j	        *j        _
        ||-j        f*j        _        |*j        _        -j	        *j        _
        (-j        -j        f*j        _        d<&*+-fd!}d='+,fd#}d>&*+-fd&}d?*fd+}d@&*+-fd.}dA*fd0}dB*fd4}dC&()*+-fd6}dD&*+-fd8}dE%(*+fd9} ||          }  |d: ||                    d         }! |            }" ||"%||             ||"%||z  |z  |!            || |          }# ||#          }$ ||$d|"d            ||$          }# || ||#           dS )Fa  Secure a windows file to read-only access for the user.

    Follows guidance from win32 library creator:
    http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html

    This method should be executed against an already generated file which
    has no secrets written to it yet.

    Parameters
    ----------

    fname : unicode
        The path to the file to secure
    r   Nwintypesadvapi32T)use_last_errorsecur32r         z      i   i   i   i   r               i  c                  d    e Zd Zd j        fd j        fd j        fd j        fd j        fgZdS )0_win32_restrict_file_to_user_ctypes.<locals>.ACLAclRevisionSbz1AclSizeAceCountSbz2N)__name__
__module____qualname__BYTEWORD_fields_r   s   r   r   r     sH        HM*X]#&'X]#
r   r   resultintfuncr   argsr   c                Z    | s'                                                               |S r   )WinErrorget_last_error)r  r  r  ctypess      r   _nonzero_successz=_win32_restrict_file_to_user_ctypes.<locals>._nonzero_success  s.     	;//&"7"7"9"9:::r   WellKnownSidTypec           	         j         dz              }                                }	                     | d |                    |                     ne# t          $ rX}|j        k    r  j         |j        z              }                    | d |                    |                     Y d }~nd }~ww xY w|d d          S )Nr   )c_charDWORDr   byrefr@   winerrorvalue)r  pSidcbSidr   ERROR_INSUFFICIENT_BUFFERr   r  r   s       r   r   z?_win32_restrict_file_to_user_ctypes.<locals>.CreateWellKnownSid"  s    !!$$  	[''(8$fllSXFYFYZZZZ 	[ 	[ 	[z666/FMEK/22D''(8$fllSXFYFYZZZZZZZZ		[
 AAAws   +A 
B7AB22B7
NameFormatc                b                                            d                    }	                     | d |           n## t          $ r}|j        k    r Y d }~nd }~ww xY w|j        j        sd S                     |j        j                  }                    | ||           |j        S Nr   )pointerc_ulongGetUserNameExWr@   r  contentsr  create_unicode_buffer)r  nSizer   lpNameBufferERROR_MORE_DATAr  r   s       r   r   z:_win32_restrict_file_to_user_ctypes.<locals>.GetUserNameEx/  s     v~~a0011	"":tU;;;; 	 	 	z_,, -,,,,	 ~# 	433EN4HIIz<???!!s   A 
A#AA#lpSystemNamelpAccountNamec                4                        d          }                     d          }                     d          }	                     | |d                     |          d                     |                              |                     n## t          $ r}|j        
k    r Y d }~nd }~ww xY w                    d|j                  }                                        |          j	                  }                    d|j        dz             }                    | ||                    |          |                    |                              |                    }	|	s
                                ||j        |j        fS )Nr   r   r   )r  LookupAccountNameWr  r@   r  r  r  castr  LPVOIDr
  )r#  r$  r  cchReferencedDomainNamepeUser   Sidr  lpReferencedDomainNamesuccessr  r   r  r   s             r   r   z>_win32_restrict_file_to_user_ctypes.<locals>.LookupAccountName>  s    q!!"*.."3"3q!!	''U##455U##     	 	 	z666 76666	 **2u{;;{{6>>#..@@!'!=!=bBYB_bcBc!d!d--LL"LL011LL
 
  	$//###+15;>>s   AB 
B7!B22B7pAcldwAceRevision
AccessMaskr  c                8                         | |||           d S r   )r   )r.  r/  r0  r  r   s       r   r   z@_win32_restrict_file_to_user_ctypes.<locals>.AddAccessAllowedAcea  s%     	$$T=*dKKKKKr   
lpFileNameRequestedInformationc           	     l                        d          }	                     | |d d                    |                     n## t          $ r}|j        k    r Y d }~nd }~ww xY w|j        sd S  j        |j        z              }                    | |||                    |                     |S r  )r  GetFileSecurityWr  r@   r  r  r  )	r2  r3  nLengthr   pSecurityDescriptorr  r   r  r   s	        r   r   z<_win32_restrict_file_to_user_ctypes.<locals>.GetFileSecurityf  s    ..##
	%%$W%%     	 	 	z666 76666	 } 	4<x}w}<??!! LL!!	
 	
 	
 #"s   ,A 
A%A  A%r7  c                6                         | ||           d S r   )SetFileSecurityW)r2  r3  r7  r   s      r   r   z<_win32_restrict_file_to_user_ctypes.<locals>.SetFileSecurity  s%     	!!*.BDWXXXXXr   bDaclPresentpDaclbDaclDefaultedc                8                         | |||           d S r   )r   )r7  r:  r;  r<  r   s       r   r   zF_win32_restrict_file_to_user_ctypes.<locals>.SetSecurityDescriptorDacl  s'     	**+>eUcdddddr   pSelfRelativeSecurityDescriptorc                   d }                     d          }d }                     d          }d }                     d          }d }                     d          }d }	                     d          }
	                     | |                    |          |                    |          |                    |          |                    |          |	                    |
                     n## t          $ r}|j        k    r Y d }~nd }~ww xY w j        |j        z              } j        |j        z              }                    |          j        } j        |j        z              }                    |          j        } j        |j        z              }                    |          } j        |
j        z              }                    |          }	                    | |                    |          |                    |          |                    |          |||	                    |
                     |S r  )	r  MakeAbsoluteSDr  r@   r  r  r  r'  r  )r>  pAbsoluteSecurityDescriptor"lpdwAbsoluteSecurityDescriptorSizer;  lpdwDaclSizepSacllpdwSaclSizepOwnerlpdwOwnerSizepPrimaryGrouplpdwPrimaryGroupSizer   	pDaclData	pSaclData
pOwnerDatapPrimaryGroupDatar  PACLPSIDr   r  r   s                   r   r@  z;_win32_restrict_file_to_user_ctypes.<locals>.MakeAbsoluteSD  sz    '+#-5^^A->->*~~a((~~a(( q))'~~a00	##/+?@@\**\**]++122     	 	 	z666 76666	 (`x}7Y7_'_&b&b#7X]\%77::	It,,57X]\%77::	It,,59hmm&99<<
Z..GX]-A-GGJJ$5t<<+'LL;<<LL&&LL&&LL-..	
 	
 	
 +*s   6A>C5 5
D?DDrA  c                V   d }                     d          }	                     | |                    |                     n## t          $ r}|j        k    r Y d }~nd }~ww xY w j        |j        z              }                    | |                    |                     |S r  )r  MakeSelfRelativeSDr  r@   r  r  r  )rA  r>  lpdwBufferLengthr   r  r   r  r   s       r   rQ  z?_win32_restrict_file_to_user_ctypes.<locals>.MakeSelfRelativeSD  s     +/'#>>!,,	''+/-..   
  	 	 	z666 76666	 ,R8=;K;Q+Q*T*T'##'+LL)**	
 	
 	

 /.s   *A 
A%A  A%c                     d}                      |           }                    |          j        }                    ||            |S )Ni  )create_string_bufferr'  r  InitializeAcl)
nAclLengthacl_datar.  r   rN  r   r  s      r   NewAclz3_win32_restrict_file_to_user_ctypes.<locals>.NewAcl  sN    
..z::{{8T**3tZ>>>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   r0  r   r  r   r   r   )r2  r   r3  r   r   r   )r2  r   r3  r   r7  r   r   r   )
r7  r   r:  r   r;  r   r<  r   r   r   )r>  r   r   r   )rA  r   r   r   )r   r   )r  r   WinDLL	Structurec_void_pPOINTERr  r  errcheckBOOLrestypec_intLPWSTRPULONGargtypesr   r  PDWORDr&  LPDWORDr   r   r5  LPCWSTRr9  r@  rQ  rU  ).r   r   r   r   SYNCHRONIZEr   STANDARD_RIGHTS_REQUIREDSTANDARD_RIGHTS_READSTANDARD_RIGHTS_WRITEFILE_READ_DATAFILE_READ_EAFILE_READ_ATTRIBUTESFILE_WRITE_DATAFILE_APPEND_DATAFILE_WRITE_EAFILE_WRITE_ATTRIBUTESr   r   r   r   PSECURITY_DESCRIPTORr  r   r   r   r   r   r   r   r@  rQ  rX  	SidAdminsSidUserAclSelfRelativeSD
AbsoluteSDr   r  r"  rN  rO  r   r  r   r   s.                                        @@@@@@@@@r   r   r   z  s    MMM}}Z}==HmmIdm;;G"$ !L #OKF&"#NLOM.<uDO~-0DD|SVaa  	
	
	  	 		
 	 
 
 
 
 
 
 
f 
 
 
 ?D>>#D!>>(-88     
 '7G#%-]G"'G# ,<H(*2-H'	,H( ,<H(*2-H',H( -=H )+3=H (	-H ) 3CH&/19H&.	3H&/ *:H&(0H%*H& *:H&(0H%*H& (8H$&.mH#(H$ ,<H(*2-H',H( '7H#%-]H"'H#        " " " " " " " "!? !? !? !? !? !? !? !? !?FL L L L L L
# # # # # # # # #4Y Y Y Y Y Ye e e e e e4+ 4+ 4+ 4+ 4+ 4+ 4+ 4+ 4+ 4+ 4+l/ / / / / / / / /,         #"#>??IMM2C$D$DEEaHG
&((C\?IFFF..7	   %_U,EFFN//Jj!S!444''
33NOE4nEEEEEr   r  c                x    t          j        t          |                                            j                  dz  S )zRetrieves the file mode corresponding to fname in a filesystem-tolerant manner.

    Parameters
    ----------

    fname : unicode
        The path to the file to get mode from

    i  )r=   S_IMODEr   r   )r   s    r   get_file_moderz    s0     	T%[[%%''/0069r   JUPYTER_ALLOW_INSECURE_WRITESr$   )true1binaryIterator[Any]c              #    K   |rdnd}|rdnd}t           j        t           j        z  t           j        z  }	 t	          |                                            n# t          $ r Y nw xY wt           j        dk    rht          rt                       nRt          j
        | |d          }t          j        |           t           j        t           j        z  }t          |            t          j        t          j
        | |d          ||          5 }t           j        dk    rPt          |           }|dk    r;t          rt                       n%d|  d	t          |           d
}t!          |          |V  ddd           dS # 1 swxY w Y   dS )aD  Opens a file in the most restricted pattern available for
    writing content. This limits the file mode to `0o0600` and yields
    the resulting opened filed handle.

    Parameters
    ----------

    fname : unicode
        The path to the file to write

    binary: boolean
        Indicates that the file is binary
    wbwNzutf-8rx   i  )encodingz0Permissions assignment failed for secure file: 'z'. Got 'z' instead of '0o0600'.)r'   O_CREATO_WRONLYO_TRUNCr   unlinkr@   r   allow_insecure_writesissue_insecure_write_warningopencloser   fdopenrz  octRuntimeError)	r   r~  moder  	open_flagfdf	file_modemsgs	            r   secure_writer  
  s      "44sD*tt7H
R[(2:5IU    
w$  	/ )****
 	622BHRLLLbj0I'...	275)V44dX	N	N	N RS7d??%e,,IF""( ,02222H5 H H!$YH H H  's+++                 s$   !A 
A%$A%A%E==FFc                 R    dd} | t           _        t          j        dd	
           dS )z Issue an insecure write warning.r  r   r  r   kwargsr   c                &    t          |           dz   S )N
)r   )r  r  r  s      r   format_warningz4issue_insecure_write_warning.<locals>.format_warningC  s    3xx$r   zWARNING: Insecure writes have been enabled via environment variable 'JUPYTER_ALLOW_INSECURE_WRITES'! If this is not intended, remove the variable or set its value to 'False'.r   r   N)r  r   r  r   r  r   r   r   )r   formatwarningr   )r  s    r   r  r  @  sM        ,HM	0 	     r   )F)r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   )r   r   )r4   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   r   r   )r   r   r   r  )r   r   r~  r   r   r  )r   r   )H__doc__
__future__r   r   r'   r   r=   rK   rT   r   
contextlibr   pathlibr   typingr   r   r   r	   r
   r]   utilsr   r4   joinr`   rl   rL   rN   r_   r   r   r   r,   r2   r3   __annotations__rE   rP   rW   rc   rp   rt   rv   rw   r   r(   rO   r   r   site_data_dirr   r   r|   r   r   r   site_config_dirr   r7   r   r   r   r   r   r   rz  getenvr)   r  r  r  r   r   r   <module>r     s      # " " " " "  				   



   % % % % % %       = = = = = = = = = = = = = =          
 <7LHSZ%:%:?%K%KGGG GD+u--	 
 9 9 9 9 
 9 
 D D D 
 DS S S S S2 2 2 2( ( ( (     ! ! ! !6   ,
 
 
 
' ' ' '*! ! ! !>0 0 0 0"   9::  : : : :#  # # # #7d??'?z~~mT::  
	w$/"s44
GY#G#GHHI8l8u
 
 

%


 	 K	K   
w$ 	N#(5)99#E#E"F#&3ttCJ'K'K#L#L"M ' 

  #s44
GY#G#GHHI  I I I IU U U Up "c$$sz5)"D"DEEF F F F F 	w$/ -QQQ/9\9u
 
 

%


 	 W__  0!c$$'7"C"CDDE,QQQ/ 	!B B B BJ   * * * * *Z% % % % %P <7'NN)N3 3 3 3 3l) ) ) )XwF wF wF wFt   & "	"A7KKQQSSWdd  2 2 2 2 2j     r   