o
    pj                     @  sL   d Z ddlmZ ddlZddlmZ G dd deZdddZdddZ	dS )z-Manifest discovery and capability resolution.    )annotationsN)AppManifestc                   @  s   e Zd ZdS )AppContractErrorN)__name__
__module____qualname__ r   r   ;/var/www/html/flask_server/bridge_platform/apps/registry.pyr   
   s    r   app_idstrreturnAppManifest | Nonec                 C  s   t d|  }t|dd }|d u rd S t|ts t|  d| }|r2t|  dd| |j| kr>td|  |S )Nzapps.APP_MANIFESTz! APP_MANIFEST has an invalid typez manifest invalid: z; z'Manifest app_id does not match module: )		importlibimport_modulegetattr
isinstancer   r   validatejoinr
   )r
   modulemanifesterrorsr   r   r	   load_manifest   s   

r   
caller_app
target_app
capabilityc                 C  st   t | }t |}|d u s|d u rtd|||s&t|  d| d| ||}|d u r8t| d| |S )Nz;Capability calls require standard v1 manifests on both appsz is not allowed to call :z does not export capability: )r   r   allows_callPermissionErroraction_for_capabilityLookupError)r   r   r   callertargetactionr   r   r	   resolve_capability   s   
r$   )r
   r   r   r   )r   r   r   r   r   r   r   r   )
__doc__
__future__r   r   bridge_platform.apps.contractsr   
ValueErrorr   r   r$   r   r   r   r	   <module>   s    
