3 ,WO@s@dZddlmZddlmZddlmZddlmZddlmZddlmZddl m Z dd l m Z dd l m Z dd l mZdd lmZdd lmZddlmZmZddlmZddlmZyddlmZWn0ek rddZeZZZ Z!eZYn2Xddl"mZddl"mZddl"m Z ddl"m#Z#e dZ$Gddde%eZ&ddZ'Gddde Z(Gdd d e Z)d!d"Z*d@d&d'Z+Gd(d)d)e Z,e'Z-dAd*d+Z.Gd,d-d-e(Z/dBd.d/Z0Gd0d1d1e Z1dCd2d3Z2Gd4d5d5e Z3Gd6d7d7e Z4Gd8d9d9e3e4Z5d#d#d#e fd:d;Z6Gdd?Z8d#S)Dz.Component Architecture configuration handlers )ConfigurationError)Bool)GlobalInterface) GlobalObject)PythonIdentifier)Tokens)MessageFactory) Interface) implementedBy) providedBy)TextLine)getSiteManager) adaptedBygetName)provideInterface)_BLANK) PermissioncOs tddS)NzTsecurity proxied components are not supported because zope.security is not available)r)argskwr/usr/lib/python3.6/zcml.py _no_security$sr)_checker)proxify)protectedFactory)securityAdapterFactoryZzopec@s eZdZdS)ComponentConfigurationErrorN)__name__ __module__ __qualname__rrrrr1srcOstt|}|||dS)N)getattrr )Z methodNamerkwargsmethodrrrhandler4s r#c@sNeZdZeededddZeededddZeededddZd S) IBasicComponentInformationzComponent to usezPython name of the implementation object. This must identify an object in a module using the full dotted name. If specified, the ``factory`` field must be left blank.F)title descriptionrequiredrz*Permission required to use this component.FactoryzPython name of a factory which can create the implementation object. This must identify an object in a module using the full dotted name. If specified, the ``component`` field must be left blank.N) rrrr_ componentr permissionfactoryrrrrr$8sr$c@seZdZdZeededdedZeededdd Z eed ed dee d dZ e ed eddd Z eededdd ZeededdddZeededdddZdS)IAdapterDirectivez Register an adapter zAdapter factory/factorieszHA list of factories (usually just one) that create the adapter instance.T)r%r&r' value_typez Interface the component provideszIThis attribute specifies the interface the adapter instance must provide.F)r%r&r'zSpecifications to be adaptedz.This should be a list of interfaces or classes) missing_valuerzEThis adapter is only available, if the principal has this permission.NamezYAdapters can have names. This attribute allows you to specify the name for this adapter.TrustedaIMake the adapter a trusted adapter Trusted adapters have unfettered access to the objects they adapt. If asked to adapt security-proxied objects, then, rather than getting an unproxied adapter of security-proxied objects, you get a security-proxied adapter of unproxied objects. )r%r&r'defaultLocatezMake the adapter a locatable adapter Located adapter should be used if a non-public permission is used. N)rrr__doc__rr)rr,rprovidesobjectfor_rr+r namertrustedlocaterrrrr-SsH r-csfdd}d|_|S)NcsxD] }||}qW|S)Nr)obf) factoriesrrr,s  z!_rolledUpFactory..factoryr)r,)r=r,r)r=r_rolledUpFactorys  r>NFc Cs|dkr0t|dkr t|d}|dkr0tdt|}|dkrt|dkrptt|d}t|dkrp|d}|dkrtd|dkrt|dkrt|d}|} t| dkr| d}n@t| dkrtdn*t| dkrt|dkrtdnt| }|dk rt |||}|s&|dk s&|r4t ||||}|j d|||ft d |||||j fd |j dtd|fd |rx,|D]$} | dk rz|j dtd| fd qzWdS) NrzJNo for attribute was provided and can't determine what the factory adapts.zMissing 'provides' attributer?zNo factory specifiedz-Can't use multiple factories and multiple foradapterregisterAdapter) discriminatorcallabler)lenr TypeErrortuplelistr rrr>rractionr#infor) _contextr,r5r7r+r8r9r:pr=ifacerrrrAsZ                rAc@seZdZdZeededddZeededddZeeded ddZ e ed ed dee d d Z e ededddZeededdddZeededdddZdS)ISubscriberDirectivez Register a subscriber zSubscriber factoryz1A factory used to create the subscriber instance.F)r%r&r'ZHandlerz&A callable object that handles events.z Interface the component provideszIThis attribute specifies the interface the adapter instance must provide.z5Interfaces or classes that this subscriber depends onz.This should be a list of interfaces or classes)r/)r%r&r'r.rzHThis subscriber is only available, if the principal has this permission.r1aXMake the subscriber a trusted subscriber Trusted subscribers have unfettered access to the objects they adapt. If asked to adapt security-proxied objects, then, rather than getting an unproxied subscriber of security-proxied objects, you get a security-proxied subscriber of unproxied objects. )r%r&r'r2r3zMake the subscriber a locatable subscriber Located subscribers should be used if a non-public permission is used. N)rrrr4rr)r,r#rr5rr6r7rr+rr9r:rrrrrNsFrNc Cs<|dkr.|dkrtd|dk r(td|}n |dk r>td|dkrNtd|dkrnt|}|dkrntd|dk rt|||}t|}|s|dk s|rt||||}|dk r|jdtd||t|jfdn|jdtd|||t|jfd|dk r |jdt d |fdx,|D]$}|dk r|jdt d |fdqWdS) NzNo factory or handler providedz Cannot use handler with provideszCannot use handler with factoryz@You must specify a provided interface when registering a factoryzWNo for attribute was provided and can't determine what the factory (or handler) adapts.ZregisterHandler)rCrDrZregisterSubscriptionAdapterr?) rFrrrGrrI_handlerrrJr) rKr7r,r#r5r+r9r:rMrrr subscriber&sT     rPc@s<eZdZdZeededddZeededddZdS) IUtilityDirectivezRegister a utility.zProvided interfacez"Interface provided by the utility.F)r%r&r'r0zTName of the registration. This is used by application code when locating a utility.N) rrrr4rr)r5r r8rrrrrQdsrQcCs|r|rtd|dkrT|r*tt|}n tt|}t|dkrL|d}ntd|dkrr|rjt|}nt|}|dk rt|||d}|jd||ftd||||j ft |d d |jdt d|fd dS) Nz$Can't specify factory and component.r@rzMissing 'provides' attributer?)r5r+utilityZregisterUtility)r,)rCrDrr)rCrDr) rFrHr r rErrrIr#rJdictr)rKr5r*r,r+r8rrrrRts0    rRc@s@eZdZdZeedddZeedddZeedddZ dS) IInterfaceDirectivez Define an interface r T)r%r'zInterface typeFr0N) rrrr4rr) interfacetyper r8rrrrrTsrTcCs|jdt|||fddS)N)rCrDr)rIr)rKrUrVr8rrrrUsrUc@seZdZdZeededdeeddZe ededd d Z eed ed d d Z eed edd e dZ eededd edZdS)IBasicViewInformationz,This is the basic information for all views.z*Specifications of the objects to be viewedz7This should be a list of interfaces or classes T)r/)r%r&r'r.rz&The permission needed to use the view.F)r%r&r'ZClassz2A class that provides attributes used by the view.z6Interface that is also allowed if user has permission.a= By default, 'permission' only applies to viewing the view and any possible sub views. By specifying this attribute, you can make the permission also apply to everything described in the supplied interface. Multiple interfaces can be provided, separated by whitespace.zAView attributes that are also allowed if the user has permission.z By default, 'permission' only applies to viewing the view and any possible sub views. By specifying 'allowed_attributes', you can make the permission also apply to the extra attributes on the view object.N)rrrr4rr)rr6r7rr+Zclass_rallowed_interfacerallowed_attributesrrrrrWs8 rWc@sPeZdZdZeededdedZeededde dZ eed dd Z d S) IBasicResourceInformationz) Basic information for resources zThe name of the resource.z3The name shows up in URLs/paths. For example 'foo'.T)r%r&r'r2z&The interface this component provides.zi A view can provide an interface. This would be used for views that support other views.Fz Request type)r%r'N) rrrr4r r)rr8rr r5rVrrrrrZsrZc@s$eZdZdZeeddedZdS)IViewDirectivezRegister a view for a componentr(F)r%r'r.N)rrrr4rr)rr,rrrrr[s r[c sJ|s|r| rtd|dk rNt||||} Gdddt} | |d| |d<|sZtdt|}|tdkr|d}nNtdkrtdn8tdkrt|dkrtdnfd d }d|_||f}|jd |||ftd |||||jfd |jdt d|fd |dk rFx,|D]$} | dk r|jdt d| fd qWdS)NzF'permission' required with 'allowed_interface' or 'allowed_attributes'c@s eZdZdZddZddZdS)zview..ProxyViewz#Class to create simple proxy views.cSs||_||_dS)N)r,checker)selfr,r\rrr__init__sz view..ProxyView.__init__cWst|j||jS)N)rr,r\)r]Zobjectsrrr__call__#sz view..ProxyView.__call__N)rrrr4r^r_rrrr ProxyViewsr`r@zNo for interfaces specifiedrzNo view factory specifiedz-Can't use multiple factories and multiple forcs,xddD] }||}qWd||S)Nr@rar)r;requestr<)r=rrr,7s zview..factoryviewrB)rCrDrr?rara) rrr6rGrEr,rIr#rJr) rKr,rVr8r7r+rXrYr5r\r`rMr)r=rrc sN             rcc@s8eZdZdZeeddedZeeddedZ dS)IResourceDirectivezRegister a resourcez6Interface that is also allowed if user has permission.F)r%r'r.z=View attributes that are also allowed if user has permission.N) rrrr4rr)rrXrrYrrrrrdVs rdc Cs|s|r| rtd|dk rDt||||}||fdd} || _| }|jd|||ftd||f|||jfd|jdtd|fd|jdtd|fddS)NzDMust use name attribute with allowed_interface or allowed_attributescSst|||S)N)r)rbr,r\rrr proxyResourcexszresource..proxyResourceresourcerB)rCrDrr?)rrr,rIr#rJr) rKr,rVr8r+rXrYr5r\rerrrrfgs.  rf)NNNr?FF)NNNNNFF)NNNNr?)Nr?)9r4Zzope.configuration.exceptionsrZzope.configuration.fieldsrrrrrZzope.i18nmessageidrZzope.interfacer r r Z zope.schemar Zzope.component._apir Zzope.component._declarationrrZzope.component.interfacerZzope.component._compatrZzope.security.zcmlr ImportErrorrrrrZsecurityZzope.component.securityrr) ValueErrorrr#r$r-r>rArNrOrPrQrRrTrUrWrZr[rcrdrfrrrrsl                   E  @A = # 3  H