
    rh                       S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r
SSK	Jr  SSKJs  Jr  SSKJr  SSKJr  SSKJr  SrSS	 jr " S
 S\R.                  5      r " S S\5      r " S S\5      r " S S5      r\" 5       SS.rS r " S S5      r " S S5      r S r!S r"S r# " S S\RH                  5      r%\ \\/r&\'S:X  a  SSKr\RP                  " \%5        gg)a  
The environment module describes an object for accessing and setting
variables related to the user's music21 environment. Such variables include
the location of external applications such as MusicXML readers (e.g. MuseScore),
whether music21 is allowed to download files directly (via the virtual corpus),
and other settings.

Additional documentation for and examples of using this module are found in
:ref:`User's Guide, Chapter 24, Environment <usersGuide_24_environment>`.

# TODO: Update to user's guide -- showing each function
    )annotationsN)overload)saxutils)exceptions21)commonenvironmentc                8   SX-  S-  -   n[        U 5      (       a  U R                  (       a  U R                  R                  5       (       d  X2S-  -   U l        U R                  (       a  U R                  R                  5       (       d  X0l        U  H  n[	        XAS-   5        M     U R                  (       a  U R                  R                  5       (       d  X0l        ggU(       a8  U R                  (       a  U R                  R                  5       (       d  X0l        ggg)z,
indent an elementTree element for printing

    N)lentextstriptailetIndent)elemlevelspacesisubEls        M/home/james-whalen/.local/lib/python3.13/site-packages/music21/environment.pyr   r   .   s     	u~##A
4yyyy		 1 1SL(DIyy		 1 1IEUAI& yy		 1 1I !2 $))499??+<+<I ,=5    c                      \ rS rSrSrg)EnvironmentExceptionD    N__name__
__module____qualname____firstlineno____static_attributes__r   r   r   r   r   D       r   r   c                      \ rS rSrSrg)UserSettingsExceptionH   r   Nr   r   r   r   r%   r%   H   r#   r   r%   c                  <   ^  \ rS rSrSrSU 4S jjrU 4S jrSrU =r$ )LocalCorpusSettingsN   a  
A lightweight object for storing the 'LocalCorpusSettings' tag in the
.music21rc

It is a subclass of list and has two additional attributes, name (which
should be None for the unnamed localCorpus) and cacheFilePath
for a full filepath (ending in .json) as a location
to store the .metadataBundle (.json) cache for the
LocalCorpus.  This can be None, in which case the (volatile) temp
directory is used.

>>> lcs = environment.LocalCorpusSettings(['/tmp', '/home'])
>>> lcs
LocalCorpusSettings(['/tmp', '/home'])

>>> lcs.name = 'theWholeEnchilada'
>>> lcs
LocalCorpusSettings(['/tmp', '/home'], name='theWholeEnchilada')

>>> lcs.cacheFilePath = '/home/enchilada.json'
>>> lcs
LocalCorpusSettings(['/tmp', '/home'],
                    name='theWholeEnchilada',
                    cacheFilePath='/home/enchilada.json')


>>> list(lcs)
['/tmp', '/home']
>>> lcs.name
'theWholeEnchilada'
>>> lcs.cacheFilePath
'/home/enchilada.json'
>>> '/home' in lcs
True
>>> '/root' in lcs
False
c                F   > Uc  / n[         TU ]  U5        X l        X0l        g N)super__init__namecacheFilePath)selfpathsr.   r/   	__class__s       r   r-   LocalCorpusSettings.__init__u   s%    =E	*r   c                   > [         TU ]  5       nSnSnU R                  b  S[        U R                  5      -   nU R                  b  S[        U R                  5      -   nSU U U S3$ )N z, name=z, cacheFilePath=zLocalCorpusSettings())r,   __repr__r.   reprr/   )r0   listReprnamePartmdbpPartr2   s       r   r7   LocalCorpusSettings.__repr__|   sn    7#%99  4		?2H))D1C1C,DDH%hZz(1EEr   )r/   r.   )NNN)	r   r   r    r!   __doc__r-   r7   r"   __classcell__)r2   s   @r   r(   r(   N   s    $L+F Fr   r(   c                      \ rS rSrSrSS jrS rS rS rS r	SS	 jr
SS
 jrSS jrSS jrS rS rS rS rS rSSS jjrS rS rS rSS jrS rSS jrSrg)_EnvironmentCore   ax  
This private class should never be directly created; use the Environment
object to access this object.

Multiple Environment instances may exist, but all share access to the same
_EnvironmentCore instance that is stored in this module.

The only case in which a new _EnvironmentCore is created is if the
forcePlatform argument is passed and is different from the stored
forcePlatform argument. This is only used in testing--it allows authors to
test what the settings on a different platform (win, Mac, etc.) would be.

NOTE: this is a private class. All documentation for public methods should
be placed in the Environment class.
Nc                    0 U l         / U l        S H  nU R                  R                  U5        M      U R                  US9  Uc  U R	                  5         S U l        g )N)
braillePathgraphicsPathlilypondPathlocalCorpusPathmanualCoreCorpusPathmidiPathmusescoreDirectPNGPathmusicxmlPathpdfPath
vectorPathforcePlatform)_ref_keysToPathsappend_loadDefaultsreaddefaultRootTempDir)r0   rN   pathKeys      r   r-   _EnvironmentCore.__init__   sa     	 
G $$W-
 	7 IIK"&r   c                   XR                   ;  a  US:w  a  [        SU 35      eUS:w  a  U R                   U   nO/[        U R                   S   5      n[        U5      S:  a  US   nOSn[	        U[
        5      (       a  UR                  SSS9n[        U5      R                  5       nUS	:X  a  US
:X  a  [        R                  nO~US:X  a  [        R                  nOgSU;   a  [        R                  nOPSU;   a  [        R                  nO9SU;   a  [        R                  nO"SU;   a  [        R                  nO[        U5      nUb1  US:w  a+  XR                  5       ;   a  [         R"                  " U5      nU$ S nU$ )NrF   no preference: localCorpusSettingsr   r5   utf-8replace)encodingerrorsdebugtruefalseoffuserdevelall)rO   r   listr   
isinstancebytesdecodestrlowerr   
DEBUG_USER	DEBUG_OFFDEBUG_DEVEL	DEBUG_ALLintgetKeysToPathspathlibPath)r0   keyvaluer1   valueStrs        r   __getitem___EnvironmentCore.__getitem__   sZ    iiC+<$<&'>??##IIcNE#89:E5zA~aeU##LL')LDEu:##%'>6!))W$((("((8#))H$**("((E
"))++U+  Er   c                    g)Nz<Environment>r   r0   s    r   r7   _EnvironmentCore.__repr__   s    r   c                :   SUR                  5       ;   a  Ub  [        R                  " USS9nXR                  ;  a  US:w  a  [	        SU 35      eUS:X  a  S nSnUS:X  a'  UR                  5       nU[        R
                  ;   a  SnOzUS	:X  a'  UR                  5       nU[        R                  ;   a  SnOMUS
:X  a'  UR                  5       nU[        R                  ;   a  SnO US:X  a  [        U[        5      (       a  SnOSnU(       d  [	        U SU 35      e[        U[        5      (       a  [        R                  " U5      nUS:X  aE  [        U5      U R                  S   ;  a(  U R                  S   R                  [        U5      5        g g X R                  U'   g )NpathFreturnPathlibrF   rX   r5   
showFormatTwriteFormatautoDownloadrY   z, is not an acceptable value for preference: )rj   r   	cleanpathrO   r   VALID_SHOW_FORMATSVALID_WRITE_FORMATSVALID_AUTO_DOWNLOADrf   r(   ri   r   escaperQ   )r0   rs   rt   valids       r   __setitem___EnvironmentCore.__setitem__   s    SYY[ U%6$$U%@Eii''*_SE+BCCB;E,KKME111M!KKME222N"KKME222))%!455E&'EcUKM M eS!!OOE*E##5z+@!AA		/077E
C B #IIcNr   c                ,    [        U R                  5      $ r+   )r8   rO   ry   s    r   __str___EnvironmentCore.__str__$  s    DIIr   c                N   Uc  0 nUR                  5       nU GH  nUR                  S:X  a  [        5       nU Hq  nUR                  S:X  a-  UR                  R	                  5       nUR                  U5        M@  UR                  S:X  d  MR  UR                  R	                  5       Ul        Ms     XRS'   M  UR                  S:X  a  0 US'   U H  nUR                  S5      n	[        5       nXl        U Hq  nUR                  S:X  a-  UR                  R	                  5       nUR                  U5        M@  UR                  S:X  d  MR  UR                  R	                  5       Ul        Ms     XRS   U	'   M     GM[  UR                  S5      n	UR                  S5      n
X;  a  GM  XU	'   GM     g)zx
Takes in a ElementTree and possibly an already populated reference dictionary
(or creates a new one) and populates it.
NrY   rF   r/   localCorporaSettingsr.   rt   )	getroottagr(   r   r   rQ   r/   getr.   )r0   settingsTreerefsettingsslotlcs	slotChildfpCandidaterY   r.   rt   s              r   _fromSettings_EnvironmentCore._fromSettings(  sr   
 ;C'')Dxx00)+!%I }}(99&/nn&:&:&<

;/"/9,5NN,@,@,B) "& .1)*33.0*++/'.226:D-/C#H%8	$==,==*3..*>*>*@KJJ{3&]]o=090D0D0FC- &9 9<./5 ,0 xx')? !&IA r   c                &   SU R                   S'   SU R                   S'   SU R                   S'   SU R                   S'   SU R                   S'   SU R                   S	'   SU R                   S
'   SU R                   S'   SU R                   S'   SU R                   S'   SU R                   S'   SU R                   S'   SU R                   S'   SU R                   S'   SU R                   S'   SU R                   S'   SU R                   S'   SU R                   S'   [        5       U R                   S'   0 U R                   S'   SU R                   S'   Uc  [        R                  " 5       nOUnUS:X  a?  SS	[        R                  " S 5      4S[        R                  " S 5      44 H	  u  p4X@U'   M     gUS!:X  a  S" H	  u  p4X@U'   M     gUS#:X  aR  [        R
                  " 5       nUS   S$:  d  US   S%:X  a  US   S&:  a  S'nOS(nS)S*SU4SU4SU4S+S,4 H	  u  p4X@U'   M     gg)-z;
Load defaults.

All keys are derived from these defaults.
NdirectoryScratchrE   lilypondVersionpdflilypondFormatpslilypondBackendrJ   rH   rD   rL   rK   rC   rI   musicxmlr   r   zipython.musicxml.pngipythonShowFormataskr   r   r^   r   warningsrY   r   rG   win)rE   lilypondz-%PROGRAMFILES%\MuseScore 3\bin\MuseScore3.exenix))rE   z/usr/bin/lilypond)rJ   /usr/bin/mscore3)rI   r   )rD   /usr/bin/xdg-open)rK   r   darwin   
      z /System/Applications/Preview.appz/Applications/Preview.app)rE   z:/Applications/Lilypond.app/Contents/Resources/bin/lilypond)rJ   3/Applications/MuseScore 3.app/Contents/MacOS/mscore)rH   z/Applications/GarageBand.app)rI   r   )rO   r(   r   getPlatformr   macOSVersion)r0   rN   platformr.   rt   versionTuplepreviewLocations          r   rR   _EnvironmentCore._loadDefaultsR  sg    )-		$% %)		.! (,		#$&+		"#'+		#$ %)		.! !%		* %)		.! #'		,  $		) $(		-  /3		*+",		,#-		- )?		%&$)		.!		' !"		* ,?+@		'(,.		(),0		() ))+H$Hu,!!"RS *!!"RS  #T
    #T
  !!..0LA"$aB)><PQ?VXCX"D"=OH1/O,<H  #T
  "r   c                H   [        U[        R                  [        45      (       a}  [        R
                  R                  U5      n[        R                  " U[        R                  5      n[        R                  " U[        R                  5      nU=(       a    U=(       a    U$ g)z;
Return True if the path exists, is readable and writable.
F)
rf   rq   rr   ri   osr|   existsaccessR_OKW_OK)r0   r|   r   readablewritables        r   _checkAccessibility$_EnvironmentCore._checkAccessibility  sg     dW\\3/00WW^^D)Fyyrww/Hyyrww/H3h383r   c                   Uc  U R                   nSS0n[        R                  " SU5      n[        R                  " U5      n[	        UR                  5       5       GH!  u  pVUnUS:X  a  [        R                  " S5      n[	        U5       H=  n	[        R                  " S5      n
U	b  [        U	5      U
l        UR                  U
5        M?     UR                  bA  [        R                  " S5      n[        UR                  5      Ul        UR                  U5        UR                  U5        M  US:X  Ga  [        R                  " S5      n[	        UR                  5       5       H  u  p[        R                  " SUS9n[	        U5       H=  n	[        R                  " S5      n
U	b  [        U	5      U
l        UR                  U
5        M?     UR                  bA  [        R                  " S5      n[        UR                  5      Ul        UR                  U5        UR                  U5        M     UR                  U5        GM  S	U0nUb  [        U5      US
'   [        R                  " SU5      nUR                  U5        GM$     U$ )zs
Convert a ref dictionary to an xml.etree.ElementTree.Element object
with root "<settings>" and return that object
r\   rZ   r   rY   rF   r/   r   )r.   r.   rt   
preference)
rO   ETElementElementTreesorteditemsri   r   rQ   r/   )r0   r   settingsDictr   r   rs   rt   r   rY   filePathrF   mdbpr   r.   attribsr   s                   r   toSettingsXML_EnvironmentCore.toSettingsXML  s   
 ;))C"G,::j,7~~h/ -JCC++&(jj1F&G# &sH&(jj1B&CO+/28},'..?	 !,
 $$0::o6D #C$5$5 6DI'..t4 34..')zz2H'I$!'!6ID*,**5JQU*V'$*3K*,**5F*G#/36x=O0+22?C	 %0
 ((4!zz/:$'(9(9$:	+2248(//0CD "7  45 "3-$'*5zGG$zz,8%M .N r   c                   U R                  U R                  5      (       a  U R                  $ [        R                  " [        R
                  " 5       5      S-  U l        U R                  U R                  5      (       a  U R                  $  U R                  R                  5         U R                  $ ! [         Ga    [        R                  " 5       S;   aE  [        R                  " 5       n[        R                  " [        R
                  " 5       5      SU 3-  nO([        R                  " [        R                  " SS95      nU R                  U5      (       a  X l         U R                  $  UR                  5         X l         U R                  $ ! [         a=    [        R                  " [        R
                  " 5       5      U l          U R                  $ f = ff = f)a  
returns whatever tempfile.gettempdir() returns plus 'music21'.

Creates the subdirectory if it doesn't exist:

>>> import tempfile
>>> import pathlib
>>> tempFile = tempfile.gettempdir()
>>> #_DOCS_SHOW tempFile
'/var/folders/x5/rymq2tx16lqbpytwb1n_cc4c0000gn/T'

>>> import os
>>> e = environment.Environment()
>>> e.getDefaultRootTempDir() == pathlib.Path(tempFile) / 'music21'
True

If failed to create the subdirectory (OSError is raised), this function
will return (1), for Linux and Mac platforms, a subdirectory under the
system temp directory which is named with 'music21-userid-$UID' or (2),
for other platforms, a temporary directory which is created by
tempfile.mkdtemp(prefix="music21-"), which is named with 'music21-'
plus 8 hashed codes, and (3) if failing for both above, it will return
the directory from tempfile.gettempdir(). The location of this directory
depends on OS.

Note the temporary directory may be different in each python session.
music21r   r   music21-userid-zmusic21-)prefix)r   rT   rq   rr   tempfile
gettempdirmkdirOSErrorr   r   r   getuidmkdtemp)r0   uiddir_paths      r   getDefaultRootTempDir&_EnvironmentCore.getDefaultRootTempDir  s   : ##D$;$;<<*** #*,,x/B/B/D"E	"Q ##D$;$;<<***V''--/$ ***#  V%%'+<<))+C&||H,?,?,ABWZV[E\\H&||H,<,<J,OPH++H55.6+ ***V (2:/
 ***	 # V29,,x?R?R?T2U/***	VVs+   B1 1B-G,F8GGGGc                    U R                   $ )z
Find all keys that refer to paths

>>> e = environment.Environment()
>>> for i in e.getKeysToPaths():
...     #_DOCS_SHOW print(i)
...     pass #_DOCS_HIDE

braillePath
graphicsPath
lilypondPath
...
)rP   ry   s    r   rp   _EnvironmentCore.getKeysToPaths7  s        r   c                H    [        U R                  R                  5       5      $ )z
Find all keys (in any order)...

>>> e = environment.Environment()
>>> for i in e.getRefKeys():
...     #_DOCS_SHOW print(i)
...     pass #_DOCS_HIDE

lilypondBackend
pdfPath
lilypondVersion
graphicsPath
...
re   rO   keysry   s    r   
getRefKeys_EnvironmentCore.getRefKeysG  s      DIINN$%%r   c                    U R                   S   c  U R                  5       $ [        R                  " U R                   S   5      nUR	                  5       (       d  [        SR                  U5      5      eU$ )z
gets either the directory in key 'directoryScratch' or self.getDefaultRootTempDir

Returns an exception if directoryScratch is defined but does not exist.

Returns a pathlib.Path
r   zcuser-specified scratch directory ({!s}) does not exist; remove preference file or reset Environment)rO   r   rq   rr   r   r   format)r0   refDirs     r   getRootTempDir_EnvironmentCore.getRootTempDirY  sn     99'(0--// dii(:;<}}&>>Df?  r   c                    [         R                  " 5       nS[        R                  ;   a+  [        R
                  " [        R                  S   5      S-  nOSnUS:X  a  S[        R                  ;   a,  [        R
                  " [        R                  S   5      nUS-  $ U(       a  UnUS-  $ [        R
                  " [        R                  R                  S5      5      nUS-  $ US;   a  S	[        R                  ;   ag  [        R                  " [        R                  S	   [        R                  5      (       a,  [        R
                  " [        R                  S	   5      nUS-  $ [        R
                  " S
5      nUS-  $ g)z9
Return a pathlib.Path object to the '.music21rc' object
USERPROFILEzApplication DataNr   APPDATA~zmusic21-settings.xmlr   HOMEz/tmp/z
.music21rc)
r   r   r   environrq   rr   r|   
expanduserr   r   )r0   r   userProfilePath	directorys       r   getSettingsPath _EnvironmentCore.getSettingsPathn  s4    %%'BJJ&%ll2::m+DEHZZO"Ou BJJ&#LLI)>?	
 555	 !+	 555 $LL););C)@A	555**#		"**V2Dbgg(N(N#LLF);<	 |++ $LL1	|++ +r   c                   U R                  5       nU(       a  UR                  S5      (       d  SU-   n[        R                  " X1SS9 nUR                  nSSS5        U(       a  [
        R                  " W5      $ W$ ! , (       d  f       N-= f)a  
Gets a temporary file with a suffix that will work for a bit.

v5 -- added returnPathlib.
v6 -- returnPathlib defaults to True

OMIT_FROM_DOCS
>>> e = environment.Environment()
>>> tmp1 = e.getTempFile(returnPathlib=False)
>>> isinstance(tmp1, str)
True
>>> import pathlib
>>> tmp2 = e.getTempFile()
>>> isinstance(tmp2, pathlib.Path)
True
>>> import os
>>> os.remove(tmp1)
>>> os.remove(tmp2)
.F)dirsuffixdeleteN)r   
startswithr   NamedTemporaryFiler.   rq   rr   )r0   r   r~   rootDirntfntf_names         r   getTempFile_EnvironmentCore.getTempFile  ss    * %%'&++C006\F((WERVYxxH S <<))O SRs   A<<
B
c                P    [        U R                  R                  5       5      S/-   $ )NrF   r   ry   s    r   r   _EnvironmentCore.keys  s!    DIINN$%):(;;;r   c                    SnUS:X  a  SnU$ US;   a  SnU$ US:X  a  SnU$ US:X  a  S	nU$ US
;   a  SnU$ US:X  a  SnU$ US:X  a  SnU$ )a  
Finds the appropriate key to the file/app that can launch the given format:

>>> e = environment.Environment()
>>> e.formatToKey('lilypond')
'lilypondPath'
>>> e.formatToKey('png')
'graphicsPath'
>>> e.formatToKey('jpeg')
'graphicsPath'
>>> e.formatToKey('svg')
'vectorPath'
>>> e.formatToKey('pdf')
'pdfPath'
>>> e.formatToKey('musicxml')
'musicxmlPath'
>>> e.formatToKey('midi')
'midiPath'
>>> e.formatToKey('braille')
'braillePath'

returns None if there is no key for this format (whether the format exists or not)

>>> e.formatToKey('ipython') is None  # actual format
True
>>> e.formatToKey('adobePhotoshop') is None  # not a music21 format
True
Nr   rE   )pngjpegrD   svgrL   r   rK   )r   rJ   midirH   braillerC   r   r0   	m21FormatenvironmentKeys      r   formatToKey_EnvironmentCore.formatToKey  s    : 
"+N  /)+N  %)N  %&N  -'+N
 	 & 'N  )#*Nr   c                    U R                  U5      nUb,  X R                  ;  a  [        US-   5      eU R                  U   $ g)z5
