
    @eً              	          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j0                  dv rd	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jR                  edd      jU                  ejV                        Z,nm ed       ejZ                  dk(  rRej\                  j_                  d d      Z0e0r ee0d
      gZ,n-ej*                  j-                  ejb                  d!d
      gZ,nd"d#gZ,ej*                  j-                  ejb                  d!d
      gZ2ee   e"d$<   d%edee   fd&Z3 e       r/ ejh                  edd      jU                  ejV                        Z5nRejZ                  dk(  r?ej\                  j_                  d d      Z0e0rej*                  j-                  e0d
      gZ5ng Z5nd'd(gZ5ej*                  j-                  ejb                  d)d
      gZ6ee   e"d*<   dee   fd+Z7dedefd,Z8d?d-ed.ee   defd/Z9d?d-ed.ee   defd0Z:ej0                  d1k(  re9Z;ne:Z;d@d-ed2edefd3Z<d4eddfd5Z=d4eddfd6Z>d4ede?fd7Z@ ej                  d8d9      j                         d:v ZCe	d>d4ed;edee   fd<       ZDdAd=ZEy)BzPath utility functions.    N)contextmanager)Path)AnyDictIteratorListOptional   )deprecation)win32darwinJupyterjupyter	UF_HIDDENi   Fnamedefaultreturnc                 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)r   r   s     4/usr/lib/python3/dist-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#   2   s     )511r   c                      t         j                  j                  d      } t        t	        |       j                               } | S )z'Get the real path of the home directory~)r   path
expanduserstrr   resolve)homedirs    r   get_home_dirr+   ;   s4    gg  %G $w-'')*GNr   _dtempsr&   c                 *   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)r&   psts      r   	_do_i_ownr=   G   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_userrH   b   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.
    -)rD   )r,   KeyErrortempfilemkdtemp)r   ds     r   _mkdtemp_oncerO   x   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   rG   rO   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                  F   t         j                  } | j                  d      r| d   S t               rt	        j
                  t        d      S t               }t        j                  dk(  r!t         j                  j                  |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_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!"%&&))'UCC>D
||xww||D)Y77	D**..D1tGY/779::+-v66 ggot,h0CS)$$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   rG   rX   rj   )rY   s    r   jupyter_runtime_dirrn      s7     **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                  ,   g }t         j                  j                  d      rF|j                  d t         j                  d   j	                  t         j
                        D               t               g}t        j                  rlt        t        d      rt        j                         nt        j                  }|r6t         j                  j                  |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.0r;   s     r   	<genexpr>zjupyter_path.<locals>.<genexpr>   s     \!QXXbff%\   )+getuserbaserc   r   )r   r   rG   extendsplitpathseprj   siteENABLE_USER_SITEr4   r~   	USER_BASEr&   rf   appendrq   SYSTEM_JUPYTER_PATHrH   rX   )rr   pathsuseruserbaseuserdirr;   rY   s          r   jupyter_pathr      s<   , E 
zz~~n%\rzz./I/O/OPRPZPZ/[\\ D *1})E4##%4>>ggll8Wi@Gd"G$&
G!3F*F1
GC
G#%STTS 
LL$% -23q#7#33L H 4s   7FF5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                  rlt        t        d      rt        j                         nt        j                  }|r6t         j                  j                  |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.
    rQ   JUPYTER_CONFIG_PATHc              3   Z   K   | ]#  }|j                  t        j                         % y wrv   rw   rz   s     r   r|   z&jupyter_config_path.<locals>.<genexpr>F  s     c!QXXbff%cr}   r~   r   r   )r   r   rG   r[   r   r   r   r   r   r4   r~   r   r&   rf   r   r   SYSTEM_CONFIG_PATHrH   )r   r   r   r   r;   rY   s         r   jupyter_config_pathr   4  s4    
zz~~)*"$%%E 
zz~~+,crzz:O/P/V/VWYWaWa/bcc  !D *1})E4##%4>>ggll8UI>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   lstatr8   )r&   s    r   r/   r/   c  s+    
   s    	$$abs_pathstat_resc                    t         j                  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&   basenamerF   r5   r8   errnoENOENTst_file_attributesFILE_ATTRIBUTE_HIDDENAttributeErrorwarningswarnr   r   es      r   is_file_hidden_winr   n  s      
ww!,,S1	wwx(H''(() ) +  	ww%,,&	   	b	
 	s/   A) 	B )	B2BBB C ?C c                    t         j                  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&   r   rF   r5   S_ISLNKst_moder8   r   r   S_ISDIRr9   X_OKR_OKgetattrr   r   s      r   is_file_hidden_posixr     s      
ww!,,S14<<(8(89	wwx(H ||H$$%yy277RWW#45 xQ')3  	ww%,,&	s   C 	DC>=C>>Dr   abs_rootc                 4   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 |j	                  t         j
                        D              ryt         j                  j                  |       }|r|j                  |      r||k7  rt        |      s t         j                  j                  |      }C	 t        j                  |      }t        |dd      t        z  ryt         j                  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)rF   )r{   parts     r   r|   zis_hidden.<locals>.<genexpr>  s     
FD4??3
Fs   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     sF   ( ww)Hww)H8h>>"&&!,Q/"&&83x=?+K

