
    f                       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 ddlZddlmZ ej*                  j,                  Zej0                  d	k(  s*ej0                  d
k(  rej2                  j5                  d      sdZndZ eedd      Zd8d9dZd:dZd;dZ i Z!de"d<   d<dZ#d:dZ$d=dZ%d;dZ&d;dZ'd;dZ( e       r/ ejR                  edd      jU                  ejV                        Z,n` ed       ejZ                  dk(  rEej\                  j_                  d d      Z0e0r ee0d      gZ,n  e1 eej2                  d!d            gZ,nd"d#gZ, e1 eej2                  d!d            gZ2d$e"d%<   d>d&Z3 e       r/ ejh                  edd      jU                  ejV                        Z5nEejZ                  dk(  r2ej\                  j_                  d d      Z0e0r e1 ee0d            gZ5ng Z5nd'd(gZ5 e1 eej2                  d)d            gZ6d$e"d*<   d?d+Z7d<d,Z8d@dAd-Z9d@dAd.Z:ej0                  d	k(  re9Z;ne:Z;dBdCd/Z<dDd0Z=dDd1Z>dEd2Z? ej                  d3d4      j                         d5v ZBed8dFd6       ZCdGd7ZDy)HzPath utility functions.    )annotationsN)contextmanager)Path)AnyIteratorOptional   )deprecationwin32darwinz/opt/homebrewJupyterjupyter	UF_HIDDENi   Fc                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lower)namedefaults     M/var/www/cvtools/html/venv/lib/python3.12/site-packages/jupyter_core/paths.pyenvsetr   )   s3     2::::d!!#+RRR    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   use_platform_dirsr!   7   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(   @   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_uidr+   NotImplementedErrorOSErroraccessW_OK)pathpsts      r   	_do_i_ownr;   K   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_prefixr;   
startswithgetr    r   r   prefer_environment_over_userrF   f   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.
    -)rB   )r)   KeyErrortempfilemkdtemp)r   ds     r   _mkdtemp_oncerM   |   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   rE   rM   r!   platformdirsuser_config_dirAPPNAMEr(   pjoin)envhome_dirs     r   jupyter_config_dirrY      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_DIRFrQ   r   Libraryr   r   APPDATANr   dataXDG_DATA_HOMEz.localshare)r   r   rE   r!   rS   user_data_dirrU   r(   rA   platformr%   r   r&   rV   rY   )rW   homeappdataxdgs       r   jupyter_data_dirrf      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   rE   rV   rf   )rW   s    r   jupyter_runtime_dirrj      s7     **C