Given a format, return the app that will launch it.
Nz is not set in UserSettings. )r
  rO   r   r  s      r   formatToApp_EnvironmentCore.formatToApp  sG     )))4%YY.*><[+[\\99^,,r   c           	     :   Uc  U R                  5       nUR                  5       (       d  g [        R                  " [	        U5      5      nU R                  X R                  5        g! [        R
                   a   n[        SU S[	        U5       35      UeSnAff = f)zi
Read the environment file from .music21rc and call _fromSettings
Called only once per music21 instance.
NzCannot parse file z: )	r   r   r   parseri   
ParseErrorr   r   rO   )r0   r   r   pes       r   rS   _EnvironmentCore.read  s    
 ++-H  	88CM2L 	<3 }} 	&$XJbR	:	s   A& &B:BBc                2    0 U l         U R                  5         g)z3
Changes everything to default but does not write.
N)rO   rR   ry   s    r   restoreDefaults _EnvironmentCore.restoreDefaults  s     	r   c                   Uc  U R                  5       nUb  UR                  R                  5       (       d  [        SU 35      eU R	                  5       n[        UR                  5       5        UR                  [        U5      SS9  g)zE
Write the .music21rc using `.getSettingsPath` and `.toSettingsXML`.
Nzbad file path for .music21rc: rZ   )r\   )	r   parentr   r   r   r   r   writeri   )r0   r   r   s      r   r  _EnvironmentCore.write  s}     ++-H 8??#9#9#;#;&)Gz'RSS))+%%'(
 	3x=7;r   )rP   rO   rT   r+   )r|   zstr | pathlib.Path | Nonereturnboolr5   T)r  str | pathlib.Path)r   r   r    r!   r=   r-   rv   r7   r   r   r   rR   r   r   r   rp   r   r   r   r   r   r
  r  rS   r  r  r"   r   r   r   r@   r@      sy    $'<.`4#l(&Tc#J
