o
    P!;b*                     @   sX  d dl Z d dlZd dlZd dlZd dlmZmZmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZmZ d dlmZmZmZmZm Z!m"Z#m$Z%m&Z' dd Z(d	d
 Z)dd Z*dd Z+G dd dZ,G dd dZ-G dd dZ.dd Z/dd Z0dd Z1dd Z2dd Z3dd  Z4i Z5d!d" Z6G d#d$ d$eZ7G d%d& d&e
e7Z8G d'd( d(eee7Z9dS ))    N)XTypeProviderXSingleComponentFactoryXServiceInfo)RuntimeExceptionXCurrentContext)ALL)INOUTINOUT)	MAYBEVOIDBOUNDCONSTRAINED	TRANSIENTREADONLYMAYBEAMBIGUOUSMAYBEDEFAULT	REMOVABLEc                 C   s4   d}| t kr
d}|S | tkrd}|S | tkrd}|S )Nz[]z[inout]z[out]z[in])PARAM_MODE_INOUTPARAM_MODE_OUTPARAM_MODE_INmoderet r   +/usr/lib/python3/dist-packages/unohelper.py_mode_to_str,   s   r   c                 C   s   d}t | @ r
|d }t| @ r|d }t| @ r|d }t| @ r"|d }t| @ r*|d }t| @ r2|d }t| @ r:|d }t| @ rB|d	 }| S )
N z
removable zmaybedefault zmaybeambiguous z	readonly z
transient zconstrained zbound z
maybevoid )	PROP_ATTR_REMOVABLEPROP_ATTR_MAYBEDEFAULTPROP_ATTR_MAYBEAMBIGUOUSPROP_ATTR_READONLYPROP_ATTR_TRANSIENTPROP_ATTR_CONSTRAINEDPROP_ATTR_BOUNDPROP_ATTR_MAYBEVOIDrstripr   r   r   r   _propertymode_to_str6   s$   r&   c                 C   s  t | tjs$t | tjs$t | tjs$t | tjs$t | tjs$t | tjr/|t	| d  d S t
 }|jd|}|d t| drW|  }|D ]}|d| d  qJn|d |d t| drz|  }|D ]}|d|j d  qln|d || }|t}|d	 |D ]K}|d|jj d
 |j  |j}	|j}
|d tdt|	D ]#}|dkr|d |t|
| jd
 |	| j d
 |
| j  q|d q|t}|d |D ]}|dt|j  d |jj d
 |j d  qd S )N
z com.sun.star.beans.IntrospectionzSupported services:
getSupportedServiceNamesz  z
  unknown
zInterfaces:
getTypesz	Methods:
 z( r   z, z )
zProperties:
z  (z) )!
isinstanceunoZTypeZCharZBoolZByteSequenceEnumZAnywritestrZgetComponentContextServiceManagercreateInstanceWithContexthasattrr(   r)   ZtypeNameinspectZ
getMethodsMETHOD_CONCEPT_ALLZ
ReturnTypeNameZParameterTypesZParameterInfosrangelenr   ZaModeZaNameZgetPropertiesPROPERTY_CONCEPT_ALLr&   Z
Attributes)objoutctxZintrospectionnamesiiZ
interfacesaccessmethodsargsZinfosiZpropsr   r   r   r3   J   s`   















2

0r3   c                 C   s   t | ||S N)_FactoryHelper_clazzimplementationNameserviceNamesr   r   r   createSingleServiceFactory{   s   rH   c                   @      e Zd Zdd ZdS )_ImplementationHelperEntryc                 C   s   || _ || _d S rB   )ctorrG   )selfrK   rG   r   r   r   __init__      
z#_ImplementationHelperEntry.__init__N__name__
__module____qualname__rM   r   r   r   r   rJ   ~       rJ   c                   @   <   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )ImplementationHelperc                 C   s
   i | _ d S rB   )implsrL   r   r   r   rM         
zImplementationHelper.__init__c                 C   s   t ||| j|< d S rB   )rJ   rV   )rL   rK   rF   rG   r   r   r   addImplementation   s   z&ImplementationHelper.addImplementationc                 C   sL   t | j D ]}d|d  d }||}|d jD ]}|| qqdS )N/r   /UNO/SERVICES   )listrV   items	createKeyrG   )rL   regKeysmgrrA   keyNamekeyserviceNamer   r   r   writeRegistryInfo   s   
z&ImplementationHelper.writeRegistryInfoc                 C   s4   | j |d }|d u rt|d d t|j||jS Nz is unknown)rV   getr   rH   rK   rG   )rL   rF   r`   ra   entryr   r   r   getComponentFactory   s   z(ImplementationHelper.getComponentFactoryc                 C   s*   | j |d }|d u rt|d d |jS rf   rV   rg   r   rG   )rL   rF   rh   r   r   r   r(      s   z-ImplementationHelper.getSupportedServiceNamesc                 C   s.   | j |d }|d u rt|d d ||jv S rf   rj   )rL   rF   rd   rh   r   r   r   supportsService   s   
z$ImplementationHelper.supportsServiceN)	rP   rQ   rR   rM   rY   re   ri   r(   rk   r   r   r   r   rU      s    rU   c                   @   rI   )ImplementationEntryc                 C      || _ || _|| _d S rB   )implNamesupportedServicesrE   )rL   rn   ro   rE   r   r   r   rM         
zImplementationEntry.__init__NrO   r   r   r   r   rl      rS   rl   c                 C   s<   |D ]}d|j  d }||}|jD ]}|| qqd S )NrZ   r[   )rn   r_   ro   )ra   r`   
seqEntriesrh   rb   rc   rd   r   r   r   writeRegistryInfoHelper   s   

rr   c                 C   
   t | S )z,returns a file-url for the given system path)pyunosystemPathToFileUrl)Z
systemPathr   r   r   ru         
ru   c                 C   rs   )zVreturns a system path (determined by the system, the python interpreter is running on))rt   fileUrlToSystemPath)Zurlr   r   r   rw      rv   rw   c                 C   s   t | |S )z0returns an absolute file url from the given urls)rt   
absolutize)pathZrelativeUrlr   r   r   rx      s   rx   c                 C   s,   |D ]}|j | krt|j| |j  S qd S rB   )rn   rH   rE   ro   )rF   ra   r`   rq   xr   r   r   getComponentFactoryHelper   s
   
