
    h!                     .   S SK Jr  S SKrS SKJr  S SKJrJr  S SKJ	r	  S SK
Jr   " S S\5      r " S	 S
\5      r " S S\5      rSr\R$                  " \5      rSr\R$                  " \5      rSr\R$                  " \5      rSr\R$                  " \5      rg)    )BytesION)sstruct)	bytesjointostr)OrderedDict)MutableMappingc                       \ rS rSrSrg)ResourceError	    N)__name__
__module____qualname____firstlineno____static_attributes__r       G/var/www/html/env/lib/python3.13/site-packages/fontTools/misc/macRes.pyr
   r
   	   s    r   r
   c                       \ rS rSrSrS r\S 5       r\S 5       rS r	SS jr
S	 rS
 rS rS rS rS rS rS rS r\S 5       rS rS rS rS rS rS rSrg)ResourceReader   a  Reader for Mac OS resource forks.

Parses a resource fork and returns resources according to their type.
If run on OS X, this will open the resource fork in the filesystem.
Otherwise, it will open the file itself and attempt to read it as
though it were a resource fork.

The returned object can be indexed by type and iterated over,
returning in each case a list of py:class:`Resource` objects
representing all the resources of a certain type.

c                    [        5       U l        [        US5      (       a  Xl        O( U R	                  U5      U l        U R                  5         gU R                  5         g! [        [        4 a    U R                  U5      U l         N9f = f)zOpen a file

Args:
        fileOrPath: Either an object supporting a ``read`` method, an
                ``os.PathLike`` object, or a string.
readN)	r   
_resourceshasattrfileopenResourceFork	_readFiler
   IOErroropenDataFork)self
fileOrPaths     r   __init__ResourceReader.__init__   sw     &-:v&&"I: 11*=	  	 "7+ : --j9	:s   &A! !&B
	B
c                     [        U S5      (       a  U R                  5       n [        U S-   S5       nUR                  5       nS S S 5        [	        W5      nXl        U$ ! , (       d  f       N!= f)N
__fspath__z/..namedfork/rsrcrb)r   r%   openr   r   name)pathresforkdatainfiles       r   r   ResourceReader.openResourceFork0   sY    4&&??$D$,,d3w<<>D 4	 43s   A
A+c                     [        U S5       nUR                  5       nS S S 5        [        W5      nXl        U$ ! , (       d  f       N!= f)Nr&   )r'   r   r   r(   )r)   dataforkr+   r,   s       r   r   ResourceReader.openDataFork:   s:    $==?D 	 s	   9
Ac                 D    U R                  5         U R                  5         g N)_readHeaderAndMap_readTypeListr    s    r   r   ResourceReader._readFileB   s     r   Nc                 f   UbE   U R                   R                  U5        U R                   R	                  5       U:w  a  [        S5      e U R                   R                  U5      n[        U5      U:w  a  [        S5      eU$ ! [         a    [        S5      ef = f! [         a    [        S5      ef = f)Nz-Failed to seek offset ('offset' is too large)z#Failed to seek offset (reached EOF)z.Cannot read resource ('numBytes' is too large)z&Cannot read resource (not enough data))r   seekOverflowErrorr
   tellr   len)r    numBytesoffsetr+   s       r   _readResourceReader._readF   s    U		v& yy~~6)#$IJJ	R99>>(+D t9  HII ! U#$STTU  	R PQQ	Rs   B 
B BB0c                    U R                   R                  S5        U R                  [        5      n[        R
                  " [        X5        U R                  S-   nU R                  [        U5      n[        R
                  " [        X05        U R                  U R                  -   U l        U R                  U R                  -   U l        g )Nr      )r   r8   r>   ResourceForkHeaderSizer   unpackResourceForkHeader	mapOffsetResourceMapHeaderSizeResourceMapHeadertypeListOffsetabsTypeListOffsetnameListOffsetabsNameListOffset)r    
headerDatarE   resourceMapDatas       r   r3    ResourceReader._readHeaderAndMapV   s    		qZZ 67
):<NNR'	**%:IF(/@!%$2E2E!E!%$2E2E!Er   c                    U R                   nU R                  SU5      n[        R                  " SU5      u  U l        US-   n[        U R                  S-   5       H|  nU[        U-  -   nU R                  [        U5      n[        R                  " [        U5      n[        US   SS9nXS   -   n	US   S-   n
U R                  XU
5      nXR                  U'   M~     g )	N   z>H   type	mac-romanencodingrefListOffsetnumRes)rI   r>   structrC   numTypesrangeResourceTypeItemSizer   ResourceTypeItemr   _readReferenceListr   )r    rI   numTypesDataabsTypeListOffset2iresTypeItemOffsetresTypeItemDataitemresTyperV   rW   	resourcess               r   r4   ResourceReader._readTypeLista   s     22zz!%67!==|<.2t}}q()A 25IA5M M"jj)=?PQO>>"2ODDDL;?G-_0EEM(^a'F//OI'0OOG$ *r   c                     / n[        U5       HR  nU[        U-  -   nU R                  [        U5      n[        U5      nUR	                  Xp5        UR                  U5        MT     U$ r2   )rZ   ResourceRefItemSizer>   Resource	decompileappend)	r    rd   rV   rW   re   r`   	refOffsetrefDataress	            r   r]   !ResourceReader._readReferenceListp   sb    	vA%(;a(??Ijj!4i@G7#CMM'(S!  r   c                      U R                   U   $ r2   r   r    rd   s     r   __getitem__ResourceReader.__getitem__z   s    w''r   c                     U R                   U	 g r2   rq   rr   s     r   __delitem__ResourceReader.__delitem__}   s    OOG$r   c                      X R                   U'   g r2   rq   )r    rd   re   s      r   __setitem__ResourceReader.__setitem__   s    #, r   c                 ,    [        U R                  5      $ r2   )r;   r   r5   s    r   __len__ResourceReader.__len__   s    4??##r   c                 ,    [        U R                  5      $ r2   )iterr   r5   s    r   __iter__ResourceReader.__iter__   s    DOO$$r   c                 6    U R                   R                  5       $ r2   )r   keysr5   s    r   r   ResourceReader.keys   s    ##%%r   c                 H    [        U R                  R                  5       5      $ )z6A list of the types of resources in the resource fork.)listr   r   r5   s    r   typesResourceReader.types   s     DOO((*++r   c                 >     [        X   5      $ ! [         a     gf = f)z/Return the number of resources of a given type.r   )r;   KeyErrorrr   s     r   countResourcesResourceReader.countResources   s&    	t}%% 		s    
c                 f    U R                  U5      nU(       a  [        [        SUS-   5      5      $ / $ )z7Returns a list of indices of resources of a given type.rQ   )r   r   rZ   )r    rd   rW   s      r   
getIndicesResourceReader.getIndices   s0    $$W-a!,--Ir   c                     U R                  U/ 5       Vs/ s H  o"R                  c  M  UR                  PM     sn$ s  snf )z6Return list of names of all resources of a given type.)getr(   )r    rd   rn   s      r   getNamesResourceReader.getNames   s1    $(HHWb$9R$9SXX$9RRRs   <<c                 V    US:  a  g X   US-
     nU$ ! [         [        4 a     gf = f)zReturn resource of given type located at an index ranging from 1
to the number of resources for that type, or None if not found.
rQ   N)r   
IndexError)r    rd   indexrn   s       r   getIndResourceResourceReader.getIndResource   sC     19	-	*C 
 *% 		s   
 ((c                 r    [        USS9nU R                  U/ 5       H  nUR                  U:X  d  M  Us  $    g)z:Return the named resource of given type, else return None.rS   rT   N)r   r   r(   )r    rd   r(   rn   s       r   getNamedResourceResourceReader.getNamedResource   s9    TK088GR(Cxx4
 ) r   c                 p    U R                   R                  (       d  U R                   R                  5         g g r2   )r   closedcloser5   s    r   r   ResourceReader.close   s"    yyIIOO  r   )r   rK   rI   r   rY   r2   )r   r   r   r   __doc__r"   staticmethodr   r   r   r>   r3   r4   r]   rs   rv   ry   r|   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r      s    *     	F1(%-$%& , ,S
r   r   c                   *    \ rS rSrSr SS jrS rSrg)ri      zRepresents a resource stored within a resource fork.

Attributes:
        type: resource type.
        data: resource data.
        id: ID.
        name: resource name.
        attr: attributes.
Nc                 @    Xl         X l        X0l        X@l        XPl        g r2   )rR   r+   idr(   attr)r    rd   resDataresIDresNameresAttrs         r   r"   Resource.__init__   s     				r   c                 j   [         R                  " [        X5        [        R                  " S[	        SU R
                  /5      5      u  U l        UR
                  U R
                  -   n[        R                  " SUR                  SU5      5      u  nUR                  U5      U l        U R                  S:X  a  g UR                  U R                  -   n[        R                  " SUR                  SU5      5      u  n[        R                  " SU-  UR                  U5      5      u  n[        USS	9U l        g )
Nz>L       BrQ   z>%ssrS   rT   )r   rC   ResourceRefItemrX   r   
dataOffsetr>   r+   
nameOffsetrK   r   r(   )r    rm   readerabsDataOffset
dataLengthabsNameOffset
nameLengthr(   s           r   rj   Resource.decompile   s    6#]]4E4??;S1TU))DOO;dFLLM,JKLL,	??b 004??Bc6<<=+IJ-- 3V\\*5MN$5	r   )r   r+   r   r   r(   rR   )NNNNN)r   r   r   r   r   r"   rj   r   r   r   r   ri   ri      s     MQ6r   ri   zb
		> # big endian
		dataOffset:     L
		mapOffset:      L
		dataLen:        L
		mapLen:         L
zW
		> # big endian
		attr:              H
		typeListOffset:    H
		nameListOffset:    H
zX
		> # big endian
		type:              4s
		numRes:            H
		refListOffset:     H
z
		> # big endian
		id:                h
		nameOffset:        h
		attr:              B
		dataOffset:        3s
		reserved:          L
)ior   rX   fontTools.miscr   fontTools.misc.textToolsr   r   collectionsr   collections.abcr   	Exceptionr
   r   objectri   rD   calcsizerB   rG   rF   r\   r[   r   rh   r   r   r   <module>r      s      " 5 # *	I 	m^ m` 6v  6F  !))*<=    (():;   ''(89  &&7 r   