ó FRTc@s¼ddlZddlmZddlZddlZdefd„ƒYZdefd„ƒYZdefd„ƒYZd efd „ƒYZ d e fd „ƒYZ d e fd„ƒYZ dS(iÿÿÿÿN(tjsontSearchServiceExceptioncBseZRS((t__name__t __module__(((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/document.pyRstCommitMismatchErrorcBseZRS((RR(((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/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__(((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/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(((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/document.pyR.stDocumentServiceConnectioncBsVeZdZd d d„Zdd„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|_dS(N(tdomaintendpointtdoc_service_endpointtdocuments_batchtNonet_sdf(tselfR R ((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/document.pyt__init__Rs     tencCs=idd6|d6|d6|d6|d6}|jj|ƒdS(sª 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 version: int :param version: Version of the document being indexed. If a file is being reindexed, the version should be higher than the existing one in CloudSearch. :type fields: dict :param fields: A dictionary of key-value pairs to be uploaded . :type lang: string :param lang: The language code the data is in. Only 'en' is currently supported taddttypetidtversiontlangtfieldsN(R tappend(Rt_idRRRtd((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/document.pyRZs cCs/idd6|d6|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. :type version: int :param version: Version of the document to remove. The delete will only occur if this version number is higher than the version currently in the index. tdeleteRRRN(R R(RRRR((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/document.pyRtscCs |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((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/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(R RR (R((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/document.pyt clear_sdfs 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((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/document.pytadd_sdf_from_s3›s cCså|jƒ}d|krYtjjdƒ|jdƒ}tjj||d|d!ƒnd|j}tjƒ}tjj ddddd d ƒ}|j d |ƒ|j d |ƒ|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$http://%s/2011-02-01/documents/batchtpool_connectionsit pool_maxsizei2t max_retriesishttp://shttps://tdatatheaderssapplication/jsons Content-Type( RtbototlogterrortindexR trequeststSessiontadapterst HTTPAdaptertmounttposttCommitResponse(RtsdfR*turltsessiontadaptertr((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/document.pytcommit©s  "    "N( RRRR RRRRRR!R7(((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/document.pyR8s   R1cBs eZdZd„Zd„ZRS(sjWrapper 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.cloudsearch.document.DocumentServiceConnection` :param doc_service: Object containing the documents posted and methods to retry :raises: :class:`boto.exception.BotoServerError` :raises: :class:`boto.cloudsearch.document.SearchServiceException` :raises: :class:`boto.cloudsearch.document.EncodingError` :raises: :class:`boto.cloudsearch.document.ContentTooLongError` cCsÀ||_||_||_|jjdƒ}ytj|ƒ|_WnGtjj dj ||jƒƒtj j |jj dd|ƒ‚nX|jd|_|jdkrmg|jjdgƒD]}|jdƒ^qÂ|_xG|jD]<}d |kr td ƒ‚qê|d krêtd ƒ‚qêqêWd |jksHd|jkrvtd|jjddƒƒ‚qvn g|_|jd |_|jd|_|jd|jƒ|jd|jƒdS(Nsutf-8s9Error indexing documents. Response Content: {0} SDF: {1}ttbodytstatusR)terrorstmessagesIllegal Unicode characters%Illegal Unicode character in documentsThe Content-Length is too longsContent was too longtaddstdeletessError indexing documents => %sRR(tresponset doc_serviceR2tcontenttdecodeRtloadsR'R(R)tformatt exceptiontBotoServerErrort status_codeR:tgetR;RRRR=R>t_check_num_ops(RR?R@R2t_bodyte((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/document.pyRÛs8    %   cCsctg|jjD]}|d|kr|^qƒ}||kr_tdj|||ƒƒ‚ndS(sXRaise 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.cloudsearch.document.CommitMismatchError` Rs<Incorrect number of {0}s returned. Commit: {1} Response: {2}N(tlenR@R RRD(Rttype_t response_numRt commit_num((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/document.pyRIþs  (RRRRRI(((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/document.pyR1Ìs #( tboto.exceptionR't boto.compatRR+t ExceptionRRRRtobjectRR1(((sF/opt/freeware/lib/python2.7/site-packages/boto/cloudsearch/document.pyts     ”