
    lCeK              	       B   U d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZmZmZmZmZ ddlZddlmZ ej        j        Zej        dk    s%ej        d	k    rej                            d
          sdZndZ eedd          Zd@dedee         dee         fdZ defdZ!defdZ"i Z#eeef         e$d<   dedefdZ%defdZ&dedefdZ'defdZ(defdZ)defdZ* e!            r, ej+        edd          ,                    ej-                  Z.nh ed            ej/        d!k    rNej0        1                    d"d          Z2e2r ee2d          gZ.n'ej                            ej        d#d          gZ.nd$d%gZ.ej                            ej        d#d          gZ3ee         e$d&<   d'edee         fd(Z4 e!            r, ej5        edd          ,                    ej-                  Z6nLej/        d!k    r=ej0        1                    d"d          Z2e2rej                            e2d          gZ6ng Z6nd)d*gZ6ej                            ej        d+d          gZ7ee         e$d,<   dee         fd-Z8dedefd.Z9dAd/ed0ee         defd1Z:dAd/ed0ee         defd2Z;ej        dk    re:Z<ne;Z<dBd/ed4edefd5Z=d6eddfd7Z>d6eddfd8Z?d6ede@fd9ZA ejB        d:d;          C                                d<v ZDe	d@d6ed=edee         fd>            ZEdCd?ZFdS )DzPath utility functions.    N)contextmanager)Path)AnyDictIteratorListOptional   )deprecationwin32darwinz/opt/homebrewJupyterjupyter	UF_HIDDENi   Fnamedefaultreturnc                 n    | t           j        vr|S t           j        |                                          dvS )a%  Return the boolean value of a given environment variable.

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

    If the environment variable is not defined, the default value is returned.
    )nonfalseoff0z0.0)osenvironlower)r   r   s     2lib/python3.11/site-packages/jupyter_core/paths.pyenvsetr   )   s5     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11r   c                      t           j                            d          } t          t	          |                                                     } | S )z'Get the real path of the home directory~)r   path
expanduserstrr   resolve)homedirs    r   get_home_dirr+   @   s=    g  %%G $w--''))**GNr   _dtempsr&   c                 :   t          |                                           }|                                s1||j        k    r&|j        }|                                s||j        k    &	 |                                t          j                    k    S # t          $ r Y nw xY wt          t
          d          rH	 |	                                }|j
        t          j                    k    S # t          t          f$ r Y nw xY wt          j        |t
          j                  S )z3Return whether the current user owns the given pathgeteuid)r   r)   existsparentownerr   getlogin	Exceptionhasattrstatst_uidr.   NotImplementedErrorOSErroraccessW_OK)r&   psts      r   	_do_i_ownr=   L   s
   T

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

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

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

    These are non-transient, non-configuration files.

    Returns JUPYTER_DATA_DIR if defined, else a platform-appropriate path.
    JUPYTER_DATA_DIRFrS   r   Libraryr   ntAPPDATANr   dataXDG_DATA_HOMEz.localshare)r   r   rG   r#   rU   user_data_dirrW   r+   rC   platformr&   joinr   r(   r   r)   rX   r[   )rY   homeappdataxdgs       r   jupyter_data_dirrj      s     *C
ww!"" '%&& D)'UCCCC>>D
|xw||D)Y777	D*..D11 	7tGY//7799:::+--v666 ggot,, 	1h00CS)$$$r   c                      t           j        } |                     d          r| d         S t          t	                      d          S )zReturn the runtime dir for transient jupyter files.

    Returns JUPYTER_RUNTIME_DIR if defined.

    The default is now (data_dir)/runtime on all platforms;
    we no longer use XDG_RUNTIME_DIR after various problems.
    JUPYTER_RUNTIME_DIRruntime)r   r   rG   rX   rj   )rY   s    r   jupyter_runtime_dirrn      sC     *C
ww$%% *())!##Y///r   T)rT   	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` v6r_   PROGRAMDATArc   z/usr/local/share/jupyterz/usr/share/jupyterENV_JUPYTER_PATHsubdirsc                  4    g }t           j                            d          rL|                    d t           j        d                             t           j                  D                        t                      g}t          j        rpt          t          d          rt          j
                    nt          j        }|r:t           j                            |dd          }||vr|                    |           d t          D             }t!                      r+|                    |           |                    |           n*|                    |           |                    |           |                    t"                      r fd|D             }|S )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   T   K   | ]#}|                     t          j                  V  $d S Nrstripr   sep.0r;   s     r   	<genexpr>zjupyter_path.<locals>.<genexpr>  s0      \\!QXXbf%%\\\\\\r   getuserbaserc   r   c                 $    g | ]}|t           v|S r"   )SYSTEM_JUPYTER_PATHrz   s     r   
