ó h'dWc@s dZddlZddlZddlmZmZmZmZm Z m Z m Z m Z m Z mZddlmZmZmZmZde fd„ƒYZdS(s AI Manifest Interface iÿÿÿÿN( tCriteriat AIServerErrort ERROR_TYPEtSERVICE_STATUStEventsGeneratortObjectChangedEventt DeletedEventt CreatedEventt check_authst MANIFEST_AUTH(t ai_databasetget_server_instancetlogtMAX_MANIFEST_NAME_LENtManifestcBs"eZdZdded„Zed„ƒZd„Zed„ƒZ ed„ƒZ ed„ƒZ d„Z d„Z ed „ƒZed „ƒZed „ƒZed „ƒZed „ƒZd„Zeeed„Zed„ƒZed„ƒZed„ƒZed„ƒZd„ZRS(sThe Manifest interface represents a manifest in the AI server. Each specific manifest is associated with exactly one AI service. The following event types are possible for a Manifest: - ObjectChangedEvent - CreatedEvent - DeletedEvent cCs||_||_||_||_t|_t|_|dkrW|j|ƒ|_n|j |j ƒ|j j d|j ƒr¡t tjtdƒ|j ƒ‚n|ttfkrÎt tjtdƒƒ‚n|rã||j _ntt|ƒjtttgƒdS(sIThis method creates a new manifest for the service, initializing with the specified values. Parameters name: String Optional: This is the name to be given to the manifest, if no name is provided then the name will be extracted from the ai_instance tag's name attribute in the XML in the content. content: String This is the complete content of an XML manifest file, and will be validated against the service it's being added to. criteria: Criteria Object Optional: This is the Criteria used in selecting a manifest for use by a client. If omitted then the manifest will only be assigned to a client if it is set as the default for the service. default: Boolean Optional: Set this manifest as the default manifest for the service. Return Value None Errors / Exceptions AIServerError The following error types can be raised by this method: - ParsingError This error/exception will be raised should the provided manifest content fail to validate against the DTDs in the service. tfilter_by_namesDuplicated manifest name: '%s's!Default can only be True or FalseN(t_servicet_contentt_namet _criteriatFalset_criteria_fetchedt_pendingtNonetget_name_from_contentt validate_nametnametservicet get_manifestsRRtDUPLICATE_ENTRYt_tTruet INVALID_VALUEt_default_manifesttsuperRt__init__RRR(tselfRtcontentRtcriteriatdefault((s manifest.pyR#0s(!          c Ksâttƒ||||}t|_|jƒtƒ}tƒ}||d<|j|d<||d<|j|d<|j|d<|j |dtnametag(RRR Rt isinstancet basestringRAtlenR R tdebugtAIdbt sanitize_sqlR<R=R>tsett ExceptionR(R5Rtroot((s manifest.pyRÏs*      cCs |jdƒS(s@Return True if the contents are from a derived manifest s#!(t startswith(R5R%((s manifest.pyR;öscCsùtj|ƒrdSytjj|ƒ}Wn;tjjk rf}ttj t dƒt |ƒƒ‚nX|j dƒ}|dkrttj t dƒƒ‚ny|j dƒ}t |ƒ}Wn6tk rôttjt dƒ|jdƒƒ‚nX|S(sExtracts and returns the manifest name from the XML content Parameters content: String This is the complete content of an XML manifest file. Return Value String The manifest name according to the attribute of the ai_instance tag. If no name attribute is found on a valid manifest or the contents are from a derived manifest, it will return None. Errors / Exceptions AIServerError The following error types can be raised by this method: - ParsingError This signifies that there was some issue with the XML, more information can be found in the error's reason field. sManifest Error: %st ai_instances,Manifest Error: No ai_instance tag was foundRsInvalid manifest name: '%s'sutf-8N(RR;RR<R=R>R?RRR@RRAtfindtgettUnicodeEncodeErrorR tencode(R5R%RQRGRSRt manifest_name((s manifest.pyRüs&      c CsÙttƒ|jjd|jƒsDttjtdƒ|jƒ‚nt ƒ}t ƒ}||d<|jj|d<|j|ds   F"