3n;+z! &$*,<B<,\	4(<r   r@   )instancerN   c                     [         S   $ )zL
returns the _environStorage['instance'], _EnvironmentCore singleton
object
r  )_environStorager   r   r   envSingletonr"  !  s    
 :&&r   c                  
   \ rS rSr% Sr/ SQrSS0rS\S'   S S	 jrS
 r	S r
S rS rS rS rS rS rS r\S!S j5       r\S"S#S jj5       rS"S$S jjrS rS rS r\R0                  4S jrS%S jrS rS%S jrS%S jrS rSrg)&Environmenti,  aF  
The environment.Environment object stores user preferences as a
dictionary-like object.  Additionally, the Environment object provides
convenience methods to music21 modules for getting temporary files,
launching files with external applications, and printing debug and warning
messages.

Generally, each module creates a single, module-level instance of
Environment, passing the module's name during creation. (This is an
efficient operation since the Environment module caches most information
from module to module)

For a more user-friendly interface for creating and editing settings, see
the :class:`~music21.environment.UserSettings` object.

>>> env = environment.Environment(forcePlatform='darwin')
>>> env['musicxmlPath'] = '/Applications/Finale Reader.app'
>>> env['musicxmlPath']
PosixPath('/Applications/Finale Reader.app')
)rS   r  r   modNameParentzt
            A string representation of the module that contains this
            Environment instance.
            zdict[str, str]	_DOC_ATTRNc                L    Xl         U[        S   :w  a  [        US9[        S'   gg)a  
Create an instance of this object, reading settings from disk.

When created from a module, the `modName` parameter stores a string
naming the module. This is used to identify the output of printDebug()
calls.

The `forcePlatform` argument can be used for testing what the
environment settings would look like on another OS platform (e.g., win,
nix, darwin).

>>> myEnv = environment.Environment()
>>> post = myEnv['writeFormat']
>>> #_DOCS_SHOW post
>>> print("'musicxml'") #_DOCS_HIDE
'musicxml'
rN   rM   r  N)r%  r!  r@   )r0   modNamerN   s      r   r-   Environment.__init__O  s-    $ % OO<<*:*WOJ' =r   c                4    [        5       R                  U5      $ r+   )r"  rv   r0   rs   s     r   rv   Environment.__getitem__j  s    ~))#..r   c                (    [        [        5       5      $ r+   )r8   r"  ry   s    r   r7   Environment.__repr__m  s    LN##r   c                6    [        5       R                  X5        g)a  
Dictionary-like setting. Changes are made only to local dictionary.

Must call write() to make permanent:

>>> from pathlib import Path
>>> a = environment.Environment()
>>> a['debug'] = 1
>>> a['graphicsPath'] = '/test&Encode'
>>> 'test&amp;Encode' in str(a['graphicsPath'])
True
>>> isinstance(a['graphicsPath'], Path)
True

>>> a['autoDownload'] = 'asdf'
Traceback (most recent call last):
music21.environment.EnvironmentException: asdf is not an acceptable
    value for preference: autoDownload

>>> a['showFormat'] = 'asdf'
Traceback (most recent call last):
music21.environment.EnvironmentException: asdf is not an acceptable
    value for preference: showFormat

>>> a['showFormat'] = 'musicxml'
>>> a['localCorpusPath'] = '/path/to/local'
N)r"  r   )r0   rs   rt   s      r   r   Environment.__setitem__p  s    8 	""3.r   c                (    [        [        5       5      $ r+   )ri   r"  ry   s    r   r   Environment.__str__  s    <>""r   c                x    [        5       R                  5       nU R                  [        S[	        U5      /5        U$ )aZ  
Use the Python tempfile.gettempdir() to get the system specified
temporary directory, and try to add a new 'music21' directory, and then
return this directory.

This method is only called if the no scratch directory preference has
been set.

If not able to create a 'music21' directory, the standard default is
returned.

Returns a pathlib.Path
zusing temporary directory:)r"  r   
printDebug_MODri   )r0   dstDirs     r   r   !Environment.getDefaultRootTempDir  s1     557;S[IJr   c                2    [        5       R                  5       $ )a"  
Get the keys that refer to file paths.

>>> a = environment.Environment()
>>> for x in sorted(a.getKeysToPaths()):
...     x
...
'braillePath'
'graphicsPath'
'lilypondPath'
'localCorpusPath'
'manualCoreCorpusPath'
'midiPath'
'musescoreDirectPNGPath'
'musicxmlPath'
'pdfPath'
'vectorPath'

)r"  rp   ry   s    r   rp   Environment.getKeysToPaths  s    ( ~,,..r   c                2    [        5       R                  5       $ )aI  
Get the raw keys stored in the internal reference dictionary.

