
    ^h                    x   % S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
Jr  SSKJr  SSKJrJrJrJrJr  SSKrSSKJr  \R.                  R0                  r\R4                  S	:X  d0  \R4                  S
:X  a#  \R6                  R9                  S5      (       d  SrOSr\" \SS5      r\S?S@S jj5       r \SAS j5       r S?SBS jjr SCS jr!SDS jr"0 r#S\$S'   SES jr%SCS jr&SFS jr'SDS jr(SDS jr)SDS jr*\ " S5      r+S\$S '   Sr,S!\$S"'   \RZ                  S#:X  a#  \+(       a  \R\                  R_                  S$S5      r,\!" 5       (       a_  \RZ                  S#:X  a#  \+(       d  \0" \" \R6                  S%S5      5      /r1Ov\Rd                  " \SS&S'9Rg                  \Rh                  5      r1OJ\" S(5        \RZ                  S#:X  a.  \,(       a  \" \,S5      /r1O \0" \" \R6                  S%S5      5      /r1OS)S*/r1\0" \" \R6                  S%S5      5      /r5S+\$S,'   SGS- jr6\0" \" \R6                  S.S5      5      /r7S+\$S/'   \!" 5       (       aI  \RZ                  S#:X  a  \+(       d  \7SS r8O^\Rr                  " \SS&S'9Rg                  \Rh                  5      r8O2\RZ                  S#:X  a  \,(       a  \0" \" \,S5      5      /r8O
\7SS r8OS0S1/r8SHS2 jr:SES3 jr;SISJS4 jjr<SISJS5 jjr=\R4                  S	:X  a  \<r>O\=r>SKSLS6 jjr?SMS7 jr@SMS8 jrASNS9 jrB\R                  " S:S;5      R                  5       S<;   rE\S?SOS= jj5       rFSPS> jrGg)QzPath utility functions.    )annotationsN)contextmanager)Path)AnyIteratorLiteralOptionaloverload   )deprecationwin32darwinz/opt/homebrewJupyterjupyter	UF_HIDDENi   Fboolc                    g N namedefaults     L/home/james-whalen/.local/lib/python3.13/site-packages/jupyter_core/paths.pyenvsetr   )   s    69    c                    g r   r   r   s     r   r   r   -   s    ADr   c                v    U [         R                  ;  a  U$ [         R                  U    R                  5       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   s3     2::::d!!#+RRRr   c                     [        SS5      $ )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1r   c                 x    [        S5      R                  5       n [        [        U 5      R                  5       5      $ )z'Get the real path of the home directory~)r   
expanduserstrresolve)homedirs    r   get_home_dirr/   H   s.    3i""$G tG}$$&''r   zdict[str, str]_dtempsc                T   [        U 5      R                  5       nUR                  5       (       dA  XR                  :w  a2  UR                  nUR                  5       (       d  XR                  :w  a  M2   UR	                  5       [
        R                  " 5       :H  $ ! [         a     Of = f[        [
        S5      (       aI   UR                  5       nUR                  [
        R                  " 5       :H  $ ! [        [        4 a     Of = f[
        R                  " U[
        R                  5      $ )z3Return whether the current user owns the given pathgeteuid)r   r-   existsparentownerr#   getlogin	Exceptionhasattrstatst_uidr2   NotImplementedErrorOSErroraccessW_OK)pathpsts      r   	_do_i_ownrB   S   s    T
A hhjjQ((]HH hhjjQ((]
wwyBKKM))  r9	B99

,,#W- 		
 99Q  s$   1%B 
B$#B$=1C/ /DDc                    S[         R                  ;   a  [        S5      $ [        R                  [        R
                  :w  a  [        [        R                  5      (       a  gS[         R                  ;   ax  [        R                  R                  [         R                  S   5      (       aC  [         R                  R                  SS5      S:w  a  [        [        R                  5      (       a  gg)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_prefixrB   
startswithgetr   r   r   prefer_environment_over_userrM   n   s     !BJJ./00 zzS__$3::)>)> 	"**$JJ!!"**^"<==JJNN.76Acjj!!r   c                z     [         U    $ ! [         a%    [        R                  " U S-   S9=n[         U '   Us $ f = f)zMake or reuse a temporary directory.

If this is called with the same name in the same process, it will return
the same directory.
-)rI   )r0   KeyErrortempfilemkdtemp)r   ds     r   _mkdtemp_oncerT      sB    t} $,,D3J??GDMs    ,::c                    [         R                  n U R                  S5      (       a  [        S5      $ U R                  S5      (       a  U S   $ [	        5       (       a  [
        R                  " [        SS9$ [        5       n[        US5      $ )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$   rL   rT   r(   platformdirsuser_config_dirAPPNAMEr/   pjoin)envhome_dirs     r   jupyter_config_dirr`      su     **C
ww"##011
ww#$$'((++GuEE~H:&&r   c                 X   [         R                  n U R                  S5      (       a  U S   $ [        5       (       a  [        R
                  " [        SS9$ [        5       n[        R                  S:X  a  [        [        USS5      5      $ [        R                  S:X  a^  [         R                  R                  SS	5      nU(       a#  [        [        US
5      R                  5       5      $ [        [        5       S5      $ U R                  SS	5      nU(       d  [        USS5      n[        US
5      $ )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_DIRFrX   r   Libraryr   r   APPDATANr   dataXDG_DATA_HOMEz.localshare)r#   r$   rL   r(   rZ   user_data_dirr\   r/   rH   platformr,   r   r-   r]   r`   )r^   homeappdataxdgs       r   jupyter_data_dirrm      s     **C
ww!""%&&))'UCC>D
||x4i344
||w**..D1tGY/779::')622
''/4
(CD(G,i  r   c                     [         R                  n U R                  S5      (       a  U S   $ [        [	        5       S5      $ )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$   rL   r]   rm   )r^   s    r   jupyter_runtime_dirrq      s:     **C
ww$%%())!#Y//r   JUPYTER_USE_PROGRAMDATA_use_programdataz
str | None_win_programdatantPROGRAMDATArg   T)rY   	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_PATHc                    / n[         R                  R                  S5      (       aF  UR                  S [         R                  S   R	                  [         R
                  5       5       5        [        5       /n[        R                  (       am  [        [        S5      (       a  [        R                  " 5       O[        R                  nU(       a,  [        [        USS5      5      nXB;  a  UR                  U5        [        [         :X  a  [        nO![         Vs/ s H  of[         ;  d  M  UPM     nn[#        5       (       a#  UR                  U5        UR                  U5        O"UR                  U5        UR                  U5        [          H  nXq;  d  M
  UR                  U5        M     U (       a  U Vs/ s H  n[%        U/U Q76 PM     nnU$ s  snf s  snf )a	  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  ^   #    U  H#  oR                  [        R                  5      v   M%     g 7fr   rstripr#   sep.0r@   s     r   	<genexpr>jupyter_path.<locals>.<genexpr>+  s      \/[!XXbff%%/[   +-getuserbaserg   r   )r#   r$   rL   extendsplitpathseprm   siteENABLE_USER_SITEr8   r   	USER_BASEr,   r   appendry   SYSTEM_JUPYTER_PATHrM   r]   )subdirspathsuseruserbaseuserdirr^   r@   _paths           r   jupyter_pathr      sb   V E 
zz~~n%%\rzz./I/O/OPRPZPZ/[\\ D *1})E)E4##%4>>$x)<=G"G$
 ..*K*Q7J.Jq*K#%%STTS %LL %
 -23Uq#7#U3L# L  4s   G(G4GetcENV_CONFIG_PATHz/usr/local/etc/jupyterz/etc/jupyterc                    [         R                  R                  S5      (       a  [        5       /$ / n [         R                  R                  S5      (       aF  U R	                  S [         R                  S   R                  [         R                  5       5       5        [        5       /n[        R                  (       am  [        [        S5      (       a  [        R                  " 5       O[        R                  nU(       a,  [        [        USS5      5      nX1;  a  UR                  U5        [        [         :X  a  [        nO![         Vs/ s H  oU[         ;  d  M  UPM     nn[#        5       (       a#  U R	                  U5        U R	                  U5        O"U R	                  U5        U R	                  U5        [        [         :w  a  U R	                  [         5        U $ s  snf )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']

rV   JUPYTER_CONFIG_PATHc              3  ^   #    U  H#  oR                  [        R                  5      v   M%     g 7fr   r}   r   s     r   r   &jupyter_config_path.<locals>.<genexpr>  s      c/b!XXbff%%/br   r   r   r   )r#   r$   rL   r`   r   r   r   r   r   r8   r   r   r,   r   r   r   SYSTEM_CONFIG_PATHrM   )r   r   r   r   r^   r@   s         r   jupyter_config_pathr   m  sS   2 
zz~~)**"$%%E 
zz~~+,,crzz:O/P/V/VWYWaWa/bcc  !D *1})E)E4##%4>>$x	:;G"G$
 ,,)I/Q6H-Hq/I#%%STTS ,,'(L Js   GGc                R     [         R                  " U 5        g! [         a     gf = f)z[Replacement for `os.path.exists` which works for host mapped volumes
on Windows containers
FT)r#   lstatr<   )r?   s    r   r3   r3     s+    
   s    
&&c                   [        U 5      R                  R                  S5      (       a  gUc   [        U 5      R                  5       n UR                  [        R                  -  (       a  g g! [         a)  nUR
                  [
        R                  :X  a   SnAge SnAff = f! [         a    [        R                  " SSS9   gf = f)  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   rK   r9   r<   errnoENOENTst_file_attributesFILE_ATTRIBUTE_HIDDENAttributeErrorwarningswarnabs_pathstat_reses      r   is_file_hidden_winr     s      H~%%c**	H~**,H
''(() ) )  	ww%,,&	  
 	b	

 
s/   A. 	"B$ .
B!8BBB!$CCc                >   [        U 5      R                  R                  S5      (       a  gUb%  [        R                  " UR
                  5      (       a   [        U 5      R                  5       n[        R                  " UR
                  5      (       a<  [        R                  " U [        R                  [        R                  -  5      (       d  g[        USS5      [        -  (       a  gg! [         a)  nUR                  [        R                  :X  a   SnAge SnAff = f)r   r   TNFst_flagsr   )r   r   rK   r9   S_ISLNKst_moder<   r   r   S_ISDIRr#   r=   X_OKR_OKgetattrr   r   s      r   is_file_hidden_posixr     s      H~%%c**4<<(8(899	H~**,H ||H$$%%yy277RWW#455 xQ')3  	ww%,,&	s   C) )
D3DDDc                   [         R                  R                  U 5      n [         R                  R                  U5      nX:X  a  g[        U 5      (       a  gU(       d4  U R	                  [         R
                  S5      S   [         R
                  -   nU [        U5      S n[        S [        U5      R                   5       5      (       a  g[        [        U 5      R                  5      nU(       a  UR                  U5      (       a  X1:w  a  [        U5      R                  5       (       d   [        [        U5      R                  5      nM`   [         R                  " U5      n[!        USS5      ["        -  (       a  g[        [        U5      R                  5      nU(       a  UR                  U5      (       a  X1:w  a  M  g! [         a     gf = f)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  B   #    U  H  oR                  S 5      v   M     g7f)r   N)rK   )r   parts     r   r   is_hidden.<locals>.<genexpr>8  s     
D,CD??3,Cs   r   )r#   r?   normpathis_file_hiddenr   r   lenanyr   partsr,   r4   rK   r3   r   r<   r   r   )r   abs_rootinside_rootr?   rA   s        r   	is_hiddenr     sZ   ( ww)Hww)Hh>>"&&!,Q/"&&83x=?+K

DD,=,C,C
DDD tH~$$%D
4??8,,1ADz  ""tDz(()D	$B 2z1%	14:$$% 4??8,,1A   		s   	F< <
G	G	c                j    SSK nSSKnSSKnUR                  UR                  5      nUR                  SUR                  UR                  5      5      u  pVnUR                  XR                  5      nUR                  5       n	U	R                  UR                  UR                  UR                   -  UR"                  -  U5        U	R                  UR                  UR$                  U5        UR'                  SU	S5        UR)                  XR                  U5        g! [         a    [        U 5      s $ f = f)ac  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 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)
fnamer   conr   adminsr   _domain_typesddacls
             r   win32_restrict_file_to_userr   N  s   :   --m.W.WXF(::
H""8#=#=>D5 
	&	&u.U.U	VBD"" 6 66C
 	]779L9LfU  D!,!!%)P)PRTU3  :2599:s   D D21D2c                
  ^%^&^'^(^)^*^+^,^- SSK m+SSK Jm-  T+R                  SSS9m*T+R                  SSS9m,SnS	nS
nSm%Sm&Sm'SnSnSnSnSnSn	Sn
SnSnS
nSnSnXd-  S-  nXy-  U-  U
-  U-  nUU-  U-  U-  U-  U-  n " U-4S jST+R                  5      nT+R                  m)T+R                  U5      m(T+R                  T-R                  5      nS%U+4S jjnUT,R                  l        T-R                  T,R                  l
        T+R                  T-R                  T-R                  4T,R                  l        UT*R                  l        T-R                  T*R                  l
        T-R                   T)T)T-R"                  4T*R                  l        UT*R$                  l        T-R                  T*R$                  l
        T-R                  T-R                  T)T-R&                  T-R                  T-R&                  T-R&                  4T*R$                  l        UT*R(                  l        T-R                  T*R(                  l
        T(T-R                   T-R                   T)4T*R(                  l        UT*R*                  l        T-R                  T*R*                  l
        UT-R                  T(T-R                  4T*R*                  l        UT*R,                  l        T-R                  T*R,                  l
        T-R.                  T-R                   UT-R                   T-R&                  4T*R,                  l        UT*R0                  l        T-R                  T*R0                  l
        T-R.                  T-R                   U4T*R0                  l        UT*R2                  l        T-R                  T*R2                  l
        UUT-R&                  T(T-R&                  T(T-R&                  T)T-R&                  T)T-R&                  4T*R2                  l        UT*R4                  l        T-R                  T*R4                  l
        UUT-R&                  4T*R4                  l        UT*R6                  l        T-R                  T*R6                  l
        T(T-R                   T-R                   4T*R6                  l        S&U&U*U+U-4S jjnS'U'U+U,4S jjnS(U&U*U+U-4S jjnS)U*4S jjnS*U&U*U+U-4S jjn        S+U*4S jjn          S,U*4S  jjnS-U&U(U)U*U+U-4S! jjnS.U&U*U+U-4S" jjnS/U%U(U*U+4S# jjnU" U5      n U" S$U" U5      5      S   n!U" 5       n"U" U"T%UU 5        U" U"T%UU-  U-  U!5        U" X5      n#U" U#5      n$U" U$SU"S5        U" U$5      n#U" XU#5        g)0ad  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                     > \ rS rSrS Y R                  4S Y R                  4S Y R
                  4S Y R
                  4S Y R
                  4/rSrg)	0_win32_restrict_file_to_user_ctypes.<locals>.ACLi  AclRevisionSbz1AclSizeAceCountSbz2r   N)__name__
__module____qualname____firstlineno__BYTEWORD_fields___static_attributes__r   s   r   r   r     sF    HMM*X]]#&'X]]#
r   r   c                T   > U (       d  TR                  TR                  5       5      eU$ r   )WinErrorget_last_error)resultfuncargsctypess      r   _nonzero_success=_win32_restrict_file_to_user_ctypes.<locals>._nonzero_success  s#    //&"7"7"9::r   c           	     p  > TR                   S-  " 5       nTR                  5       n TR                  U S UTR                  U5      5        US S  $ ! [         a\  nUR
                  T:w  a  e TR                   UR                  -  " 5       nTR                  U S UTR                  U5      5         S nANfS nAff = f)Nr   )c_charDWORDr   byrefr<   winerrorvalue)WellKnownSidTypepSidcbSidr   ERROR_INSUFFICIENT_BUFFERr   r  r   s       r   r   ?_win32_restrict_file_to_user_ctypes.<locals>.CreateWellKnownSid"  s    !$ 	[''(8$fllSXFYZ Aw  	[zz66MMEKK/2D''(8$fllSXFYZZ		[s   #A 
B5AB00B5c                z  > TR                  TR                  S5      5      n TR                  U S U5        UR
                  R                  (       d  g TR                  UR
                  R                  5      nTR                  XU5        UR                  $ ! [         a  nUR                  T:w  a  e  S nANS nAff = fNr   )pointerc_ulongGetUserNameExWr<   r  contentsr  create_unicode_buffer)
NameFormatnSizer   lpNameBufferERROR_MORE_DATAr  r   s       r   r   :_win32_restrict_file_to_user_ctypes.<locals>.GetUserNameEx/  s     v~~a01	"":tU; ~~##33ENN4H4HIz?!!!  	zz_, -	s   B 
B:B55B:c                  > TR                  S5      nTR                  S5      nTR                  S5      n TR                  U US TR                  U5      S TR                  U5      TR                  U5      5        TR                  SUR                  5      nTR                  TR                  U5      TR                  5      nTR                  SUR                  S-   5      nTR                  U UUTR                  U5      UTR                  U5      TR                  U5      5      n	U	(       d  TR                  5       eXxR                  UR                  4$ ! [         a  nUR                  T
:w  a  e  S nANS nAff = f)Nr   r   r   )r  LookupAccountNameWr  r<   r  r  r  castr  LPVOIDr  )lpSystemNamelpAccountNamer  cchReferencedDomainNamepeUser   Sidr  lpReferencedDomainNamesuccessr  r   r  r   s             r   r   >_win32_restrict_file_to_user_ctypes.<locals>.LookupAccountName>  sX    q!"*.."3q!	''U#45U# **2u{{;{{6>>#.@!'!=!=bBYB_B_bcBc!d--LL"LL01LL
 //##115;;>>#  	zz66 7	s   AE 
E8E33E8c                *   > TR                  XX#5        g r   )r   )pAcldwAceRevision
AccessMaskr  r   s       r   r   @_win32_restrict_file_to_user_ctypes.<locals>.AddAccessAllowedAcea  s     	$$T*Kr   c           	     l  > TR                  S5      n TR                  U US STR                  U5      5        UR
                  (       d  g TR                  UR
                  -  " 5       nTR                  U UUUTR                  U5      5        U$ ! [         a  nUR                  T:w  a  e  S nANvS nAff = fr  )r  GetFileSecurityWr  r<   r  r  r   )	
lpFileNameRequestedInformationnLengthr   pSecurityDescriptorr  r   r  r   s	        r   r   <_win32_restrict_file_to_user_ctypes.<locals>.GetFileSecurityf  s    ..#
	%%$W% }}'}}w}}<?!! LL!	
 #"  	zz66 7	s   $B 
B3B..B3c                *   > TR                  XU5        g r   )SetFileSecurityW)r5  r6  r8  r   s      r   r   <_win32_restrict_file_to_user_ctypes.<locals>.SetFileSecurity  s     	!!*DWXr   c                *   > TR                  XX#5        g r   )r   )r8  bDaclPresentpDaclbDaclDefaultedr   s       r   r   F_win32_restrict_file_to_user_ctypes.<locals>.SetSecurityDescriptorDacl  s     	**+>edr   c                x  > S nTR                  S5      nS nTR                  S5      nS nTR                  S5      nS nTR                  S5      nS n	TR                  S5      n
 TR                  U UTR                  U5      UTR                  U5      UTR                  U5      UTR                  U5      U	TR                  U
5      5        TR
                  UR                  -  " 5       nTR
                  UR                  -  " 5       nTR                  UT5      R                  nTR
                  UR                  -  " 5       nTR                  UT5      R                  nTR
                  UR                  -  " 5       nTR                  UT5      nTR
                  U
R                  -  " 5       nTR                  UT5      n	TR                  U UTR                  U5      UTR                  U5      UTR                  U5      UUU	TR                  U
5      5        U$ ! [         a  nUR                  T:w  a  e  S nAGNlS nAff = fr  )	r  MakeAbsoluteSDr  r<   r  r   r  r$  r  )pSelfRelativeSecurityDescriptorpAbsoluteSecurityDescriptor"lpdwAbsoluteSecurityDescriptorSizer?  lpdwDaclSizepSacllpdwSaclSizepOwnerlpdwOwnerSizepPrimaryGrouplpdwPrimaryGroupSizer   	pDaclData	pSaclData
pOwnerDatapPrimaryGroupDatar  PACLPSIDr   r  r   s                   r   rC  ;_win32_restrict_file_to_user_ctypes.<locals>.MakeAbsoluteSD  s    '+#-5^^A->*~~a(~~a( q)'~~a0	##/+?@\*\*]+12  (0}}7Y7_7_'_&b#]]\%7%77:	It,55]]\%7%77:	It,55mmm&9&99<
Z.%]]-A-G-GGJ$5t<+'LL;<LL&LL&LL-.	
 +*3  	zz66 7	s   "A&H 
H9H44H9c                D  > S nTR                  S5      n TR                  U UTR                  U5      5        TR
                  UR                  -  " 5       nTR                  U UTR                  U5      5        U$ ! [         a  nUR                  T:w  a  e  S nANbS nAff = fr  )r  MakeSelfRelativeSDr  r<   r  r   r  )rE  rD  lpdwBufferLengthr   r  r   r  r   s       r   rV  ?_win32_restrict_file_to_user_ctypes.<locals>.MakeSelfRelativeSD  s     +/'#>>!,	''+/-. ,4==;K;Q;Q+Q*T'##'+LL)*	

 /.  	zz66 7	s   "A: :
BBBc                    > Sn TR                  U 5      nTR                  UT5      R                  nTR                  X T5        U$ )Ni  )create_string_bufferr$  r  InitializeAcl)
nAclLengthacl_datar/  r   rR  r   r  s      r   NewAcl3_win32_restrict_file_to_user_ctypes.<locals>.NewAcl  sC    
..z:{{8T*33t>r   r   )r  intr  r   r  r   returnr   )r  r   ra  r   )r  r   ra  r   )r&  r   r'  r   ra  r   )
r/  r   r0  r   r1  r   r  r   ra  r   )r5  r   r6  r   ra  r   )r5  r   r6  r   r8  r   ra  r   )
r8  r   r>  r   r?  r   r@  r   ra  r   )rD  r   ra  r   )rE  r   ra  r   )ra  r   )r  r   WinDLL	Structurec_void_pPOINTERr   r  errcheckBOOLrestypec_intLPWSTRPULONGargtypesr   r  PDWORDr#  LPDWORDr   r   r4  LPCWSTRr;  rC  rV  r[  ).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   rC  rV  r^  	SidAdminsSidUserAclSelfRelativeSD
AbsoluteSDr   r  r   rR  rS  r   r  r   r   s.                                        @@@@@@@@@r   r   r   z  s    }}Z}=HmmIdm;G"$ !L #OKF&"#NLOM.<uDO-0DD|SVaa  	
	
	  	 		
 	 
f 
 ??D>>#D!>>(--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$&.mmH#(H$ ,<H(*2--H',H( '7H#%-]]H"'H# " "!? !?FL
# #4YY/2YILY	Ye e03e<?eQTe	e4+ 4+l/ /,  ##>?IM2C$DEaHG
(C\?IF..7	 %UFN/Jj!S!4'
3NEnEr   c                v    [         R                  " [        U 5      R                  5       R                  5      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  )r9   S_IMODEr   r   )r   s    r   get_file_moder    s-     	T%[%%'//069r   JUPYTER_ALLOW_INSECURE_WRITESr    )true1c              #  8  #    U(       a  SOSnU(       a  SOSn[         R                  [         R                  -  [         R                  -  n [	        U 5      R                  5         [         R                  S:X  ao  [        (       a  [        5         OY[         R                  " XS5      n[         R                  " U5        [         R                  [         R                  -  n[        U 5        [         R                  " [         R                  " XS5      X#S9 n[         R                  S:w  aD  [        U 5      nUS:w  a3  [        (       a  [        5         OSU  S	[        U5       S
3n[!        U5      eUv   SSS5        g! [         a     GN f = f! , (       d  f       g= f7f)a   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-8ru   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   fdopenr  octRuntimeError)	r   binarymoder  	open_flagfdf	file_modemsgs	            r   secure_writer  
  s@     4sDt7H

R[[(2::5IU
 
ww$   )*
 62BHHRLbjj0I'.	2775V4d	NRS77d?%e,IF"((02 K5' R!!$Y 00FH  's++ 
O	N%  $ 
O	NsD   A	FE8 %B-FAF	/	F8
FFFF	
FFc                 N    SS jn U [         l        [         R                  " SSS9  g)z Issue an insecure write warning.c                    [        U 5      S-   $ )N
)r,   )r  r  kwargss      r   format_warning4issue_insecure_write_warning.<locals>.format_warningC  s    3x$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   ra  r,   )r   formatwarningr   )r  s    r   r  r  @  s'     ,HMM	0 	r   )F)r   r,   r   r   ra  r   )r   r,   r   zLiteral[None]ra  Optional[bool])r   r,   r   r  ra  r  )ra  r   )ra  r,   )r?   r,   ra  r   )r   r,   ra  r,   )r   r,   ra  rx   )ra  rx   r   )r   r,   r   zOptional[Any]ra  r   )r   )r   r,   r   r,   ra  r   )r   r,   ra  None)r   r,   ra  r`  )r   r,   r  r   ra  zIterator[Any])ra  r  )H__doc__
__future__r   r   r#   r   r9   rH   rQ   r   
contextlibr   pathlibr   typingr   r   r   r	   r
   rZ   utilsr   r?   joinr]   ri   rI   rK   r\   r   r   r   r(   r/   r0   __annotations__rB   rM   rT   r`   rm   rq   rs   rt   r   r$   rL   r,   r   site_data_dirr   r   ry   r   r   r   site_config_dirr   r3   r   r   r   r   r   r   r  getenvr%   r  r  r  r   r   r   <module>r     s;    #  	   
   %  = =  
 <<7LLHSZZ%:%:?%K%KGG D+u-	 
 9 
 9 
 D 
 DS2(  !6,
'*!>0"   9: $ :# * #77d?'zz~~mT: 	ww$/"4

GY#GHI*88u

%


 	 	K 
ww$#()99#E"F#&tCJJ'K#L"M ' 

  #4

GY#GHI ) IUp "$szz5)"DEF F	ww$/ -Q/)99u

%


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