B
    LE^*                 @   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   (G:\Soft\LibreOffice\program\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unoTypeCharBoolByteSequenceEnumAnywritestrgetComponentContextServiceManagercreateInstanceWithContexthasattrr'   r(   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namesZiiZ
interfacesaccessmethodsargsZinfosiZpropsr   r   r   r9   J   sN    














6


r9   c             C   s   t | ||S )N)_FactoryHelper_)clazzimplementationNameserviceNamesr   r   r   createSingleServiceFactory{   s    rK   c               @   s   e Zd Zdd ZdS )_ImplementationHelperEntryc             C   s   || _ || _d S )N)ctorrJ   )selfrM   rJ   r   r   r   __init__   s    z#_ImplementationHelperEntry.__init__N)__name__
__module____qualname__rO   r   r   r   r   rL   ~   s   rL   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)rN   r   r   r   rO      s    zImplementationHelper.__init__c             C   s   t ||| j|< d S )N)rL   rT   )rN   rM   rI   rJ   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   )listrT   items	createKeyrJ   )rN   regKeysmgrrF   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)rT   getr   rK   rM   rJ   )rN   rI   r[   r\   entryr   r   r   getComponentFactory   s    z(ImplementationHelper.getComponentFactoryc             C   s*   | j |d }|d kr$t|d d |jS )Nz is unknown)rT   ra   r   rJ   )rN   rI   rb   r   r   r   r'      s    z-ImplementationHelper.getSupportedServiceNamesc             C   s.   | j |d }|d kr$t|d d ||jkS )Nz is unknown)rT   ra   r   rJ   )rN   rI   r_   rb   r   r   r   supportsService   s    z$ImplementationHelper.supportsServiceN)	rP   rQ   rR   rO   rU   r`   rc   r'   rd   r   r   r   r   rS      s   rS   c               @   s   e Zd Zdd ZdS )ImplementationEntryc             C   s   || _ || _|| _d S )N)implNamesupportedServicesrH   )rN   rf   rg   rH   r   r   r   rO      s    zImplementationEntry.__init__N)rP   rQ   rR   rO   r   r   r   r   re      s   re   c             C   sD   x>|D ]6}d|j  d }||}x|jD ]}|| q*W qW d S )NrV   z/UNO/SERVICES)rf   rZ   rg   )r\   r[   
seqEntriesrb   r]   r^   r_   r   r   r   writeRegistryInfoHelper   s
    

ri   c             C   s
   t | S )z,returns a file-url for the given system path)pyunosystemPathToFileUrl)
systemPathr   r   r   rk      s    rk   c             C   s
   t | S )zVreturns a system path (determined by the system, the python interpreter is running on))rj   fileUrlToSystemPath)urlr   r   r   rm      s    rm   c             C   s   t | |S )z0returns an absolute file url from the given urls)rj   
absolutize)pathrelativeUrlr   r   r   ro      s    ro   c             C   s,   x&|D ]}|j | krt|j| |jS qW d S )N)rf   rK   rH   rg   )rI   r\   r[   rh   xr   r   r   getComponentFactoryHelper   s    

rs   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   rW   z.unoz.dylibz.soZIMPLEMENTATIONSrV   )r5   r6   osnamesysplatformopenendswithZregisterImplementationZ
getRootKeyZopenKeyZgetKeyNamesactivatemaxsplitinsertclose)ZtoBeExtendedContextZcontextRuntimeZcomponentUrlsZ
loaderNamer\   loaderZimplRegZisWinZisMacZcomponentUrlZregZrootKeyZimplementationKeyZ	implNamesZextSMGRrr   Zfacr   r   r   addComponentsToContext   s*    




r   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_typeTablerX   	__bases__r=   popr+   isInterfaceZ__pyunointerface__keysgetTypeByNameappendtuple)
rN   r   rB   ZtraverseitembasesZlsttypesrr   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   )rN   r   r   r   r(      s    zBase.getTypesc             C   s   dS )Nr   r   )rN   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 )N)hashMap
oldContext)rN   r   r   r   r   r   rO     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)rN   rw   r   r   r   r   	  s
    


zCurrentContext.getValueByNameN)rP   rQ   rR   __doc__rO   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 )rG   c             C   s   || _ || _|| _d S )N)rH   rI   rJ   )rN   rH   rI   rJ   r   r   r   rO     s    z_FactoryHelper_.__init__c             C   s   | j S )N)rI   )rN   r   r   r   getImplementationName  s    z%_FactoryHelper_.getImplementationNamec             C   s
   || j kS )N)rJ   )rN   ServiceNamer   r   r   rd     s    z_FactoryHelper_.supportsServicec             C   s   | j S )N)rJ   )rN   r   r   r   r'      s    z(_FactoryHelper_.getSupportedServiceNamesc             C   s
   |  |S )N)rH   )rN   contextr   r   r   r6   #  s    z)_FactoryHelper_.createInstanceWithContextc             C   s   | j |f| S )N)rH   )rN   rE   r   r   r   r   %createInstanceWithArgumentsAndContext&  s    z5_FactoryHelper_.createInstanceWithArgumentsAndContextN)	rP   rQ   rR   rO   r   rd   r'   r6   r   r   r   r   r   rG     s   rG   ):r+   rj   rv   rx   com.sun.star.langr   r   r   com.sun.star.unor   r   Z com.sun.star.beans.MethodConceptr   r:   Z"com.sun.star.beans.PropertyConceptr>   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%   r9   rK   rL   rS   re   ri   rk   rm   ro   rs   r   r   r   r   r   rG   r   r   r   r   <module>   s6   (

1"