
    rh)                        S r SSKJr  / SQrSSKJr  SSKrSSKr\R                  (       a  SSK
Jr  / SQr/ SQr/ S	QrSS
 jrS r\SS j5       rS rS rS r\S:X  a  SSKr\R.                  " 5         gg)zQ
Utilities for working with file formats.

almost everything here is deprecated.
    )annotations)	findSubConverterForFormat
findFormatfindInputExtensionfindFormatFilefindFormatExtFilefindFormatExtURLVALID_SHOW_FORMATSVALID_WRITE_FORMATSVALID_AUTO_DOWNLOAD)cacheN)SubConverter)musicxmllilypondtexttextlinemidipngpdfsvglily.pdflily.pnglily.svgbraillevexflowvexflow.html
vexflow.jsipythonipython.pngipython.midimusicxml.pngmusicxml.pdf)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   rntxt)askdenyallowc                    U R                  5       R                  5       n SSKJn  UR	                  5       R                  5       nU H  nUR                  nX;   d  M  Us  $    g)ab  
return a converter.subConverter.SubConverter subclass
for a given format -- this is a music21 format name,
not a file extension. Or returns None

>>> common.findSubConverterForFormat('musicxml')
<class 'music21.converter.subConverters.ConverterMusicXML'>

>>> common.findSubConverterForFormat('text')
<class 'music21.converter.subConverters.ConverterText'>

>>> common.findSubConverterForFormat('romantext')
<class 'music21.converter.subConverters.ConverterRomanText'>

Some subConverters have format aliases

>>> common.findSubConverterForFormat('t')
<class 'music21.converter.subConverters.ConverterText'>

r   	converterN)lowerstripmusic21r)   	ConvertersubConvertersListregisterFormats)fmtr)   sclscformatss        P/home/james-whalen/.local/lib/python3.13/site-packages/music21/common/formats.pyr   r   <   sV    * ))+


C!




1
1
3C$$>I      c                "   SSK Jn  UR                  5       nUR                  U 5      nUc  gUR	                  5       nXC   nUR
                  (       a  SUR
                  S   -   nX64$ UR                  (       a  SUR                  S   -   nX64$ SnX64$ )a  
Given a format defined either by a format name, abbreviation, or
an extension, return the regularized format name as well as
the output extensions.

DEPRECATED May 2014 -- moving to converter


All but the first element of the tuple are deprecated for use, since
the extension can vary by subConverter (e.g., lily.png)

>>> common.findFormat('.mxl')
('musicxml', '.musicxml')
>>> common.findFormat('musicxml')
('musicxml', '.musicxml')
>>> common.findFormat('lily')
('lilypond', '.ly')
>>> common.findFormat('lily.png')
('lilypond', '.ly')
>>> common.findFormat('humdrum')
('humdrum', '.krn')
>>> common.findFormat('txt')
('text', '.txt')
>>> common.findFormat('textline')
('textline', '.txt')
>>> common.findFormat('midi')
('midi', '.mid')
>>> common.findFormat('abc')
('abc', '.abc')
>>> common.findFormat('scl')
('scala', '.scl')
>>> common.findFormat('braille')
('braille', '.txt')
>>> common.findFormat('vexflow')
('vexflow', '.html')
>>> common.findFormat('capx')
('capella', '.capx')


Works the same whether you have a leading dot or not:


>>> common.findFormat('md')
('musedata', '.md')
>>> common.findFormat('.md')
('musedata', '.md')


If you give something we can't deal with, returns a Tuple of None, None:

>>> common.findFormat('wpd')
(None, None)


These don't work but should eventually:

# >>> common.findFormat('png')
# ('musicxml.png', '.png')

# >>> common.findFormat('ipython')
# ('ipython', '.png')
# >>> common.findFormat('ipython.png')
# ('ipython', '.png')

# >>> common.findFormat('musicxml.png')
# ('musicxml.png', '.png')
r   r(   NNN.)r,   r)   r-   regularizeFormatgetSubConverterFormatsregisterOutputExtensionsregisterInputExtensions)r0   r)   c
fileFormatscfr2   firstOutputs          r4   r   r   \   s    H "A##C(J

"
"
$C	B	""B77:: "" 
	#	#B66q99 "" ""r5   c                `   SSK Jn  U R                  5       R                  5       n U R	                  S5      (       a  U SS n [        U 5      nUc  / nUR                  5       R                  5        Hg  nXR                  ;  a  M  UR                   H/  nUR	                  S5      (       d  SU-   nUR                  U5        M1     U(       d  M\  [        U5      s  $    [        U5      $ / nUR                   H/  nUR	                  S5      (       d  SU-   nUR                  U5        M1     [        U5      $ )a  
Will be fully deprecated when there's an exact equivalent in converter.