FK,=,=bff,E
FF 77??8$D
4??8,1Ad|77??4(D	$B 2z1%	1wwt$ 4??8,1A   		s   (F 	FFfnamec                 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)
r   r   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U1  :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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.                  _        |*j0                  _
        -j                  *j0                  _        -j2                  -j$                  |-j$                  -j*                  f*j0                  _        |*j4                  _
        -j                  *j4                  _        -j2                  -j$                  |f*j4                  _        |*j6                  _
        -j                  *j6                  _        ||-j*                  (-j*                  (-j*                  )-j*                  )-j*                  f*j6                  _        |*j8                  _
        -j                  *j8                  _        ||-j*                  f*j8                  _        |*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        ||$      }# || ||#       y)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                       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   resultfuncargsr   c                 J    | sj                  j                               |S rv   )WinErrorget_last_error)r   r   r   ctypess      r   _nonzero_successz=_win32_restrict_file_to_user_ctypes.<locals>._nonzero_successm  s#    //&"7"7"9::r   WellKnownSidTypec           	      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   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$fllSXFYZ Aw  	[zz66/FMMEKK/2D''(8$fllSXFYZZ		[s   #A 	B3AB..B3
NameFormatc                 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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1	"":tU; ~~##33ENN4H4HIz<?!!!  	zz_, -	s   B 	B4B//B4lpSystemNamelpAccountNamec                    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  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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pAcldwAceRevision
AccessMaskr  c                 .    j                  | |||       y rv   )r   )r  r  r   r  r   s       r   r   z@_win32_restrict_file_to_user_ctypes.<locals>.AddAccessAllowedAce  s     	$$T=*dKr   
lpFileNameRequestedInformationc           	      ^   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  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% }}<x}}w}}<?!! LL!	
 #"  	zz66 7	s   $B	 		B,B''B,r'  c                 ,    j                  | ||       y rv   )SetFileSecurityW)r"  r#  r'  r   s      r   r   z<_win32_restrict_file_to_user_ctypes.<locals>.SetFileSecurity1  s     	!!*.BDWXr   bDaclPresentpDaclbDaclDefaultedc                 .    j                  | |||       y rv   )r   )r'  r*  r+  r,  r   s       r   r   zF_win32_restrict_file_to_user_ctypes.<locals>.SetSecurityDescriptorDacl7  s     	**+>eUcdr   pSelfRelativeSecurityDescriptorc                 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  r8   r  r   r  r  r  )r.  pAbsoluteSecurityDescriptor"lpdwAbsoluteSecurityDescriptorSizer+  lpdwDaclSizepSacllpdwSaclSizepOwnerlpdwOwnerSizepPrimaryGrouplpdwPrimaryGroupSizer   	pDaclData	pSaclData
pOwnerDatapPrimaryGroupDatar  PACLPSIDr   r   r   s                   r   r0  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r1  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  r8   r  r   r  )r1  r.  lpdwBufferLengthr   r  r   r   r   s       r   rA  z?_win32_restrict_file_to_user_ctypes.<locals>.MakeSelfRelativeSDs  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   r   WinDLL	Structurec_void_pPOINTERr   intr   r  errcheckBOOLrestypec_intLPWSTRPULONGargtypesr   r  PDWORDr  LPDWORDr   r   r%  LPCWSTRr)  r0  rA  rE  ).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   r0  rA  rH  	SidAdminsSidUserAclSelfRelativeSD
AbsoluteSDr   r  r  r>  r?  r   r   r   r   s.                                        @@@@@@@@@r   r   r   +  s5    }}Z}=HmmIdm;G"$ !L #OKF&"#NLOM.<uDO~-0DD|SVaa  	
	
	  	 		
 	 
f 
 ??D>>#D!>>(--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$&.mmH#(H$ ,<H(*2--H',H( '7H#%-]]H"'H#S S  "# "# "!? !?C !?C !? !?FL# Lc Ls LRU LZ] L
#C #s #s # #4YY/2YILY	Ye e03e<?eQTe	e4+ 4+ 4+ 4+l/ / / /,C   ##>?IM2C$DEaHG
(C\?IF..7	 %U,EFN/Jj!S!4'
3NE4nEr   c                 l    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_moderk    s(     	RWWU^++,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                  |        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-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   fdopenrk  octRuntimeError)	r   ro  moders  	open_flagfdf	file_modemsgs	            r   secure_writer    sD     4sDt7H

R[[(2::5I
		%
 
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E/	E;	E,(E;+E,,E;/E84E;c                      dt         dt        dt        dt         fd} | t        _        t        j                  dd       y	)
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    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   formatwarningr   )r  s    r   ry  ry    sC    C  s s  ,HMM	0 	r   )Frv   )r   )r   N)F__doc__r   r   r   r5   rC   rL   r   
contextlibr   pathlibr   typingr   r   r   r   r	   rU   utilsr   r&   rf   rX   re   rW   r   r   r(   boolr   r#   r+   r,   __annotations__r=   rH   rO   r[   rj   rn   site_data_dirr   r   r   r   r   rG   programdatarD   rq   r   site_config_dirr   r   r   r/   r   r   r   r   r   r   rM  rk  getenvr   rx  r  ry  r"   r   r   <module>r     s     	   
   %  6 6  
 ||'::)	 D+u-	S Sx~ S(4. S24 2c  c3h !C !D !6d ,
 
 
'C '*%# %B0S 0  4,445DeBJJ  	K 
ww$jjnn]D9#(i#@"A#%77<<

GY#O"P ' 

  "ww||CJJKL $s) L83 849 8v 5555DeBJJ  
ww$jjnn]D9"$'',,{I"F!G!# %
 !ggll3::uiHIc I,T#Y ,^  + + + +\%3 %(3- %4 %P <<7'N)N3 3s 3D 3l(Vs (Vt (VVwFs wFt wFt  & "		"A7KQQSWdd  2 2T 2hsm 2 2jr   