ww$%())!#Y//r   T)rR   	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` v6ntPROGRAMDATAr`   z/usr/local/share/jupyterz/usr/share/jupyter	list[str]ENV_JUPYTER_PATHc                    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        D cg c]  }|t         vs| }}t#               r#|j                  |       |j                  |       n"|j                  |       |j                  |       |j                  t                | r|D cg c]  }t%        |g|   }}|S c c}w c c}w )a  Return a list of directories to search for data files

    JUPYTER_PATH environment variable has highest priority.

    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.


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

    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Nrstripr   sep.0r9   s     r   	<genexpr>zjupyter_path.<locals>.<genexpr>  s     \!QXXbff%\   )+getuserbaser`   r   )r   r   rE   extendsplitpathseprf   siteENABLE_USER_SITEr1   r{   	USER_BASEr%   r   appendro   SYSTEM_JUPYTER_PATHrF   rV   )subdirspathsuseruserbaseuserdirr9   rW   s          r   jupyter_pathr      s9   , E 
zz~~n%\rzz./I/O/OPRPZPZ/[\\ D *1})E4##%4>>$x)<=Gd"G$&
G!3F*F1
GC
G#%STTS 
LL$% -23q#7#33L H 4s   ,F:F*Fz/usr/local/etc/jupyterz/etc/jupyteretcENV_CONFIG_PATHc                 *   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        D cg c]  }|t         vs| }}t#               r#| j	                  |       | j	                  |       n"| j	                  |       | j	                  |       | j	                  t                | S c c}w )ar  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.
    rO   JUPYTER_CONFIG_PATHc              3  Z   K   | ]#  }|j                  t        j                         % y wrs   rt   rw   s     r   ry   z&jupyter_config_path.<locals>.<genexpr>H  s     c!QXXbff%crz   r{   r   r   )r   r   rE   rY   r|   r}   r~   r   r   r1   r{   r   r%   r   r   r   SYSTEM_CONFIG_PATHrF   )r   r   r   r   r9   rW   s         r   jupyter_config_pathr   6  s1    
zz~~)*"$%%E 
zz~~+,crzz:O/P/V/VWYWaWa/bcc  !D *1})E4##%4>>$x	:;Gd"G$%
E2D)D1
EC
E#%STTS 
LL#$L Fs   F$F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   lstatr5   )r8   s    r   r,   r,   e  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   rD   r2   r5   errnoENOENTst_file_attributesFILE_ATTRIBUTE_HIDDENAttributeErrorwarningswarnabs_pathstat_reses      r   is_file_hidden_winr   p  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   rD   r2   S_ISLNKst_moder5   r   r   S_ISDIRr   r6   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)rD   )rx   parts     r   ry   zis_hidden.<locals>.<genexpr>  s     
DD4??3
Ds   r   )r   r8   normpathis_file_hiddenr}   rv   lenanyr   partsr%   r-   rD   r,   r   r5   r   r   )r   abs_rootinside_rootr8   r:   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     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   b  sF    HMM*X]]#&'X]]#
r   r   c                J    | sj                  j                               |S rs   )WinErrorget_last_error)resultfuncargsctypess      r   _nonzero_successz=_win32_restrict_file_to_user_ctypes.<locals>._nonzero_successo  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   byrefr5   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GetUserNameExWr5   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   r5   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 rs   )r   )pAcldwAceRevision
AccessMaskr  r   s       r   r   z@_win32_restrict_file_to_user_ctypes.<locals>.AddAccessAllowedAce  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   r5   r   r   r   )	
lpFileNameRequestedInformationnLengthr   pSecurityDescriptorr  r   r   r   s	        r   r   z<_win32_restrict_file_to_user_ctypes.<locals>.GetFileSecurity  s    ..#
	%%$W% }}<x}}w}}<?!! LL!	
 #"  	zz66 7	s   $B	 		B,B''B,c                ,    j                  | ||       y rs   )SetFileSecurityW)r!  r"  r$  r   s      r   r   z<_win32_restrict_file_to_user_ctypes.<locals>.SetFileSecurity3  s     	!!*.BDWXr   c                .    j                  | |||       y rs   )r   )r$  bDaclPresentpDaclbDaclDefaultedr   s       r   r   zF_win32_restrict_file_to_user_ctypes.<locals>.SetSecurityDescriptorDacl9  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   r5   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   r,  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   r5   r   r   r   )r.  r-  lpdwBufferLengthr   r  r   r   r   s       r   r>  z?_win32_restrict_file_to_user_ctypes.<locals>.MakeSelfRelativeSDu  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   r;  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   rG  r   )r  r   rG  r   )r  r   r  r   rG  r   )
r  r   r  r   r  r   r  r   rG  r   )r!  r   r"  r   rG  r   )r!  r   r"  r   r$  r   rG  r   )
r$  r   r(  r   r)  r   r*  r   rG  r   )r-  r   rG  r   )r.  r   rG  r   )rG  r   )r   r   WinDLL	Structurec_void_pPOINTERr   r	  errcheckBOOLrestypec_intLPWSTRPULONGargtypesr   r   PDWORDr  LPDWORDr   r   r   LPCWSTRr&  r,  r>  rB  ).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,  r>  rE  	SidAdminsSidUserAclSelfRelativeSD
AbsoluteSDr   r  r  r;  r<  r   r   r   r   s.                                        @@@@@@@@@r   r   r   -  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  )r2   S_IMODEr   r   )r   s    r   get_file_moderi    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-8rl   i  )encodingz0Permissions assignment failed for secure file: 'z'. Got 'z' instead of '0o0600'.)r   O_CREATO_WRONLYO_TRUNCr   unlinkr5   r   allow_insecure_writesissue_insecure_write_warningopencloser   fdopenri  octRuntimeError)	r   binarymoderp  	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_warning  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   rG  r%   )r   formatwarningr   )r  s    r   rv  rv    s'     ,HMM	0 	r   )F)r   r%   r   Optional[bool]rG  r  )rG  bool)rG  r%   )r8   r%   rG  r  )r   r%   rG  r%   )r   r%   rG  rn   )rG  rn   rs   )r   r%   r   zOptional[Any]rG  r  )r   )r   r%   r   r%   rG  r  )r   r%   rG  None)r   r%   rG  rF  )r   r%   r|  r  rG  zIterator[Any])rG  r  )E__doc__
__future__r   r   r   r   r2   rA   rJ   r   
contextlibr   pathlibr   typingr   r   r   rS   utilsr
   r8   joinrV   rb   rB   rD   rU   r   r   r   r!   r(   r)   __annotations__r;   rF   rM   rY   rf   rj   site_data_dirr}   r~   r   r   r   rE   programdatar%   ro   r   site_config_dirr   r   r   r,   r   r   r   r   r   r   ri  getenvr   ru  r  rv  r    r   r   <module>r     s    #  	   
   %  * *  
 <<7LLHSZZ%:%:?%KGG D+u-	S2(  !6,
'*!>0  4,445DeBJJ  	K 
ww$jjnn]D9#(i#@"A#&tCJJ'K#L"M ' 

  #4

GY#GHI ) I8v 5555DeBJJ  
ww$jjnn]D9"%d;	&B"C!D!# %
 "$szz5)"DEF F,^*Z%P <<7'N)N3l)XwFt& "		"A7KQQSWdd  2 2jr   