These are different from the keys() method in that the
'localCorpusPath' entry is not included.

>>> a = environment.Environment()
>>> for x in sorted(a.getRefKeys()):
...     x
...
'autoDownload'
'braillePath'
'debug'
'directoryScratch'
'graphicsPath'
'ipythonShowFormat'
'lilypondBackend'
'lilypondFormat'
'lilypondPath'
'lilypondVersion'
'localCorporaSettings'
'localCorpusSettings'
'manualCoreCorpusPath'
'midiPath'
'musescoreDirectPNGPath'
'musicxmlPath'
'pdfPath'
'showFormat'
'vectorPath'
'warnings'
'writeFormat'
)r"  r   ry   s    r   r   Environment.getRefKeys  s    B ~((**r   c                2    [        5       R                  5       $ )z
Return a directory for writing temporary files. This does not create a
new directory for each use, but either uses the user-set preference or
gets the system-provided directory (with a music21 subdirectory, if
possible).
)r"  r   ry   s    r   r   Environment.getRootTempDir  s     ~,,..r   c                2    [        5       R                  5       $ z9
Return the path to the platform specific settings file.
)r"  r   ry   s    r   r   Environment.getSettingsPath  s     ~--//r   c                    g r+   r   r0   r   r~   s      r   r   Environment.getTempFile      r   c                    g r+   r   rB  s      r   r   rC    rD  r   c                d    [        5       R                  XS9nU R                  [        SU/5        U$ )z
Return a file path to a temporary file with the specified suffix (file
extension).

