B
    g_*                 @   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   s0   d}| t krd}n| tkr d}n| 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| @ r4|d }t| @ rD|d }t| @ rT|d }t| @ rd|d }t| @ rt|d }t| @ r|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rstrip)r   r   r   r   r   _propertymode_to_str6   s$    r%   c             C   s$  t | tjsHt | tjsHt | tjsHt | tjsHt | tjsHt | tjr^|t	| d  d S t
 }|jd|}|d t| dr|  }x*|D ]}|d| d  qW n
|d |d t| dr|  }x,|D ]}|d|j d  qW n
|d || }|t}|d	 x|D ]}|d|jj d
 |j  |j}	|j}
|d x\tdt|	D ]J}|dkr|d |t|
| jd
 |	| j d
 |
| j  qpW |d q*W |t}|d x<|D ]4}|dt|j  d |jj d
 |j d  qW d 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outZctxZintrospectionnamesZiiZ
interfacesaccessmethodsargsZinfosiZpropsr   r   r   r2   J   sN    














6


r2   c             C   s   t | ||S )N)_FactoryHelper_)clazzimplementationNameserviceNamesr   r   r   createSingleServiceFactory{   s    rC   c               @   s   e Zd Zdd ZdS )_ImplementationHelperEntryc             C   s   || _ || _d S )N)ctorrB   )selfrE   rB   r   r   r   __init__   s    z#_ImplementationHelperEntry.__init__N)__name__
__module____qualname__rG   r   r   r   r   rD   ~   s   rD   c               @   s<   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 )N)impls)rF   r   r   r   rG      s    zImplementationHelper.__init__c             C   s   t ||| j|< d S )N)rD   rL   )rF   rE   rA   rB   r   r   r   addImplementation   s    z&ImplementationHelper.addImplementationc             C   sT   xNt | j D ]<}d|d  d }||}x|d jD ]}|| q:W qW dS )N/r   z/UNO/SERVICES   )listrL   items	createKeyrB   )rF   regKeysmgrr>   keyNamekeyserviceNamer   r   r   writeRegistryInfo   s    
z&ImplementationHelper.writeRegistryInfoc             C   s4   | j |d }|d kr$t|d d t|j||jS )Nz is unknown)rL   getr   rC   rE   rB   )rF   rA   rS   rT   entryr   r   r   getComponentFactory   s    z(ImplementationHelper.getComponentFactoryc             C   s*   | j |d }|d kr$t|d d |jS )Nz is unknown)rL   rY   r   rB   )rF   rA   rZ   r   r   r   r'      s    z-ImplementationHelper.getSupportedServiceNamesc             C   s.   | j |d }|d kr$t|d d ||jkS )Nz is unknown)rL   rY   r   rB   )rF   rA   rW   rZ   r   r   r   supportsService   s    z$ImplementationHelper.supportsServiceN)	rH   rI   rJ   rG   rM   rX   r[   r'   r\   r   r   r   r   rK      s   rK   c               @   s   e Zd Zdd ZdS )ImplementationEntryc             C   s   || _ || _|| _d S )N)implNamesupportedServicesr@   )rF   r^   r_   r@   r   r   r   rG      s    zImplementationEntry.__init__N)rH   rI   rJ   rG   r   r   r   r   r]      s   r]   c             C   sD   x>|D ]6}d|j  d }||}x|jD ]}|| q*W qW d S )NrN   z/UNO/SERVICES)r^   rR   r_   )rT   rS   
seqEntriesrZ   rU   rV   rW   r   r   r   writeRegistryInfoHelper   s
    

ra   c             C   s
   t | S )z,returns a file-url for the given system path)pyunosystemPathToFileUrl)Z
systemPathr   r   r   rc      s    rc   c             C   s
   t | S )zVreturns a system path (determined by the system, the python interpreter is running on))rb   fileUrlToSystemPath)Zurlr   r   r   rd      s    rd   c             C   s   t | |S )z0returns an absolute file url from the given urls)rb   
