本文整理汇总了Python中webob.exc.HTTPBadRequest.content_type方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPBadRequest.content_type方法的具体用法?Python HTTPBadRequest.content_type怎么用?Python HTTPBadRequest.content_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webob.exc.HTTPBadRequest
的用法示例。
在下文中一共展示了HTTPBadRequest.content_type方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HEAD
# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import content_type [as 别名]
def HEAD(self, request):
"""Handle HTTP HEAD requests for the Swift Object Server."""
try:
device, partition, account, container, obj = \
split_path(unquote(request.path), 5, 5, True)
except ValueError, err:
resp = HTTPBadRequest(request=request)
resp.content_type = 'text/plain'
resp.body = str(err)
return resp
示例2: HEAD
# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import content_type [as 别名]
def HEAD(self, request):
"""Handle HTTP HEAD requests for the Swift Object Server."""
start_time = time.time()
try:
device, partition, account, container, obj = split_path(unquote(request.path), 5, 5, True)
validate_device_partition(device, partition)
except ValueError, err:
self.logger.increment("HEAD.errors")
resp = HTTPBadRequest(request=request)
resp.content_type = "text/plain"
resp.body = str(err)
return resp
示例3: __call__
# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import content_type [as 别名]
def __call__(self, environ, start_response):
req = Request(environ)
env = Environment(loader=FileSystemLoader('.'))
amz_dict = {'workerId' : '', 'assignmentId' : '', 'hitId' : ''}
templ, part, listid, template, resp = [None for x in range(5)]
required_keys = ['workerId', 'assignmentId', 'hitId', 'part']
key_error_msg = 'Missing parameter: {0}. Required keys: {1}'
try:
amz_dict['workerId'] = req.params['workerId']
amz_dict['assignmentId'] = req.params['assignmentId']
amz_dict['hitId'] = req.params['hitId']
part = int(req.params['part'])
except KeyError as e:
resp = HTTPBadRequest(key_error_msg.format(e, required_keys))
return resp(environ, start_response)
if amz_dict['assignmentId'] == 'ASSIGNMENT_ID_NOT_AVAILABLE':
template = env.get_template('preview.html')
template = template.render(part = part)
else:
worker = check_worker_exists(amz_dict['workerId'])
if worker:
forbidden_msg = '<p style="font-weight: bold; font-size: x-large;">{0}</p>'
if part in (2,3):
try:
sess = SessionState.query.filter_by(worker=worker).one()
if part == 2:
if not sess.sess1complete:
resp = HTTPForbidden(forbidden_msg.format('You must do part 1 before part 2!'))
else:
sess.sess2complete = True
sess.sess2timestamp = datetime.now()
session.commit() # important! w/o this it won't save them
if part == 3:
if not sess.sess2complete:
resp = HTTPForbidden(body_template=forbidden_msg.format('You must do part 2 before part 3!'))
if not worker.trialgroup.now:
start_time = sess.sess2timestamp + timedelta(days=2)
if datetime.now() < start_time:
resp = HTTPForbidden(forbidden_msg('You must wait at least 2 days before doing part 3!'))
if not resp:
sess.sess3complete = True
sess.sess4timestamp = datetime.now()
session.commit() # important! w/o this it won't save them
except NoResultFound:
resp = HTTPForbidden(forbidden_msg.format('Attempting to do part {0} without having done part 1!'.format(part)))
else:
if part == 1:
worker = Worker(workerid = amz_dict['workerId'], trialgroup = random_lowest_list())
SessionState(sess1complete = True, worker = worker)
session.commit() # important! w/o this it won't save them
else:
# If part is anything but 1 and there's no worker defined,
# then something is horribly wrong
resp = HTTPForbidden(forbidden_msg.format('Attempting to do part {0} without having done part 1!'.format(part)))
if not resp:
sesslist = {1 : worker.trialgroup.sess1list,
2 : worker.trialgroup.sess2list,
3 : worker.trialgroup.sess3list}[part]
if part in (1,3):
template = env.get_template('flash_experiment.html')
else:
template = env.get_template('spr_experiment.html')
template = template.render(part = part, list = sesslist, now=worker.trialgroup.now, amz_dict = amz_dict)
if template and not resp:
resp = Response()
resp.content_type='application/xhtml+xml'
resp.unicode_body = template
return resp(environ, start_response)
示例4: __call__
# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import content_type [as 别名]
def __call__(self, environ, start_response):
# SQLAlchemy boilerplate code to connect to db and connect models to db objects
engine = create_engine(engine_string)
Session = sessionmaker(bind=engine)
session = Session()
req = Request(environ)
if req.method != 'POST':
resp = HTTPBadRequest('This page can only be accesses via POST')
return resp(environ, start_response)
else:
firstname = req.POST['firstname']
lastname = req.POST['lastname']
subj = Subject(firstname=firstname, lastname=lastname)
to_add = {}
for k in ('amerind', 'afram', 'pacif', 'asian', 'white',
'unknown', 'ur_student', 'hearing_normal', 'more_expts'):
if req.POST.has_key(k):
to_add[k] = True
for k in ('sex', 'ethnicity', 'other_race', 'gradyear',
'hearing_problems', 'vision_normal', 'vision_other'):
if req.POST.has_key(k):
if req.POST[k] not in (None, '', u''):
to_add[k] = req.POST[k]
if req.POST.has_key('age'):
if req.POST['age'] not in (None, ''):
to_add['age'] = int(req.POST['age'])
if req.POST['entrydate'] not in (None, '', u''):
to_add['entrydate'] = parser.parse(req.POST['entrydate']).date()
else:
to_add['entrydate'] = date.today()
subj.from_dict(to_add)
try:
session.add(subj)
session.commit()
except IntegrityError as e:
resp = HTTPBadRequest(e)
return resp(environ, start_response)
if req.POST.has_key('phone'):
if req.POST['phone'] not in (None, '', u''):
p = Phone(subject = subj, number = req.POST['phone'])
session.add(p)
session.commit()
if req.POST.has_key('email'):
if req.POST['email'] not in (None, '', u''):
em = Email(subject = subj, address = req.POST['email'])
session.add(em)
session.commit()
from pprint import pformat
#output = pformat(subj.to_dict(deep={'phone': {}, 'email': {}}))
env = Environment(loader=FileSystemLoader(os.path.join(basepath,'templates')))
template = env.get_template('subject_list.html')
template = template.render(subjects = [subj.to_dict(deep={'phone': {}, 'email': {}}),])
resp = Response()
resp.content_type='text/html'
resp.unicode_body = template
#resp.content_type='text/plain'
#resp.body = output
return resp(environ, start_response)