<listcomp>z jupyter_path.<locals>.<listcomp>  s#    
G
G
G!3F*F*F1*F*F*Fr   c                 *    g | ]}t          |gR  S r"   )rX   )r{   r;   rr   s     r   r   z jupyter_path.<locals>.<listcomp>"  s)    333q#7###333r   )r   r   rG   extendsplitpathseprj   siteENABLE_USER_SITEr4   r}   	USER_BASEr&   rf   appendrq   rH   r   )rr   pathsuseruserbaseuserdirrY   s   `     r   jupyter_pathr      s   , E 
z~~n%% ]\\rz./I/O/OPRPZ/[/[\\\\\\ D 	% *1})E)EY4#%%%4> 	%gll8Wi@@Gd""G$$$
G
G&
G
G
GC#%% STTS 
LL$%%%  43333U333Lr   z/usr/local/etc/jupyterz/etc/jupyteretcENV_CONFIG_PATHc                  n   t           j                            d          rt                      gS g } t           j                            d          rL|                     d t           j        d                             t           j                  D                        t                      g}t          j        rpt          t          d          rt          j
                    nt          j        }|r:t           j                            |dd          }||vr|                    |           d t          D             }t!                      r+|                     |           |                     |           n*|                     |           |                     |           |                     t"                     | S )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.
    rQ   JUPYTER_CONFIG_PATHc              3   T   K   | ]#}|                     t          j                  V  $d S rv   rw   rz   s     r   r|   z&jupyter_config_path.<locals>.<genexpr>K  s0      cc!QXXbf%%ccccccr   r}   r   r   c                 $    g | ]}|t           v|S r"   )SYSTEM_CONFIG_PATHrz   s     r   r   z'jupyter_config_path.<locals>.<listcomp>Z  s#    
E
E
E2D)D)D1)D)D)Dr   )r   r   rG   r[   r   r   r   r   r   r4   r}   r   r&   rf   r   r   rH   r   )r   r   r   r   rY   s        r   jupyter_config_pathr   9  s    
z~~)** &"$$%%E 
z~~+,, dccrz:O/P/V/VWYWa/b/bcccccc   !D 	% *1})E)EY4#%%%4> 	%gll8UI>>Gd""G$$$
E
Eo
E
E
EC#%% STTS 
LL#$$$Lr   c                 T    	 t          j        |            n# t          $ r Y dS w xY wdS )zcReplacement for `os.path.exists` which works for host mapped volumes
    on Windows containers
    FT)r   lstatr8   )r&   s    r   r/   r/   h  s=    
   uu4s    
%%abs_pathstat_resc                 v   t           j                            |                               d          rdS |D	 t          j        |           }n.# t
          $ r!}|j        t          j        k    rY d}~dS  d}~ww xY w	 |j        t          j	        z  rdS n&# t          $ r t          j        dd           Y nw xY wdS )  Is a file hidden?

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

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

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

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

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

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

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

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

    Parameters
    ----------

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

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

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

    Parameters
    ----------

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

 /.s   *A 
A%A  A%c                      d}                      |           }                    |          j        }                    ||            |S )Ni  )create_string_bufferr  r  InitializeAcl)
nAclLengthacl_datar!  r   rA  r   r   s      r   NewAclz3_win32_restrict_file_to_user_ctypes.<locals>.NewAcl  sN    
..z::{{8T**3tZ>>>r   r   )r   r   WinDLL	Structurec_void_pPOINTERr   intr   r  errcheckBOOLrestypec_intLPWSTRPULONGargtypesr   r  PDWORDr  LPDWORDr   r   r(  LPCWSTRr,  r3  rD  rH  ).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   r3  rD  rK  	SidAdminsSidUserAclSelfRelativeSD
AbsoluteSDr   r
  r  rA  rB  r   r   r   r   s.                                        @@@@@@@@@r   r   r   0  s    MMM}}Z}==HmmIdm;;G"$ !L #OKF&"#NLOM.<uDO~-0DD|SVaa  	
	
	  	 		
 	 
 
 
 
 
 
 
f 
 
 
 ?D>>#D!>>(-88 C s s      
 '7G#%-]G"'G# ,<H(*2-H'	,H( ,<H(*2-H',H( -=H )+3=H (	-H ) 3CH&/19H&.	3H&/ *:H&(0H%*H& *:H&(0H%*H& (8H$&.mH#(H$ ,<H(*2-H',H( '7H#%-]H"'H#S S         "# "# " " " " " " " "!? !?C !?C !? !? !? !? !? !? !? !? !?FL# Lc Ls LRU LZ] L L L L L L
