Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: boto/mturk/question.py

Issue 8386013: Merging in latest boto. (Closed) Base URL: svn://svn.chromium.org/boto
Patch Set: Redoing vendor drop by deleting and then merging. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « boto/mturk/notification.py ('k') | boto/provider.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ 1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
2 # 2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a 3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the 4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including 5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis- 6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit 7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol- 8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions: 9 # lowing conditions:
10 # 10 #
11 # The above copyright notice and this permission notice shall be included 11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software. 12 # in all copies or substantial portions of the Software.
13 # 13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE. 20 # IN THE SOFTWARE.
21 21
22 class Question(object): 22 class Question(object):
23 template = "<Question>%(items)s</Question>" 23 template = "<Question>%(items)s</Question>"
24 24
25 def __init__(self, identifier, content, answer_spec, is_required=False, disp lay_name=None): 25 def __init__(self, identifier, content, answer_spec,
26 is_required=False, display_name=None):
26 # copy all of the parameters into object attributes 27 # copy all of the parameters into object attributes
27 self.__dict__.update(vars()) 28 self.__dict__.update(vars())
28 del self.self 29 del self.self
29 30
30 def get_as_params(self, label='Question'): 31 def get_as_params(self, label='Question'):
31 return { label : self.get_as_xml() } 32 return { label : self.get_as_xml() }
32 33
33 def get_as_xml(self): 34 def get_as_xml(self):
34 items = [ 35 items = [
35 SimpleField('QuestionIdentifier', self.identifier), 36 SimpleField('QuestionIdentifier', self.identifier),
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 return { label : self.get_as_xml() } 170 return { label : self.get_as_xml() }
170 171
171 def get_as_xml(self): 172 def get_as_xml(self):
172 content = super(Overview, self).get_as_xml() 173 content = super(Overview, self).get_as_xml()
173 return self.template % vars() 174 return self.template % vars()
174 175
175 class QuestionForm(ValidatingXML, list): 176 class QuestionForm(ValidatingXML, list):
176 """ 177 """
177 From the AMT API docs: 178 From the AMT API docs:
178 179
179 The top-most element of the QuestionForm data structure is a QuestionForm el ement. This 180 The top-most element of the QuestionForm data structure is a
180 element contains optional Overview elements and one or more Question element s. There can be 181 QuestionForm element. This element contains optional Overview
181 any number of these two element types listed in any order. The following exa mple structure has an 182 elements and one or more Question elements. There can be any
182 Overview element and a Question element followed by a second Overview elemen t and Question 183 number of these two element types listed in any order. The
183 element--all within the same QuestionForm. 184 following example structure has an Overview element and a
185 Question element followed by a second Overview element and
186 Question element--all within the same QuestionForm.
184 187
185 <QuestionForm xmlns="[the QuestionForm schema URL]"> 188 ::
186 <Overview> 189
190 <QuestionForm xmlns="[the QuestionForm schema URL]">
191 <Overview>
192 [...]
193 </Overview>
194 <Question>
195 [...]
196 </Question>
197 <Overview>
198 [...]
199 </Overview>
200 <Question>
201 [...]
202 </Question>
187 [...] 203 [...]
188 </Overview> 204 </QuestionForm>
189 <Question>
190 [...]
191 </Question>
192 <Overview>
193 [...]
194 </Overview>
195 <Question>
196 [...]
197 </Question>
198 [...]
199 </QuestionForm>
200 205
201 QuestionForm is implemented as a list, so to construct a 206 QuestionForm is implemented as a list, so to construct a
202 QuestionForm, simply append Questions and Overviews (with at least 207 QuestionForm, simply append Questions and Overviews (with at least
203 one Question). 208 one Question).
204 """ 209 """
205 schema_url = "http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchem as/2005-10-01/QuestionForm.xsd" 210 schema_url = "http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchem as/2005-10-01/QuestionForm.xsd"
206 xml_template = """<QuestionForm xmlns="%(schema_url)s">%%(items)s</QuestionF orm>""" % vars() 211 xml_template = """<QuestionForm xmlns="%(schema_url)s">%%(items)s</QuestionF orm>""" % vars()
207 212
208 def is_valid(self): 213 def is_valid(self):
209 return ( 214 return (
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 289
285 def get_as_xml(self): 290 def get_as_xml(self):
286 num_lines = self.num_lines 291 num_lines = self.num_lines
287 return self.template % vars() 292 return self.template % vars()
288 293
289 class FreeTextAnswer(object): 294 class FreeTextAnswer(object):
290 template = '<FreeTextAnswer>%(items)s</FreeTextAnswer>' 295 template = '<FreeTextAnswer>%(items)s</FreeTextAnswer>'
291 296
292 def __init__(self, default=None, constraints=None, num_lines=None): 297 def __init__(self, default=None, constraints=None, num_lines=None):
293 self.default = default 298 self.default = default
294 if constraints is None: constraints = Constraints() 299 if constraints is None:
295 self.constraints = Constraints(constraints) 300 self.constraints = Constraints()
301 else:
302 self.constraints = Constraints(constraints)
296 self.num_lines = num_lines 303 self.num_lines = num_lines
297 304
298 def get_as_xml(self): 305 def get_as_xml(self):
299 constraints = Constraints() 306 items = [self.constraints]
300 items = [constraints]
301 if self.default: 307 if self.default:
302 items.append(SimpleField('DefaultText', self.default)) 308 items.append(SimpleField('DefaultText', self.default))
303 if self.num_lines: 309 if self.num_lines:
304 items.append(NumberOfLinesSuggestion(self.num_lines)) 310 items.append(NumberOfLinesSuggestion(self.num_lines))
305 items = ''.join(item.get_as_xml() for item in items) 311 items = ''.join(item.get_as_xml() for item in items)
306 return self.template % vars() 312 return self.template % vars()
307 313
308 class FileUploadAnswer(object): 314 class FileUploadAnswer(object):
309 template = """<FileUploadAnswer><MinFileSizeInBytes>%(min_bytes)d</MinFileSi zeInBytes><MaxFileSizeInBytes>%(max_bytes)d</MaxFileSizeInBytes></FileUploadAnsw er>""" 315 template = """<FileUploadAnswer><MinFileSizeInBytes>%(min_bytes)d</MinFileSi zeInBytes><MaxFileSizeInBytes>%(max_bytes)d</MaxFileSizeInBytes></FileUploadAnsw er>"""
310 316
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 count_xml = SelectionAnswer.MIN_SELECTION_COUNT_XML_TEMPLATE %self.m in_selections 393 count_xml = SelectionAnswer.MIN_SELECTION_COUNT_XML_TEMPLATE %self.m in_selections
388 count_xml += SelectionAnswer.MAX_SELECTION_COUNT_XML_TEMPLATE %self. max_selections 394 count_xml += SelectionAnswer.MAX_SELECTION_COUNT_XML_TEMPLATE %self. max_selections
389 else: 395 else:
390 count_xml = "" 396 count_xml = ""
391 397
392 ret = SelectionAnswer.SELECTIONANSWER_XML_TEMPLATE % (count_xml, style_x ml, selections_xml) 398 ret = SelectionAnswer.SELECTIONANSWER_XML_TEMPLATE % (count_xml, style_x ml, selections_xml)
393 399
394 # return XML 400 # return XML
395 return ret 401 return ret
396 402
OLDNEW
« no previous file with comments | « boto/mturk/notification.py ('k') | boto/provider.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698