absolutize)pathZrelativeUrlr   r   r   re      s    re   c             C   s,   x&|D ]}|j | krt|j| |jS qW d S )N)r^   rC   r@   r_   )rA   rT   rS   r`   xr   r   r   getComponentFactoryHelper   s    

rh   c             C   s   |j }|||}|d|}tjdkp0tjdk}tjdk}x|D ]}	|d|}
|
ddd |s|	d	r|r||	d
 }	n|	d }	|||	|
 |
	 }|
d}| }| j }x0|D ](}|t|dd|	|}|| qW |
  qBW d S )Nz0com.sun.star.registry.ImplementationRegistrationntZdosdarwinz$com.sun.star.registry.SimpleRegistryr   r   rO   z.unoz.dylibz.soZIMPLEMENTATIONSrN   )r/   r0   osnamesysplatformopenendswithZregisterImplementationZ
getRootKeyZopenKeyZgetKeyNamesZactivatemaxsplitinsertclose)ZtoBeExtendedContextZcontextRuntimeZcomponentUrlsZ
loaderNamerT   loaderZimplRegZisWinZisMacZcomponentUrlZregZrootKeyZimplementationKeyZ	implNamesZextSMGRrg   Zfacr   r   r   addComponentsToContext   s*    




rv   c       
      C   s   d }| j tkrt| j  }ni }t| j j}xLt|dkrv| }|j}t|r\d ||j< q,t|dkr,|t| }q,W t|	 }g }x |D ]}t
|}	||	 qW t|}|t| j < |S )Nr   )	__class___g_typeTablerP   	__bases__r6   popr+   ZisInterfaceZ__pyunointerface__keysZgetTypeByNameappendtuple)
rF   r   r:   ZtraverseitembasesZlsttypesrg   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 )N)r   )rF   r   r   r   r(      s    zBase.getTypesc             C   s   dS )Nr   r   )rF   r   r   r   getImplementationId   s    zBase.getImplementationIdN)rH   rI   rJ   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 )N)hashMap
oldContext)rF   r   r   r   r   r   rG     s    zCurrentContext.__init__c             C   s2   || j kr| j | S | jd k	r*| j|S d S d S )N)r   r   getValueByName)rF   rl   r   r   r   r   	  s
    


zCurrentContext.getValueByNameN)rH   rI   rJ   __doc__rG   r   r   r   r   r   r      s   r   c               @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )r?   c             C   s   || _ || _|| _d S )N)r@   rA   rB   )rF   r@   rA   rB   r   r   r   rG     s    z_FactoryHelper_.__init__c             C   s   | j S )N)rA   )rF   r   r   r   getImplementationName  s    z%_FactoryHelper_.getImplementationNamec             C   s
   || j kS )N)rB   )rF   ZServiceNamer   r   r   r\     s    z_FactoryHelper_.supportsServicec             C   s   | j S )N)rB   )rF   r   r   r   r'      s    z(_FactoryHelper_.getSupportedServiceNamesc             C   s
   |  |S )N)r@   )rF   contextr   r   r   r0   #  s    z)_FactoryHelper_.createInstanceWithContextc             C   s   | j |f| S )N)r@   )rF   r=   r   r   r   r   %createInstanceWithArgumentsAndContext&  s    z5_FactoryHelper_.createInstanceWithArgumentsAndContextN)	rH   rI   rJ   rG   r   r\   r'   r0   r   r   r   r   r   r?     s   r?   ):r+   rb   rk   rm   Zcom.sun.star.langr   r   r   Zcom.sun.star.unor   r   Z com.sun.star.beans.MethodConceptr   r3   Z"com.sun.star.beans.PropertyConceptr7   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%   r2   rC   rD   rK   r]   ra   rc   rd   re   rh   rv   rx   r   r   r   r?   r   r   r   r   <module>   s6   (

1"