v5 -- added returnPathlib.
v6 -- returnPathlib defaults to True.
)r   r~   ztemporary file:)r"  r   r4  r5  )r0   r   r~   r   s       r   r   rC    s2      >--V-Y0(;<r   c                2    [        5       R                  5       $ )a  
Return valid keys to get and set values for the Environment instance.

>>> e = environment.Environment()
>>> for x in sorted(list(e.keys())):
...     x
...
'autoDownload'
'braillePath'
'debug'
'directoryScratch'
'graphicsPath'
'ipythonShowFormat'
'lilypondBackend'
'lilypondFormat'
'lilypondPath'
'lilypondVersion'
'localCorporaSettings'
'localCorpusPath'
'localCorpusSettings'
'manualCoreCorpusPath'
'midiPath'
'musescoreDirectPNGPath'
'musicxmlPath'
'pdfPath'
'showFormat'
'vectorPath'
'warnings'
'writeFormat'
)r"  r   ry   s    r   r   Environment.keys  s    > ~""$$r   c                4    [        5       R                  U5      $ r+   )r"  r  r0   r  s     r   r  Environment.formatToApp"      ~)))44r   c                4    [        5       R                  U5      $ r+   )r"  r
  rJ  s     r   r
  Environment.formatToKey%  rL  r   c                "   [        5       S   U:  a~  [        U[        5      (       a  U/nUS   U R                  :w  a   U R                  b  U R                  S-   /U-   n[        R
                  " U6 n[        R                  R                  U5        gg)z
Format one or more data elements into string, and print it to stderr.
The first arg can be a list of strings or a string; lists are
concatenated with common.formatStr().
r^   r   N:)	r"  rf   ri   r%  r   	formatStrsysstderrr  )r0   msgstatusLevels      r   r4  Environment.printDebug(  s     >'"k1#s##e1v+++0B0B0N))C/036""C(CJJS! 2r   c                0    [        5       R                  US9$ )z
Load an XML preference file if and only if the file is available
and has been written in the past. This means that no preference file
will ever be written unless manually done so. If no preference file
exists, the method returns None.
r   )r"  rS   r0   r   s     r   rS   Environment.read7  s     ~""H"55r   c                4    [        5       R                  5         g)aD  
Restore only defaults for all parameters. Useful for testing.

>>> a = environment.Environment()
>>> a['debug'] = 1
>>> a.restoreDefaults()
>>> a['debug']
0

And we can ``read()`` the environment settings back from our
configuration file to restore our normal working environment.

>>> a = environment.Environment().read()
N)r"  r  ry   s    r   r  Environment.restoreDefaults@  s     	&&(r   c                   [        U[        5      (       a  U/nOk[        U[        5      (       a  [        U5      /nOI[        R
                  " U5      (       a  [        U5      /nO![        U[        5      (       a  [        U5      /nUc4  US   U R                  :w  a   U R                  b  U R                  S-   /U-   nOU/U-   n[        R                  " U6 n[        R                  R                  U5        g)zx
