
    Xh                       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.                  j0                  Zej4                  d	k(  s*ej4                  d
k(  rej6                  j9                  d      sdZndZ eedd      Zed?d@d       Z edAd       Z d?dBdZ dCdZ!dDdZ"i Z#de$d<   dEdZ%dCdZ&dFdZ'dDdZ(dDdZ)dDdZ* e d      Z+de$d <   dZ,d!e$d"<   ejZ                  d#k(  re+rej\                  j_                  d$d      Z, e!       r\ejZ                  d#k(  re+s e0 eej6                  d%d            gZ1ns ejd                  edd&'      jg                  ejh                        Z1nD ed(       ejZ                  d#k(  r)e,r ee,d      gZ1n  e0 eej6                  d%d            gZ1nd)d*gZ1 e0 eej6                  d%d            gZ5d+e$d,<   dGd-Z6 e0 eej6                  d.d            gZ7d+e$d/<    e!       rFejZ                  d#k(  re+se7dd Z8n[ ejr                  edd&'      jg                  ejh                        Z8n,ejZ                  d#k(  re,r e0 ee,d            gZ8n
e7dd Z8nd0d1gZ8dHd2Z:dEd3Z;dIdJd4Z<dIdJd5Z=ej4                  d	k(  re<Z>ne=Z>dKdLd6Z?dMd7Z@dMd8ZAdNd9ZB ej                  d:d;      j                         d<v ZEed?dOd=       ZFdPd>ZGy)QzPath utility functions.    )annotationsN)contextmanager)Path)AnyIteratorLiteralOptionaloverload   )deprecationwin32darwinz/opt/homebrewJupyterjupyter	UF_HIDDENi   Fboolc                     y N namedefaults     F/var/www/html/myenv/lib/python3.12/site-packages/jupyter_core/paths.pyenvsetr   )   s    69    c                     y r   r   r   s     r   r   r   -   s    ADr   c                p    | t         j                  vr|S t         j                  |    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   s3     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1r   c                 x    t        d      j                         } t        t        |       j                               S )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        |       j                         }|j                         s;||j                  k7  r,|j                  }|j                         s||j                  k7  r,	 |j	                         t        j                         k(  S # t        $ r Y nw xY wt        t
        d      rG	 |j                         }|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   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 hhjQ!((]HH hhjQ!((]
wwyBKKM))  r9	B99

,,#W- 		
 99Q  s$   &$B 	BB+0C C.-C.c                    dt         j                  v rt        d      S t        j                  t        j
                  k7  rt        t        j                        rydt         j                  v rmt        j                  j                  t         j                  d         r=t         j                  j                  dd      dk7  rt        t        j                        ryy)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                |    	 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.
    -)rI   )r0   KeyErrortempfilemkdtemp)r   ds     r   _mkdtemp_oncerT      sB    t} $,,D3J??GDMs    -;;c                     t         j                  } | j                  d      rt        d      S | j                  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$   rL   rT   r(   platformdirsuser_config_dirAPPNAMEr/   pjoin)envhome_dirs     r   jupyter_config_dirr`      sl     **C
ww"#011
ww#$'((++GuEE~H:&&r   c                 0   t         j                  } | 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(  rYt         j                  j                  dd	      }|r#t        t        |d
      j                               S t        t               d      S | j                  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_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                 v    t         j                  } | 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$   rL   r]   rm   )r^   s    r   jupyter_runtime_dirrq      s7     **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                 V   g }t         j                  j                  d      rF|j                  d t         j                  d   j	                  t         j
                        D               t               g}t        j                  rat        t        d      rt        j                         nt        j                  }|r+t        t        |dd            }||vr|j                  |       t        t         k(  rt        }nt        D cg c]  }|t         vs| }}t#               r#|j                  |       |j                  |       n"|j                  |       |j                  |       t         D ]  }||vs|j                  |        | r|D cg c]  }t%        |g|   }}|S c c}w c c}w )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  Z   K   | ]#  }|j                  t        j                         % y wr   rstripr#   sep.0r@   s     r   	<genexpr>zjupyter_path.<locals>.<genexpr>+  s     \!QXXbff%\   )+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      s`   V E 
zz~~n%\rzz./I/O/OPRPZPZ/[\\ D *1})E4##%4>>$x)<=Gd"G$
 ..*KQa7J.JqKK#%STTS %  LL 
 -23q#7#33L# L  4s    F!F!