#C #s #s # # # # # # # # #4YY/2YILY	Y Y Y Y Y Ye e03e<?eQTe	e e e e e e4+ 4+ 4+ 4+ 4+ 4+ 4+ 4+ 4+ 4+ 4+ 4+ 4+l/ / / / / / / / / / /,C          #"#>??IMM2C$D$DEEaHG
&((C\?IFFF..7	   %_U,EFFN//Jj!S!444''
33NOE4nEEEEEr   c                 ^    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  )r5   S_IMODEr   r   )r   s    r   get_file_modern    s&     	RWU^^+,,v5r   JUPYTER_ALLOW_INSECURE_WRITESr   )true1binaryc              #     K   |rdnd}|rdnd}t           j        t           j        z  t           j        z  }	 t          j        |            n# t
          $ r Y nw xY wt           j        dk    rht          rt                       nRt          j	        | |d          }t          j
        |           t           j        t           j        z  }t          |            t          j        t          j	        | |d          ||          5 }t           j        dk    rPt          |           }|dk    r;t          rt                       n%d|  d	t          |           d
}t          |          |V  ddd           dS # 1 swxY w Y   dS )aD  Opens a file in the most restricted pattern available for
    writing content. This limits the file mode to `0o0600` and yields
    the resulting opened filed handle.

    Parameters
    ----------

    fname : unicode
        The path to the file to write

    binary: boolean
        Indicates that the file is binary
    wbwNzutf-8r_   i  )encodingz0Permissions assignment failed for secure file: 'z'. Got 'z' instead of '0o0600'.)r   O_CREATO_WRONLYO_TRUNCremover8   r   allow_insecure_writesissue_insecure_write_warningopencloser   fdopenrn  octRuntimeError)	r   rr  moderv  	open_flagfdf	file_modemsgs	            r   secure_writer    s      "44sD*tt7H
R[(2:5I
	%    
w$  	/ )****
 	622BHRLLLbj0I'...	275)V44dX	N	N	N RS7d??%e,,IF""( ,02222H5 H H!$YH H H  's+++                 s$   A 
AA>A%E00E47E4c                      dt           dt          dt          dt           fd} | t          _        t          j        dd           d	S )
z Issue an insecure write warning.r  r   kwargsr   c                 &    t          |           dz   S )N
)r(   )r  r   r  s      r   format_warningz4issue_insecure_write_warning.<locals>.format_warning  s    3xx$r   zWARNING: Insecure writes have been enabled via environment variable 'JUPYTER_ALLOW_INSECURE_WRITES'! If this is not intended, remove the variable or set its value to 'False'.r   r   N)r(   r   r   formatwarningr   )r  s    r   r|  r|    si    C  s s     ,HM	0 	     r   )Frv   )r   )r   N)G__doc__r   r   r   r5   rC   rL   r   
contextlibr   pathlibr   typingr   r   r   r   r	   rU   utilsr   r&   rf   rX   re   rD   rF   rW   r   r   r(   boolr   r#   r+   r,   __annotations__r=   rH   rO   r[   rj   rn   site_data_dirr   r   r   r   r   rG   programdatarq   r   site_config_dirr   r   r   r/   r   r   r   r   r   r   rP  rn  getenvr   r{  r  r|  r"   r   r   <module>r     sG       				   



   % % % % % %       6 6 6 6 6 6 6 6 6 6 6 6 6 6          
 <7LHSZ%:%:?%K%KGGG GD+u--	S S Sx~ S(4. S S S S24 2 2 2 2c     c3h   !C !D ! ! ! !6d    ,
 
 
 
 
 
'C ' ' ' '*%# % % % %B0S 0 0 0 0   
4,45D  eBJ  K	K   
w$jnn]D99 	Q#(5i#@#@"A#%7<<
GY#O#O"P ' 

  "w||CJKKL $s) L L L83 849 8 8 8 8v  
555D  eBJ  
w$jnn]D99 	$"$',,{I"F"F!G!# %
 !gll3:uiHHIc I I I,T#Y , , , ,^     + + + + + + + +\% %3 %(3- %4 % % % %P <7'NN)N3 3 3s 3D 3 3 3 3l(Vs (Vt (V (V (V (VVwFs wFt wF wF wF wFt     & "	"A7KKQQSSWdd  2 2 2T 2hsm 2 2 2 2j     r   