To print a warning to the user, send a list of strings to this method.
Similar to printDebug but even if debug is off.
Nr   z
: WARNING:)rf   ri   dictr8   r   isNum	Exceptionr%  rQ  rR  rS  r  )r0   rT  headers      r   warnEnvironment.warnQ  s    
 c3%CT""9+C\\#s8*CY''s8*C>1v+++0B0B0N))L89C?(S.C$

r   c                0    [        5       R                  US9$ )z
Write an XML preference file. This must be manually called to store
any changes made to the object and access preferences later.
If `filePath` is None, the default storage location will be used.
rX  )r"  r  rY  s     r   r  Environment.writeg  s     ~##X#66r   c                    U S   n[         R                  " 5       (       a  U S   nU(       d  g[        U5      R                  5       nSU;   a  gSU;   a  gSU;   a  g	g
)a  
Returns an xmlReaderType depending on the 'musicxmlPath'

>>> a = environment.Environment()
>>> original = a['musicxmlPath']  #_DOCS_HIDE
>>> a['musicxmlPath'] = '/Applications/Musescore.app'
>>> a.xmlReaderType()
'Musescore'
>>> a['musicxmlPath'] = '/Applications/Sibelius 7.app'
>>> a.xmlReaderType()
'Sibelius'
>>> a['musicxmlPath'] = r'C:\Program Files\Finale\Finale 2014.exe'
>>> a.xmlReaderType()
'Finale'

Nostalgia is unknown...

>>> a['musicxmlPath'] = r'C:\Program Files\Deluxe Music Construction Set.exe'
>>> a.xmlReaderType()
'unknown'

>>> a['musicxmlPath'] = None
>>> a.xmlReaderType() is None
True

>>> a['musicxmlPath'] = original  #_DOCS_HIDE
rJ   rI   NsibeliusSibeliusfinaleFinale	musescore	Musescoreunknown)r   runningInNotebookri   rj   )r0   xps     r   xmlReaderTypeEnvironment.xmlReaderTypeo  s`    8 .!##%%./BW]]_^Br   )r%  )NN)r   ri   r~   zt.Literal[False]r  ri   r  )r   ri   r~   zt.Literal[True]r  zpathlib.Path)r   ri   r  r  r+   ) r   r   r    r!   r=   
_DOC_ORDERr&  __annotations__r-   rv   r7   r   r   r   rp   r   r   r   r   r   r   r  r
  r   rk   r4  rS   r  rb  r  rp  r"   r   r   r   r$  r$  ,  s    , 6J 	 !I~ X6/$/<#
$/,!+F/0    
%B55 +1*;*; "6)",7*r   r$  c                  `    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rSrg)UserSettingsi  az  
The UserSettings object provides a simple interface for configuring the
user preferences in the :class:`~music21.environment.Environment` object.

It automatically writes all changes to disk.

First, create an instance of UserSettings:

>>> us = environment.UserSettings()

Second, view the available settings keys.

>>> for key in sorted(us.keys()):
...     key
'autoDownload'
'braillePath'
'debug'
'directoryScratch'
'graphicsPath'
'ipythonShowFormat'
'lilypondBackend'
'lilypondFormat'
'lilypondPath'
'lilypondVersion'
'localCorporaSettings'
'localCorpusPath'
'localCorpusSettings'
'manualCoreCorpusPath'
'midiPath'
'musescoreDirectPNGPath'
'musicxmlPath'
'pdfPath'
'showFormat'
'vectorPath'
'warnings'
'writeFormat'

Third, after finding the desired setting, supply the new value as a Python
dictionary key value pair. Setting this value updates the user's settings
file. For example, to set the file path to the Application that will be
used to open MusicXML files, use the 'musicxmlPath' key.

>>> #_DOCS_SHOW us['musicxmlPath'] = '/Applications/Finale Reader.app'
>>> #_DOCS_SHOW us['musicxmlPath']
'/Applications/Finale Reader.app'

Note that the 'localCorpusPath' setting operates in a slightly different
manner than other settings. Each time the 'localCorpusPath' setting is set,
an additional local corpus file path is added to the list of local corpus
paths (unless that path is already defined in the list of local corpus
paths). To view all local corpus paths, access the 'localCorpusSettings'
settings. This setting can also be used to set a complete list of file
paths.

>>> #_DOCS_SHOW us['localCorpusPath'] = '~/Documents'
>>> #_DOCS_SHOW list(us['localCorpusSettings'])
['~/Documents']

Alternatively, the environment.py module provides convenience functions for
setting these settings: :func:`~music21.environment.keys`,
:func:`~music21.environment.get`, and :func:`~music21.environment.set`.
c                "    [        5       U l        g r+   )r$  _environmentry   s    r   r-   UserSettings.__init__  s    'Mr   c                8    U R                   R                  U5      $ r+   )rw  rv   r+  s     r   rv   UserSettings.__getitem__  s      ,,S11r   c                ,    [        U R                  5      $ z|
Return a string representation.