r{   c                 C   s   |j }|||}|d|}tjdkptjdk}tjdk}|D ]S}	|d|}
|
ddd |sA|	d	rA|r=|	d
 }	n|	d }	|||	|
 |
	 }|
d}| }| j }|D ]}|t|dd|	|}|| qZ|
  q d S )Nz0com.sun.star.registry.ImplementationRegistrationntZdosdarwinz$com.sun.star.registry.SimpleRegistryr   r   r\   z.unoz.dylibz.soZIMPLEMENTATIONSrZ   )r0   r1   osnamesysplatformopenendswithZregisterImplementationZ
getRootKeyZopenKeyZgetKeyNamesZactivatemaxsplitinsertclose)ZtoBeExtendedContextZcontextRuntimeZcomponentUrlsZ
loaderNamera   loaderZimplRegZisWinZisMacZcomponentUrlZregZrootKeyZimplementationKeyZ	implNamesZextSMGRrz   Zfacr   r   r   addComponentsToContext   s,   



r   c           
      C   s   d }| j tv rt| j  }|S i }t| j j}t|dkr@| }|j}t|r.d ||j< nt|dkr:|t| }t|dkst|	 }g }|D ]}t
|}	||	 qJt|}|t| j < |S )Nr   )	__class___g_typeTabler]   	__bases__r7   popr,   ZisInterfaceZ__pyunointerface__keysZgetTypeByNameappendtuple)
rL   r   r<   ZtraverseitembasesZlsttypesrz   tr   r   r   _unohelper_getHandle   s,   


	

r   c                   @   s   e Zd Zdd Zdd ZdS )Basec                 C   s   t | S rB   )r   rW   r   r   r   r)      s   zBase.getTypesc                 C   s   dS )Nr   r   rW   r   r   r   getImplementationId   s   zBase.getImplementationIdN)rP   rQ   rR   r)   r   r   r   r   r   r      s    r   c                   @   s    e Zd ZdZdd Zdd ZdS )CurrentContextza current context implementation, which first does a lookup in the given
       hashmap and if the key cannot be found, it delegates to the predecessor
       if available
    c                 C   s   || _ || _d S rB   )hashMap
oldContext)rL   r   r   r   r   r   rM     rN   zCurrentContext.__init__c                 C   s.   || j v r
| j | S | jd ur| j|S d S rB   )r   r   getValueByName)rL   r   r   r   r   r   	  s
   


zCurrentContext.getValueByNameN)rP   rQ   rR   __doc__rM   r   r   r   r   r   r      s    r   c                   @   rT   )rC   c                 C   rm   rB   rD   )rL   rE   rF   rG   r   r   r   rM     rp   z_FactoryHelper_.__init__c                 C      | j S rB   )rF   rW   r   r   r   getImplementationName     z%_FactoryHelper_.getImplementationNamec                 C   s
   || j v S rB   rG   )rL   ZServiceNamer   r   r   rk     rX   z_FactoryHelper_.supportsServicec                 C   r   rB   r   rW   r   r   r   r(      r   z(_FactoryHelper_.getSupportedServiceNamesc                 C   s
   |  |S rB   rE   )rL   contextr   r   r   r1   #  rX   z)_FactoryHelper_.createInstanceWithContextc                 C   s   | j |g|R  S rB   r   )rL   r@   r   r   r   r   %createInstanceWithArgumentsAndContext&  s   z5_FactoryHelper_.createInstanceWithArgumentsAndContextN)	rP   rQ   rR   rM   r   rk   r(   r1   r   r   r   r   r   rC     s    rC   ):r,   rt   r~   r   Zcom.sun.star.langr   r   r   Zcom.sun.star.unor   r   Z com.sun.star.beans.MethodConceptr   r4   Z"com.sun.star.beans.PropertyConceptr8   Z!com.sun.star.reflection.ParamModer   r   r	   r   r
   r   Z$com.sun.star.beans.PropertyAttributer   r$   r   r#   r   r"   r   r!   r   r    r   r   r   r   r   r   r   r&   r3   rH   rJ   rU   rl   rr   ru   rw   rx   r{   r   r   r   r   r   rC   r   r   r   r   <module>   s8   (

1"