F&etcENV_CONFIG_PATHz/usr/local/etc/jupyterz/etc/jupyterc                 l   t         j                  j                  d      rt               gS g } t         j                  j                  d      rF| j	                  d t         j                  d   j                  t         j                        D               t               g}t        j                  rat        t        d      rt        j                         nt        j                  }|r+t        t        |dd            }||vr|j                  |       t        t         k(  rt        }nt        D cg c]  }|t         vs| }}t#               r#| j	                  |       | j	                  |       n"| j	                  |       | j	                  |       t        t         k7  r| j	                  t                | S c c}w )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  Z   K   | ]#  }|j                  t        j                         % y wr   r}   r   s     r   r   z&jupyter_config_path.<locals>.<genexpr>  s     c!QXXbff%cr   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  sJ   2 
zz~~)*"$%%E 
zz~~+,crzz:O/P/V/VWYWaWa/bcc  !D *1})E4##%4>>$x	:;Gd"G$
 ,,)IQQ6H-HqII#%STTS ,,'(L Js   *F18F1c                N    	 t        j                  |        y# t        $ r Y yw xY w)zcReplacement for `os.path.exists` which works for host mapped volumes
    on Windows containers
    FT)r#   lstatr<   )r?   s    r   r3   r3     s+    
   s    	$$c                z   t        |       j                  j                  d      ry|	 t        |       j                         }	 |j                  t        j                  z  ry	 y# t        $ r(}|j
                  t
        j                  k(  rY d}~y d}~ww xY w# t        $ r t        j                  dd       Y yw xY w)  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,BBB B:9B:c                    t        |       j                  j                  d      ry|t        j                  |j
                        r	 t        |       j                         }t        j                  |j
                        r6t        j                  | t        j                  t        j                  z        syt        |dd      t        z  ryy# t        $ r(}|j                  t        j                  k(  rY d}~y d}~ww xY w)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	H~**,H ||H$$%yy277RWW#45 xQ')3  	ww%,,&	s   C 	C=C87C88C=c                6   t         j                  j                  |       } t         j                  j                  |      }| |k(  ryt        |       ry|s4| j	                  t         j
                  d      d   t         j
                  z   }| t        |      d }t        d t        |      j                  D              ryt        t        |       j                        }|r|j                  |      r||k7  rt        |      j                         st        t        |      j                        }P	 t        j                  |      }t!        |dd      t"        z  ryt        t        |      j                        }|r|j                  |      r||k7  ry# t        $ r Y yw xY w)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   | ]  }|j                  d         yw)r   N)rK   )r   parts     r   r   zis_hidden.<locals>.<genexpr>8  s     
DD4??3
Ds   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     sQ   ( ww)Hww)H8h>>"&&!,Q/"&&83x=?+K

DD,=,C,C
DD tH~$$%D
4??8,1ADz  "tDz(()D	$B 2z1%	14:$$% 4??8,1A   		s   *F 	FFc                n   	 ddl }ddl}ddl}|j                  |j                        }|j                  d|j                  |j                              \  }}}|j                  | |j                        }|j                         }	|	j                  |j                  |j                  |j                   z  |j"                  z  |       |	j                  |j                  |j$                  |       |j'                  d|	d       |j)                  | |j                  |       y# t        $ r t        |       cY S w xY w)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   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#=#=>D'5 
	&	&um.U.U	VBD"" 6 66C
 	]779L9LfU  D!,!!%)P)PRTU3  :2599:s   D D43D4c                
  %&'()*+,- ddl +ddl m- +j                  dd      *+j                  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                  |      (+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,                  _        |*j0                  _        -j                  *j0                  _
        -j.                  -j                   |f*j0                  _        |*j2                  _        -j                  *j2                  _
        ||-j&                  (-j&                  (-j&                  )-j&                  )-j&                  f*j2                  _        |*j4                  _        -j                  *j4                  _
        ||-j&                  f*j4                  _        |*j6                  _        -j                  *j6                  _
        (-j                   -j                   f*j6                  _        d&&*+-fd}d''+,fd}d(&*+-fd}d)*fd}d*&*+-fd}	 	 	 	 	 	 	 	 d+*fd}	 	 	 	 	 	 	 	 	 	 d,*fd }d-&()*+-fd!}d.&*+-fd"}d/%(*+fd#} ||      }  |d$ ||            d   }! |       }" ||"%||         ||"%||z  |z  |!        || |      }# ||#      }$ ||$d|"d        ||$      }# || ||#       y)0a  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                      e Zd ZdW  j                  fdW  j                  fdW  j                  fdW  j                  fdW  j                  fgZy)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     sF    HMM*X]]#&'X]]#