>>> us = environment.UserSettings()
>>> post = repr(us)  # location specific, cannot test
)r8   rw  ry   s    r   r7   UserSettings.__repr__  s     D%%&&r   c                ,    [        U R                  5      $ r|  )ri   rw  ry   s    r   r   UserSettings.__str__  s     4$$%%r   c                   XR                   R                  5       ;   aj  Ubf  [        U5      R                  S5      (       dG  [        R
                  " USS9n[        R                  R                  U5      (       d  [        SU 35      eOUS:X  a'  [        R                  " U5      (       d  [        S5      eOUS:X  a  [        U[        5      (       d  [        S	5      eU(       a_  UR                  5        HK  u  p4[        U[        5      (       d  [        S
5      e[        R                  " U5      (       a  MB  [        S5      e   U R                   R                  X5        U R                   R                  5         g)a  
Dictionary-like setting. Changes are made and written to the user
configuration file.

>>> us = environment.UserSettings()
>>> us['musicxmlPath'] = 'asdf/asdf/asdf'
Traceback (most recent call last):
music21.environment.UserSettingsException: attempting to set a value
    to a path that does not exist: ...asdf

>>> us['localCorpusPath'] = '/path/to/local'
Traceback (most recent call last):
music21.environment.UserSettingsException: attempting to set a value
    to a path that does not exist: ...local
Nz/skipFr}   z9attempting to set a value to a path that does not exist: rY   z/localCorpusSettings must be provided as a list.r   z0localCorporaSettings must be provided as a dict.z2Each key in localCorporaSettings must be a string.z8Each entry in localCorporaSettings must point to a list.)rw  rp   ri   r   r   r   r   r|   r   r%   
isListLikerf   r^  valuesr   r  )r0   rs   rt   innerKey
innerValues        r   r   UserSettings.__setitem__  sQ   * ##2244 U)>)>w)G)G((eDww~~e,,/STYSZ[] ] ))$$U+++EG G , **eT**+FH H,1LLN(H%h443PR R!,,Z883VX X -; 	%%c1!r   c                    U R                   R                  5       R                  5       (       d  U R                   R                  5         g[	        S5      e)z`
If an environment configuration file does not exist, create one based on
the default settings.
zNAn environment configuration file already exists; simply set values to modify.N)rw  r   r   r  r%   ry   s    r   createUserSettings.create2  sF    
   00299;;##%'/0 0r   c                    U R                   R                  5       R                  5       (       a)  U R                   R                  5       R                  5         g[	        S5      e)z1
Permanently remove the user configuration file.
z1An environment configuration file does not exist.N)rw  r   r   unlinkr%   ry   s    r   r   UserSettings.delete>  sO     ,,.5577--/668'CE Er   c                6    U R                   R                  5       $ r?  )rw  r   ry   s    r   r   UserSettings.getSettingsPathH  s       0022r   c              #  \   #    U R                   R                  5       S/-    Sh  vN   g N7f)z
Return the keys found in the user's
:class:`~music21.environment.Environment` object.

Changed in v9.3 -- yields a generator, like Python 3 dict -- rather than
    returning a list
rF   N)rw  r   ry   s    r   r   UserSettings.keysN  s(      %%0026G5HHIIs   ",*,c              #  J   #    U R                  5        H  nXU   4v   M     g7f)zH
dict-like interface to allow iterating over items of the UserSettings.
N)r   )r0   ks     r   r   UserSettings.itemsX  s#      A1g, s   !#c              #  F   #    U R                  5        H	  u  pUv   M     g7f)zI
dict-like interface to allow iterating over values of the UserSettings.
N)r   )r0   _vs      r   r  UserSettings.values_  s      JJLDAG !s   !c                l    U R                   R                  5         U R                   R                  5         g)z%
Restore platform specific defaults.
N)rw  r  r  ry   s    r   r  UserSettings.restoreDefaultsf  s(    
 	))+!r   )rw  N)r   r   r    r!   r=   r-   rv   r7   r   r   r  r   r   r   r   r  r  r"   r   r   r   ru  ru    sG    =B*2'&0"j
0E3J"r   ru  c                 6    [        5       n U R                  5       $ )z%
Return all valid UserSettings keys.
)ru  r   )uss    r   r   r   s  s     
B779r   c                b    [        5       n UR                  5         XU '   g! [         a     Nf = f)ac  
Directly set a single UserSettings key, by providing a key and the
appropriate value. This will create a user settings file if necessary.

>>> environment.set('wer', 'asdf')
Traceback (most recent call last):
music21.environment.EnvironmentException: no preference: wer

>>> #_DOCS_SHOW environment.set('musicxmlPath', '/Applications/Finale Reader.app')
N)ru  r  r%   )rs   rt   r  s      r   setr  }  s6     
B
		 sG ! s   ! 
..c                    [        5       nX   $ )z
Return the current setting of a UserSettings key.

This will create a user settings file if necessary:

>>> #_DOCS_SHOW environment.get('musicxmlPath')
'/Applications/Finale Reader.app'
)ru  )rs   r  s     r   r   r     s     
B7Nr   c                  z   \ rS rSrSSKrS r\R                  " \R                  " 5       S:H  S5      S 5       r
\R                  " \R                  " 5       S:H  S5      S 5       r\R                  " \R                  " 5       S:H  S5      S	 5       r\R                  " \R                  " 5       S
;   S5      S 5       rSrg)Testi  r   Nc                    [        UR                  5       5        [        R                  " 5       nUR	                  USSS9  UR                  5       R                  S5      nU$ )NrZ   T)r\   xml_declaration)r   r   ioBytesIOr  getvaluerh   )r0   r   biomatchs       r   stringFromTreeTest.stringFromTree  sN    %%'(jjl3$G%%g.r   r   ztest assumes Unix-style pathsc                   [        SS9n[        5       R                  5       nU R                  U5      nS U l        SU;   a  SnOSnSU-   S-   n[
        R                  " UR                  SS	5      U5      nU R                  [
        R                  " XS5      =(       d    U5        [        / S
Q5      US'   [        / SQ5      nSUl
        SUl        XqS   S'   [        5       R                  5       nU R                  U5      nSU;   a  SnOSnSU-   S-   n[
        R                  " UR                  SS	5      U5      nU R                  [
        R                  " XS5      =(       d    U5        g )Nr   rM   r\   encoding='utf-8'r5   <?xml version='1.0' a  ?>
<settings encoding="utf-8">
  <preference name="autoDownload" value="ask" />
  <preference name="braillePath" />
  <preference name="debug" value="0" />
  <preference name="directoryScratch" />
  <preference name="graphicsPath" value="/System/Applications/Preview.app" />
  <preference name="ipythonShowFormat" value="ipython.musicxml.png" />
  <preference name="lilypondBackend" value="ps" />
  <preference name="lilypondFormat" value="pdf" />
  <preference name="lilypondPath"
      value="/Applications/Lilypond.app/Contents/Resources/bin/lilypond" />
  <preference name="lilypondVersion" />
  <localCorporaSettings />
  <localCorpusSettings />
  <preference name="manualCoreCorpusPath" />
  <preference name="midiPath" value="/Applications/GarageBand.app" />
  <preference name="musescoreDirectPNGPath"
      value="/Applications/MuseScore 3.app/Contents/MacOS/mscore" />
  <preference name="musicxmlPath" value="/Applications/MuseScore 3.app/Contents/MacOS/mscore" />
  <preference name="pdfPath" value="/System/Applications/Preview.app" />
  <preference name="showFormat" value="musicxml" />
  <preference name="vectorPath" value="/System/Applications/Preview.app" />
  <preference name="warnings" value="1" />
  <preference name="writeFormat" value="musicxml" />
</settings>
/System/Applications/Preview/Applications/Preview)abcrY   )barbazfuzzyz/tmp/local.jsonfoor   a  ?>
<settings encoding="utf-8">
  <preference name="autoDownload" value="ask" />
  <preference name="braillePath" />
  <preference name="debug" value="0" />
  <preference name="directoryScratch" />
  <preference name="graphicsPath" value="/System/Applications/Preview.app" />
  <preference name="ipythonShowFormat" value="ipython.musicxml.png" />
  <preference name="lilypondBackend" value="ps" />
  <preference name="lilypondFormat" value="pdf" />
  <preference name="lilypondPath"
      value="/Applications/Lilypond.app/Contents/Resources/bin/lilypond" />
  <preference name="lilypondVersion" />
  <localCorporaSettings>
    <localCorpusSettings name="foo">
      <localCorpusPath>bar</localCorpusPath>
      <localCorpusPath>baz</localCorpusPath>
      <localCorpusPath>fuzzy</localCorpusPath>
      <cacheFilePath>/tmp/local.json</cacheFilePath>
    </localCorpusSettings>
  </localCorporaSettings>
  <localCorpusSettings>
    <localCorpusPath>a</localCorpusPath>
    <localCorpusPath>b</localCorpusPath>
    <localCorpusPath>c</localCorpusPath>
  </localCorpusSettings>
  <preference name="manualCoreCorpusPath" />
  <preference name="midiPath" value="/Applications/GarageBand.app" />
  <preference name="musescoreDirectPNGPath"
      value="/Applications/MuseScore 3.app/Contents/MacOS/mscore" />
  <preference name="musicxmlPath" value="/Applications/MuseScore 3.app/Contents/MacOS/mscore" />
  <preference name="pdfPath" value="/System/Applications/Preview.app" />
  <preference name="showFormat" value="musicxml" />
  <preference name="vectorPath" value="/System/Applications/Preview.app" />
  <preference name="warnings" value="1" />
  <preference name="writeFormat" value="musicxml" />