Given an input format or music21 format, find and return all possible
input extensions.

>>> a = common.findInputExtension('musicxml')
>>> a
('.xml', '.mxl', '.musicxml')
>>> a = common.findInputExtension('humdrum')
>>> a
('.krn',)
>>> common.findInputExtension('musedata')
('.md', '.musedata', '.zip')

Leading dots don't matter:

>>> common.findInputExtension('.mxl')
('.xml', '.mxl', '.musicxml')

Blah is not a format

>>> common.findInputExtension('blah')
()
r   r(   r8      N)r,   r)   r*   r+   
startswithr   r-   r.   r<   appendtuple)r0   r)   r2   postexts        r4   r   r      s   6 "
))+


C
~~c!"g	"3	'B	z%%'99;B44411~~c**)CC  2 tT{" < T{ --C>>#&&CiKK . T{r5   c                    [        U [        R                  5      (       d  [        R                  " U 5      n [        U R                  5      u  pU$ )a  
Given a file path (relative or absolute) return the format

DEPRECATED May 2014 -- moving to converter


>>> common.findFormatFile('test.xml')
'musicxml'
>>> common.findFormatFile('long/file/path/test-2009.03.02.xml')
'musicxml'
>>> common.findFormatFile('long/file/path.intermediate.png/test-2009.03.xml')
'musicxml'

On a windows networked filesystem
>>> common.findFormatFile(r'\\long\file\path\test.krn')
'humdrum'

isinstancepathlibPathr   suffix)fpr0   
unused_exts      r4   r   r      s8    $ b',,''\\" +OCJr5   c                    [        U [        R                  5      (       d  [        R                  " U 5      n [        U R                  5      u  pUc  gXR                  4$ )a  
Given a file path (relative or absolute)
find format and extension used (not the output extension)

DEPRECATED May 2014 -- moving to converter

>>> common.findFormatExtFile('test.mxl')
('musicxml', '.mxl')
>>> common.findFormatExtFile('long/file/path/test-2009.03.02.xml')
('musicxml', '.xml')
>>> common.findFormatExtFile('long/file/path.intermediate.png/test-2009.03.xml')
('musicxml', '.xml')

>>> common.findFormatExtFile('test')
(None, None)

Windows drive
>>> common.findFormatExtFile('d:/long/file/path/test.xml')
('musicxml', '.xml')

On a windows networked filesystem
>>> common.findFormatExtFile(r'\\long\file\path\test.krn')
('humdrum', '.krn')
r7   rI   )rN   r>   unused_extOuts      r4   r   r     sJ    2 b',,''\\" *299 5JII&&r5   c                2   SSK Jn  SnSU ;   a  SnOsSU ;   a  SnOjSU ;   d  S	U ;   a  S
nO[UR                  5       R                  5        H9  nUR                  nU H$  nU R                  SU-   5      (       d  M  SU-   n  M7     M;     Ub  [        U5      u  pgXb4$ g)a  
Given a URL, attempt to find the extension.
This may scrub arguments in a URL, or simply look at the last characters.

DEPRECATED May 2014 -- moving to converter


>>> urlA = 'http://somesite.com/?l=cc/schubert/piano/d0576&file=d0576-06.krn&f=xml'
>>> urlB = 'http://somesite.com/cgi-bin/ksdata?l=cc/schubert/d0576&file=d0576-06.krn&f=kern'
>>> urlC = 'http://somesite.com/cgi-bin/ksdata?l=cc/bach/cello&file=bwv1007-01.krn&f=xml'
>>> urlF = 'https://junk'
>>> urlM = 'http://somesite.com/files/mid001.mid'

>>> common.findFormatExtURL(urlA)
('musicxml', '.xml')
>>> common.findFormatExtURL(urlB)
('humdrum', '.krn')
>>> common.findFormatExtURL(urlC)
('musicxml', '.xml')
>>> common.findFormatExtURL(urlF)
(None, None)
>>> common.findFormatExtURL(urlM)
('midi', '.mid')
r   r(   Nz=xmlz.xmlz=kernz.krnzformat=stage2zformat=stage1z.mdr8   r7   )r,   r)   r-   r.   r<   endswithr   )urlr)   rG   r2   
inputTypes	extSampler>   unused_junks           r4   r	   r	   ,  s    2 "
C}	C	C	?c#9%%'99;B33J'	<<i00	/C ( < ",S/
r5   __main__)r0   strreturnztype[SubConverter] | None)r0   rY   rZ   ztuple[str, ...])__doc__
__future__r   __all__	functoolsr   rK   typingtTYPE_CHECKINGmusic21.converter.subConvertersr   r
   r   r   r   r   r   r   r   r	   __name__r,   mainTest r5   r4   <module>rf      s   
 #
    ??<
6    / 
@S#n 4 4r4 'J0f z r5   