r   r   c                J    | sj                  j                               |S r   )WinErrorget_last_error)resultfuncargsctypess      r   _nonzero_successz=_win32_restrict_file_to_user_ctypes.<locals>._nonzero_success  s#    //&"7"7"9::r   c           	     l    j                   dz         }j                         }	 j                  | d |j                  |             |d d  S # t        $ r[}|j
                  k7  r  j                   |j                  z         }j                  | d |j                  |             Y d }~dd }~ww xY w)Nr   )c_charDWORDr   byrefr<   winerrorvalue)WellKnownSidTypepSidcbSidr   ERROR_INSUFFICIENT_BUFFERr   r  r   s       r   r   z?_win32_restrict_file_to_user_ctypes.<locals>.CreateWellKnownSid"  s    !!$ 	[''(8$fllSXFYZ Aw  	[zz66/FMMEKK/2D''(8$fllSXFYZZ		[s   #A 	B3AB..B3c                n   j                  j                  d            }	 j                  | d |       |j
                  j                  sy j                  |j
                  j                        }j                  | ||       |j                  S # t        $ r}|j                  k7  r Y d }~yd }~ww xY wNr   )pointerc_ulongGetUserNameExWr<   r	  contentsr
  create_unicode_buffer)
NameFormatnSizer   lpNameBufferERROR_MORE_DATAr  r   s       r   r   z:_win32_restrict_file_to_user_ctypes.<locals>.GetUserNameEx/  s     v~~a01	"":tU; ~~##33ENN4H4HIz<?!!!  	zz_, -	s   B 	B4B//B4c                   j                  d      }j                  d      }j                  d      }	 j                  | |d j                  |      d j                  |      j                  |             j                  d|j                        }j                  j                  |      j                        }j                  d|j                  dz         }j                  | ||j                  |      |j                  |      j                  |            }	|	sj                         ||j                  |j                  fS # t        $ r}|j                  
k7  r Y d }~d }~ww xY w)Nr   r   r   )r  LookupAccountNameWr  r<   r	  r  r
  castr  LPVOIDr   )lpSystemNamelpAccountNamer  cchReferencedDomainNamepeUser   Sidr  lpReferencedDomainNamesuccessr  r   r  r   s             r   r   z>_win32_restrict_file_to_user_ctypes.<locals>.LookupAccountName>  s[    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 	E2E--E2c                .    j                  | |||       y r   )r   )pAcldwAceRevision
AccessMaskr  r   s       r   r   z@_win32_restrict_file_to_user_ctypes.<locals>.AddAccessAllowedAcea  s     	$$T=*dKr   c           	     ^   j                  d      }	 j                  | |d dj                  |             |j
                  sy  j                  |j
                  z         }j                  | |||j                  |             |S # t        $ r}|j                  k7  r Y d }~od }~ww xY wr  )r  GetFileSecurityWr  r<   r	  r
  r   )	
lpFileNameRequestedInformationnLengthr   pSecurityDescriptorr  r   r  r   s	        r   r   z<_win32_restrict_file_to_user_ctypes.<locals>.GetFileSecurityf  s    ..#
	%%$W% }}<x}}w}}<?!! LL!	
 #"  	zz66 7	s   $B	 		B,B''B,c                ,    j                  | ||       y r   )SetFileSecurityW)r+  r,  r.  r   s      r   r   z<_win32_restrict_file_to_user_ctypes.<locals>.SetFileSecurity  s     	!!*.BDWXr   c                .    j                  | |||       y r   )r   )r.  bDaclPresentpDaclbDaclDefaultedr   s       r   r   zF_win32_restrict_file_to_user_ctypes.<locals>.SetSecurityDescriptorDacl  s     	**+>eUcdr   c                t   d }j                  d      }d }j                  d      }d }j                  d      }d }j                  d      }d }	j                  d      }
	 j                  | |j                  |      |j                  |      |j                  |      |j                  |      |	j                  |
              j
                  |j                  z         } j
                  |j                  z         }j                  |      j                  } j
                  |j                  z         }j                  |      j                  } j
                  |j                  z         }j                  |      } j
                  |
j                  z         }j                  |      }	j                  | |j                  |      |j                  |      |j                  |      |||	j                  |
             |S # t        $ r}|j                  k7  r Y d }~jd }~ww xY wr  )	r  MakeAbsoluteSDr  r<   r	  r   r
  r  r  )pSelfRelativeSecurityDescriptorpAbsoluteSecurityDescriptor"lpdwAbsoluteSecurityDescriptorSizer3  lpdwDaclSizepSacllpdwSaclSizepOwnerlpdwOwnerSizepPrimaryGrouplpdwPrimaryGroupSizer   	pDaclData	pSaclData