</settings>
)r$  r"  r   r  maxDiffr   whitespaceEqualr[   
assertTruer(   r/   r.   )r0   envr   r  enccanonictrue_but_for_preview_locationlcFoos           r   testToSettingsTest.testToSettings  sh   1#~335##L1$CC,s2 6 6 )/(>(>w*,C@EFK)M%..w>_B_` &9%I!"#$;</
-2"#E*#~335##L1$CC,s2 %6 %L )/(>(>w*,C@EFK)M%..w>_B_`r   c                   [        SS9n[        / SQ5      SS.n[        5       R                  U5      n[        5       R	                  U[        5       R
                  5        U R                  [        5       R                  5       5      nSU;   a  SnOSnS	U-   S
-   n[        R                  " UR                  SS5      U5      nU R                  [        R                  " Xd5      =(       d    U5        g )Nr   rM   )xyzw)rY   rH   r\   r  r5   r  a|  ?>
<settings encoding="utf-8">
  <preference name="autoDownload" value="ask" />
  <preference name="braillePath" />
  <preference name="debug" value="0" />
  <preference name="directoryScratch" />
  <preference name="graphicsPath" value="/System/Applications/Preview.app" />
  <preference name="ipythonShowFormat" value="ipython.musicxml.png" />
  <preference name="lilypondBackend" value="ps" />
  <preference name="lilypondFormat" value="pdf" />
  <preference name="lilypondPath"
      value="/Applications/Lilypond.app/Contents/Resources/bin/lilypond" />
  <preference name="lilypondVersion" />
  <localCorporaSettings />
  <localCorpusSettings>
    <localCorpusPath>x</localCorpusPath>
    <localCorpusPath>y</localCorpusPath>
    <localCorpusPath>z</localCorpusPath>
  </localCorpusSettings>
  <preference name="manualCoreCorpusPath" />
  <preference name="midiPath" value="w" />
  <preference name="musescoreDirectPNGPath"
      value="/Applications/MuseScore 3.app/Contents/MacOS/mscore" />
  <preference name="musicxmlPath" value="/Applications/MuseScore 3.app/Contents/MacOS/mscore" />
  <preference name="pdfPath" value="/System/Applications/Preview.app" />
  <preference name="showFormat" value="musicxml" />
  <preference name="vectorPath" value="/System/Applications/Preview.app" />
  <preference name="warnings" value="1" />
  <preference name="writeFormat" value="musicxml" />
</settings>
r  r  )r$  r(   r"  r   r   rO   r  r   r  r[   r  )r0   
unused_envr   r   r  r  r  r  s           r   testFromSettingsTest.testFromSettings	  s     !x8
 $7#G
  >//4 	$$X%1^%8%8	: ##LN$@$@$BC$CC,s2 6 > )/(>(>w*,C@EFK)M%..w>_B_`r   c                    [        SS9nU R                  US   5        SUS'   U R                  [        US   5      S/5        SUS'   U R                  [        US   5      SS/5        g )Nr   rM   rF   z/arY   z/b)r$  assertIsNoneassertEqualre   )r0   r  s     r   testEnvironmentATest.testEnvironmentAA  sv    1 	#/01 "&c"789D6B!%c"789D$<Hr   r   z.os.getuid can be called only on Unix platformsc                   SS K n[        5       nUS   nS nS nS n S US'   UR                  5       nUR                  5       UR                     n[        R
                  " XAR                  5        UR                  5       nU R                  S[        R                  " 5        3[        U5      5        Ub  Ub  [        R
                  " XE5        X2S'   Ubm  UR                  [        R                  " 5       5      n[        [        R                  " U5      5      S:H  nU(       d  U(       a  [        R                  " U5        g g g g ! Ub  Ub  [        R
                  " XE5        X2S'   Ubm  UR                  [        R                  " 5       5      n[        [        R                  " U5      5      S:H  nU(       d  U(       a  [        R                  " U5        f f f f = f)Nr   r   r   )statr$  r   ST_MODEr   chmodS_IREADassertInr   ri   samefiler   r   r   listdirrmdir)	r0   r  eoldScratchDir
oldTempDiroldPermission
newTempDirtmpemptys	            r   testGetDefaultRootTempDirTest.testGetDefaultRootTempDirO  s   
 	M,-

!	)$(A !002J&OO-dll;MHHZ.002JMMOBIIK=93z?K %-*C3(5$% % !))(*=*=*?@BJJz23q8uHHZ(  %s! & %-*C3(5$% % !))(*=*=*?@BJJz23q8uHHZ(  %s! &s   BD? ?BG)r  )r   r   r    r!   r  r  unittestskipIfr   r   r  r  r  
skipUnlessr  r"   r   r   r   r  r    s     __V'')U24ST]a U]a~ __V'')U24ST5a U5an __V'')U24STI UI  118))	))r   r  __main__)r      ))r=   
__future__r   r  r   rq   rR  r   r  typingtr   xml.etree.ElementTreeetreer   r   xml.saxr   r   r   r   r5  r   Music21Exceptionr   r%   re   r(   r@   r!  r"  r$  ru  r   r  r   TestCaser  rr  r   mainTestr   r   r   <module>r     s    # 	 	  
     " "     ,	<88 		0 	6F$ 6FxJ
< J
<h  01DI'm mfM" M"h&
])8 ])D K)<=
zT r   