FRTc@sddlZddlZddlZddlmZddlmZddlmZddl Zddl m Z ddl m Z ddlmZddlmZmZmZd e fd YZd e fd YZd efdYZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZdS(iN(thandler(tconfig(tPrice(tAWSQueryConnection(tEC2ResponseError(t ResultSet(t QuestionFormtExternalQuestiont HTMLQuestiontMTurkRequestErrorcBseZdZRS(sError for MTurk Requests(t__name__t __module__t__doc__(((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyR #stMTurkConnectioncBs/eZdZdAdAedAdAdAdAdAdAddAdAdAd ZdZdZdAdAdAdZdAdZ dAdZ dAdZ dAd d Z dAdAd Z dAdAdAejd d ddAdAdAdAejd d dAdAdAdAdAdAdZdZdAddddddZedZdZdddddAdZdAdZdAdddddAdZdAdZdAdZdAdZd ZdAd!ZdAd"ZdAd#Zd$Z d%Z!dAdAd&Z"d'd(Z#d)Z$d*Z%d+Z&d,Z'dAdAdAdAdAdAe(dd-Z)d.Z*d/Z+d0dd1Z,dAdAdAdAdAdAdAdAd2Z-d3Z.dAd4dddeed5Z/ddddd6Z0dd7Z1dAd8Z2ded9Z3d:Z4d;Z5dAd<Z6dAd=Z7ed>Z8ed?Z9ed@Z:RS(Bs 2012-03-25icCs| sBtjddr9tjdddkr9d} qBd} n| |_tt|j||||||||| | | d| d| dS(NtMTurktsandboxtTrues$mechanicalturk.sandbox.amazonaws.comsmechanicalturk.amazonaws.comtsecurity_tokent profile_name(Rt has_optiontgettdebugtsuperR t__init__(tselftaws_access_key_idtaws_secret_access_keyt is_securetporttproxyt proxy_portt proxy_usert proxy_passthostRthttps_connection_factoryRR((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyR,s*     cCsdgS(Ntmturk((R((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyt_required_auth_capabilityAscCs+i}|jd|dtfdtfgS(s tGetAccountBalancetAvailableBalancet OnHoldBalance(t_process_requestR(Rtparams((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pytget_account_balanceDs  c Cstd|d|d|j|}|jtj|jd|r_|j||d/ and can be found when looking at the details for a Queue in the AWS Console tSQSRD(RE(RRFt queue_urlRH((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pytset_sqs_notificationxstPingcCs|j|d|d||S(sx Performs a SendTestEventNotification operation with REST notification for a specified HIT type RJtSendTestEventNotification(RE(RRFRKRHttest_event_type((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pytsend_test_event_notificationsc Csi|d6}i|d6|d6tjjjjd6td6}|rW|j||dni} d} x&|D]} || | d| | fR<R=R?t annotationt questionstqualificationst layout_paramstresponse_groupsR)tneithertbothtquestion_paramtfinal_keywordst final_pricetfinal_durationtadditional_paramsRA((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyt create_hitsZ                 cCs$i|d6|d6}|jd|S(s  Change the HIT type of an existing HIT. Note that the reward associated with the new HIT type must match the reward of the current HIT type in order for the operation to be valid. :type hit_id: str :type hit_type: str tHITIdR2tChangeHITTypeOfHIT(R((Rthit_idRFR)((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pytchange_hit_type_of_hit s  t Reviewablet Expirationt Ascendingi cCshi|d6|d6|d6|d6|d6}|d k rL|ji|d6n|jd|dtfgS( s Retrieve the HITs that have a status of Reviewable, or HITs that have a status of Reviewing, and that belong to the Requester calling the operation. tStatust SortPropertyt SortDirectiontPageSizet PageNumberR2tGetReviewableHITsRnN(R9R5R(Rn(RRFtstatustsort_bytsort_directiont page_sizet page_numberR)((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pytget_reviewable_hitss    cCs/||t||}ttd|dS(s Given a page size (records per page) and a total number of records, return the page numbers to be retrieved. i(tbooltlisttrange(Rt total_recordstpages((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyt _get_pages.scsmdjd}t|j}fd}j|}tj||}tjj|S(sD Return all of a Requester's HITs Despite what search_hits says, it does not return all hits, but instead returns a page of hits. This method will pull the hits from the server 100 at a time, but will yield the results iteratively, so subsequent requests are made on demand. idRcsjdd|S(NRR(t search_hits(tpage(RR(sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pytCs(RtinttTotalNumResultsRt itertoolstimaptchaint from_iterable(Rt search_rsRt get_page_hitst page_numsthit_sets((RRsB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyt get_all_hits7s t CreationTimecCsZi|d6|d6|d6|d6}|r>|j||dn|jd|dtfgS(sI Return a page of a Requester's HITs, on behalf of the Requester. The operation returns HITs of any status, except for HITs that have been disposed with the DisposeHIT operation. Note: The SearchHITs operation does not accept any search parameters that filter the results. RRRRRlt SearchHITsRn(R^R(Rn(RRRRRRzR)((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRHs  cCsNi|d6}|r)|j||dn|jd|dtfdtfgS(s_ Retrieves an assignment using the assignment's ID. Requesters can only retrieve their own assignments, and only assignments whose related HIT has not been disposed. The returned ResultSet will have the following attributes: Request This element is present only if the Request ResponseGroup is specified. Assignment The assignment. The response includes one Assignment object. HIT The HIT associated with this assignment. The response includes one HIT object. t AssignmentIdRlt GetAssignmentt AssignmentRn(R^R(RRn(Rt assignment_idRzR)((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pytget_assignment\s    t SubmitTimec Cszi|d6|d6|d6|d6|d6}|d k rB||dt retry_delayttestt answer_keytanswer_key_xmlt test_durationt auto_grantedtauto_granted_valueR)((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pytcreate_qualification_typejs0-             cCs)i|d6}|jd|dtfgS(NtQualificationTypeIdtGetQualificationTypeR(R(R(Rtqualification_type_idR)((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pytget_qualification_types  csmdj}t|j}fd}j|}tj||}tjj|S(Nidcsjddd|S(NRRR(t)get_qualifications_for_qualification_type(R(RRR(sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRs(RRRRRRRR(RRt search_qualRtget_page_qualsRt qual_sets((RRRsB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyt$get_all_qualifications_for_qual_typesidcCs7i|d6|d6|d6}|jd|dtfgS(NRRRt%GetQualificationsForQualificationTypet Qualification(R(R(RRRRR)((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRs    c Cs$i|d6} |dk r&|| dN( treadRRRt XmlHandlertxmltsaxt parseStringR RR(RR6R5tbodytrsth((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyR4Hs   cCst|tr!dj|}nt|tr9|}nLt|trZ|jd}n+|dkrod}ntdt||S(sk Returns a comma+space-separated string of keywords from either a list or a string s, sutf-8tsAkeywords argument must be a string or a list of strings; got a %sN( RpRtjointstrtunicodetencodeR9Rttype(R>R~((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyR8Ws   cCs(t|tr|}n t|}|S(sO Returns a Price data structure from either a float or a Price (RpR(R<R((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyR6is  cCsgt|tjr)|jd|j}nyt|}Wn'tk rbtdt|nX|S(NiQs4Duration must be a timedelta or int-castable, got %s(Rptdatetimet timedeltaRftsecondsRRRD(R=((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyR4ts N(;R R t APIVersionR9RRR$R*RBRIRLRORSRERERFRRRt staticmethodRRRRRRRRRRRRRRRRRRRRtFalseRRR RRRRRR#R'R,R.R0R(R4R8R6R4(((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyR (s        &  O   (             D   $         tBaseAutoResultElementcBs)eZdZdZdZdZRS(sE Base class to automatically add attributes when parsing XML cCsdS(N((Rt connection((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRscCsdS(N(R9(RRtattrsRL((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyt startElementscCst|||dS(N(tsetattr(RRR*RL((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyt endElements(R R R RRNRP(((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRKs  RncBs#eZdZdZeeZRS(s Class to extract a HIT structure from a response (used in ResultSet) Will have attributes named as per the Developer Guide, e.g. HITId, HITTypeId, CreationTime cCs[t}t|drKtjj}tjj|jd}||k}n td|S(s Has this HIT expired yet? Rs%Y-%m-%dT%H:%M:%SZs>ERROR: Request for expired property, but no Expiration in HIT!(RJthasattrREtutcnowtstrptimeRRo(Rtexpiredtnowt expiration((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyt _has_expireds (R R R RWtpropertyRT(((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRns RcBseZdZRS(sE Class to extract an FileUploadURL structure from a response (R R R (((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRsR2cBseZdZRS(sA Class to extract an HITTypeId structure from a response (R R R (((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyR2sRcBseZdZRS(s Class to extract an Qualification structure from a response (used in ResultSet) Will have attributes named as per the Developer Guide such as QualificationTypeId, IntegerValue. Does not seem to contain GrantTime. (R R R (((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRsRcBseZdZRS(s Class to extract an QualificationType structure from a response (used in ResultSet) Will have attributes named as per the Developer Guide, e.g. QualificationTypeId, CreationTime, Name, etc (R R R (((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRsRcBs eZdZdZdZRS(s Class to extract an QualificationRequest structure from a response (used in ResultSet) Will have attributes named as per the Developer Guide, e.g. QualificationRequestId, QualificationTypeId, SubjectId, etc cCs#tt|j|g|_dS(N(RRRtanswers(RRL((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRscCs|dkrhtdtfg}tj||}|j|}tjj|||jj |nt t |j |||dS(NtAnswer( RtQuestionFormAnswerRR8tget_utf8_valueR9R:R;RYtappendRRRP(RRR*RLt answer_rsR>((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRPs (R R R RRP(((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRs RcBs eZdZdZdZRS(s Class to extract an Assignment structure from a response (used in ResultSet) Will have attributes named as per the Developer Guide, e.g. AssignmentId, WorkerId, HITId, Answer, etc cCs#tt|j|g|_dS(N(RRRRY(RRL((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRscCs|dkrhtdtfg}tj||}|j|}tjj|||jj |nt t |j |||dS(NRZ( RR[RR8R\R9R:R;RYR]RRRP(RRR*RLR^R>((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRPs (R R R RRP(((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRs R[cBs eZdZdZdZRS(s: Class to extract Answers from inside the embedded XML QuestionFormAnswers element inside the Answer element which is part of the Assignment and QualificationRequest structures A QuestionFormAnswers element contains an Answer element for each question in the HIT or Qualification test for which the Worker provided an answer. Each Answer contains a QuestionIdentifier element whose value corresponds to the QuestionIdentifier of a Question in the QuestionForm. See the QuestionForm data structure for more information about questions and answer specifications. If the question expects a free-text answer, the Answer element contains a FreeText element. This element contains the Worker's answer *NOTE* - currently really only supports free-text and selection answers cCs,tt|j|g|_d|_dS(N(RR[RtfieldsR9tqid(RRL((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRs cCsD|dkr||_n(|dkr@|jr@|jj|ndS(NRtFreeTexttSelectionIdentifiertOtherSelectionText(RaRbRc(R`R_R](RRR*RL((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyRPs  (R R R RRP(((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyR[s ( txml.saxR9RERRZRRtboto.mturk.priceRtboto.mturk.notificationtboto.connectionRtboto.exceptionRtboto.resultsetRtboto.mturk.questionRRRR R tobjectRKRnRR2RRRRR[(((sB/opt/freeware/lib/python2.7/site-packages/boto/mturk/connection.pyts0    Z