ó FRTc@s¼ddlZddlmZddlZddlZdefd„ƒYZdefd„ƒYZdefd„ƒYZd efd „ƒYZ d e fd „ƒYZ d e fd„ƒYZ dS(iÿÿÿÿN(tjsontSearchServiceExceptioncBseZRS((t__name__t __module__(((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pyRstCommitMismatchErrorcBseZdZRS(N(RRtNoneterrors(((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pyR"st EncodingErrorcBseZdZRS(s´ Content sent for Cloud Search indexing was incorrectly encoded. This usually happens when a document is marked as unicode but non-unicode characters are present. (RRt__doc__(((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pyR(stContentTooLongErrorcBseZdZRS(sÀ Content sent for Cloud Search indexing was too long This will usually happen when documents queued for indexing add up to more than the limit allowed per upload batch (5MB) (RRR(((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pyR 2stDocumentServiceConnectioncBsSeZdZddd„Zd„Zd„Zd„Zd„Zd„Z d„Z RS( s/ A CloudSearch document service. The DocumentServiceConection is used to add, remove and update documents in CloudSearch. Commands are uploaded to CloudSearch in SDF (Search Document Format). To generate an appropriate SDF, use :func:`add` to add or update documents, as well as :func:`delete` to remove documents. Once the set of documents is ready to be index, use :func:`commit` to send the commands to CloudSearch. If there are a lot of documents to index, it may be preferable to split the generation of SDF data and the actual uploading into CloudSearch. Retrieve the current SDF with :func:`get_sdf`. If this file is the uploaded into S3, it can be retrieved back afterwards for upload into CloudSearch using :func:`add_sdf_from_s3`. The SDF is not cleared after a :func:`commit`. If you wish to continue using the DocumentServiceConnection for another batch upload of commands, you will need to :func:`clear_sdf` first to stop the previous batch of commands from being uploaded again. cCsŒ||_||_|js*|j|_ng|_d|_|jr|jjr|jjjri|jjjƒd6|_ n i|_ dS(Nthttp( tdomaintendpointtdoc_service_endpointtdocuments_batchRt_sdftlayer1t use_proxytget_proxy_url_with_authtproxy(tselfR R ((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pyt__init__Xs     $cCs/idd6|d6|d6}|jj|ƒdS(sV Add a document to be processed by the DocumentService The document will not actually be added until :func:`commit` is called :type _id: string :param _id: A unique ID used to refer to this document. :type fields: dict :param fields: A dictionary of key-value pairs to be uploaded . taddttypetidtfieldsN(Rtappend(Rt_idRtd((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pyRfs cCs(idd6|d6}|jj|ƒdS(s Schedule a document to be removed from the CloudSearch service The document will not actually be scheduled for removal until :func:`commit` is called :type _id: string :param _id: The unique ID of this document. tdeleteRRN(RR(RRR((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pyRvs cCs |jr|jStj|jƒS(s« Generate the working set of documents in Search Data Format (SDF) :rtype: string :returns: JSON-formatted string of the documents in SDF (RRtdumpsR(R((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pytget_sdf„scCsd|_g|_dS(sÊ Clear the working documents from this DocumentServiceConnection This should be used after :func:`commit` if the connection will be reused for another set of documents. N(RRR(R((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pyt clear_sdfŽs cCs|jƒ|_dS(s Load an SDF from S3 Using this method will result in documents added through :func:`add` and :func:`delete` being ignored. :type key_obj: :class:`boto.s3.key.Key` :param key_obj: An S3 key which contains an SDF N(tget_contents_as_stringR(Rtkey_obj((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pytadd_sdf_from_s3™s cCs|jƒ}d|krYtjjdƒ|jdƒ}tjj||d|d!ƒnd}|jrz|jjj}nd|j|f}t j ƒ}|j |_ t j jdddd d d ƒ}|jd |ƒ|jd |ƒ|j|d|didd6ƒ}t|||ƒS(sD Actually send an SDF to CloudSearch for processing If an SDF file has been explicitly loaded it will be used. Otherwise, documents added through :func:`add` and :func:`delete` will be used. :rtype: :class:`CommitResponse` :returns: A summary of documents added and deleted s: nulls?null value in sdf detected. This will probably raise 500 error.ids 2013-01-01shttp://%s/%s/documents/batchtpool_connectionsit pool_maxsizei2t max_retriesishttp://shttps://tdatatheaderssapplication/jsons Content-Type(R tbototlogterrortindexR Rt APIVersionR trequeststSessionRtproxiestadapterst HTTPAdaptertmounttposttCommitResponse(RtsdfR-t api_versionturltsessiontadaptertr((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pytcommit§s(  "     N( RRRRRRRR R!R$R=(((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pyR =s   R6cBs eZdZd„Zd„ZRS(snWrapper for response to Cloudsearch document batch commit. :type response: :class:`requests.models.Response` :param response: Response from Cloudsearch /documents/batch API :type doc_service: :class:`boto.cloudsearch2.document.DocumentServiceConnection` :param doc_service: Object containing the documents posted and methods to retry :raises: :class:`boto.exception.BotoServerError` :raises: :class:`boto.cloudsearch2.document.SearchServiceException` :raises: :class:`boto.cloudsearch2.document.EncodingError` :raises: :class:`boto.cloudsearch2.document.ContentTooLongError` cCs€||_||_||_|jjdƒ}ytj|ƒ|_WnGtjj dj ||jƒƒtj j |jj dd|ƒ‚nX|jd|_|jdkr-g|jjdgƒD]}|jdƒ^qÂ|_xS|jD]<}d |kr td ƒ‚qê|d krêtd ƒ‚qêqêWn g|_|jd |_|jd|_|jd|jƒ|jd|jƒdS(Nsutf-8s9Error indexing documents. Response Content: {0} SDF: {1}ttbodytstatusR,RtmessagesIllegal Unicode characters%Illegal Unicode character in documentsThe Content-Length is too longsContent was too longtaddstdeletesRR(tresponset doc_serviceR7tcontenttdecodeRtloadsR*R+R,tformatt exceptiontBotoServerErrort status_codeR@tgetRRR RBRCt_check_num_ops(RRDRER7t_bodyte((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pyRÞs2    %   cCs‹tg|jjD]}|d|kr|^qƒ}||kr‡tjj|jjƒtdj |||ƒƒ}|j |_ |‚ndS(sYRaise exception if number of ops in response doesn't match commit :type type_: str :param type_: Type of commit operation: 'add' or 'delete' :type response_num: int :param response_num: Number of adds or deletes in the response. :raises: :class:`boto.cloudsearch2.document.CommitMismatchError` Rs<Incorrect number of {0}s returned. Commit: {1} Response: {2}N( tlenRERR*R+tdebugRDRFRRIR(Rttype_t response_numRt commit_numtexc((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pyRNþs   (RRRRRN(((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pyR6Ïs ( tboto.exceptionR*t boto.compatRR/t ExceptionRRRR tobjectR R6(((sG/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch2/document.pyts     ’