pOwnerDatapPrimaryGroupDatar  PACLPSIDr   r  r   s                   r   r6  z;_win32_restrict_file_to_user_ctypes.<locals>.MakeAbsoluteSD  s    '+#-5^^A->*~~a(~~a( q)'~~a0	##/+?@\*\*]+12  (`x}}7Y7_7_'_&b#7X]]\%7%77:	It,557X]]\%7%77:	It,559hmmm&9&99<
Z.GX]]-A-G-GGJ$5t<+'LL;<LL&LL&LL-.	
 +*3  	zz66 7	s   "A&H 	H7H22H7c                @   d }j                  d      }	 j                  | |j                  |              j
                  |j                  z         }j                  | |j                  |             |S # t        $ r}|j                  k7  r Y d }~`d }~ww xY wr  )r  MakeSelfRelativeSDr  r<   r	  r   r
  )r8  r7  lpdwBufferLengthr   r  r   r  r   s       r   rH  z?_win32_restrict_file_to_user_ctypes.<locals>.MakeSelfRelativeSD  s     +/'#>>!,	''+/-. ,R8==;K;Q;Q+Q*T'##'+LL)*	

 /.  	zz66 7	s   "A: :	BBBc                     d} j                  |       }j                  |      j                  }j                  ||        |S )Ni  )create_string_bufferr  r  InitializeAcl)
nAclLengthacl_datar&  r   rE  r   r  s      r   NewAclz3_win32_restrict_file_to_user_ctypes.<locals>.NewAcl  sE    
..z:{{8T*33tZ>r   r   )r   intr  r   r  r   returnr   )r  r   rQ  r   )r  r   rQ  r   )r  r   r  r   rQ  r   )
r&  r   r'  r   r(  r   r  r   rQ  r   )r+  r   r,  r   rQ  r   )r+  r   r,  r   r.  r   rQ  r   )
r.  r   r2  r   r3  r   r4  r   rQ  r   )r7  r   rQ  r   )r8  r   rQ  r   )rQ  r   )r  r   WinDLL	Structurec_void_pPOINTERr   r  errcheckBOOLrestypec_intLPWSTRPULONGargtypesr   r  PDWORDr  LPDWORDr   r   r*  LPCWSTRr0  r6  rH  rL  ).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   r6  rH  rO  	SidAdminsSidUserAclSelfRelativeSD
AbsoluteSDr   r  r  rE  rF  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,EFN/Jj!S!4'
3NE4nEr   c                t    t        j                  t        |       j                         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  )r9   S_IMODEr   r   )r   s    r   get_file_moders    s-     	T%[%%'//069r   JUPYTER_ALLOW_INSECURE_WRITESr    )true1c              #    K   |rdnd}|rdnd}t         j                  t         j                  z  t         j                  z  }	 t	        |       j                          t         j                  dk(  rit        rt                nXt        j                  | |d      }t        j                  |       t         j                  t         j                  z  }t        |        t        j                  t        j                  | |d      ||      5 }t         j                  dk7  r>t        |       }|dk7  r.t        rt                nd|  d	t        |       d
}t!        |      | ddd       y# t        $ r Y w xY w# 1 sw Y   yxY ww)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-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   fdopenrs  octRuntimeError)	r   binarymoderz  	open_flagfdf	file_modemsgs	            r   secure_writer  
  sH     4sDt7H

R[[(2::5IU
 
ww$  )*
 	62BHHRLbjj0I'.	2775)V4dX	N RS77d?%e,IF"(02 K5' R!!$Y 00FH  's++ %  $ sC   ?E?E# B)E?AE3	E?#	E0,E?/E00E?3E<8E?c                 P    dd} | t         _        t        j                  dd       y)z Issue an insecure write warning.c                    t        |       dz   S )N
)r,   )r  r  kwargss      r   format_warningz4issue_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   rQ  r,   )r   formatwarningr   )r  s    r   r  r  @  s'     ,HMM	0 	r   )F)r   r,   r   r   rQ  r   )r   r,   r   zLiteral[None]rQ  Optional[bool])r   r,   r   r  rQ  r  )rQ  r   )rQ  r,   )r?   r,   rQ  r   )r   r,   rQ  r,   )r   r,   rQ  rx   )rQ  rx   r   )r   r,   r   zOptional[Any]rQ  r   )r   )r   r,   r   r,   rQ  r   )r   r,   rQ  None)r   r,   rQ  rP  )r   r,   r  r   rQ  zIterator[Any])rQ  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   rs  getenvr%   r  r  r  r   r   r   <module>r     s8    #  	   
   %  = =  
 <<7LLHSZZ%:%:?%KGG D+u-	 
 9 
 9 
 D 
 DS2(  !6,
'*!>0"   9: $ :# * #77d?'zz~~mT: 	ww$/"4

GY#GHI8l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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   