当前位置: 首页>>代码示例>>Python>>正文


Python bottle.HTTPResponse类代码示例

本文整理汇总了Python中bottle.HTTPResponse的典型用法代码示例。如果您正苦于以下问题:Python HTTPResponse类的具体用法?Python HTTPResponse怎么用?Python HTTPResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HTTPResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: default_error_handler

 def default_error_handler(error):
     if isinstance(error, HTTPError):
         r = HTTPResponse()
         error.apply(r)
         r.content_type = error.content_type
         return r
     return error
开发者ID:deti,项目名称:boss,代码行数:7,代码来源:view.py

示例2: patch

 def patch(self, id=None):
     if id:
         m = self.query().get(id)
         if m:
             for key, value in self.model.from_dict(request.json, self.db).items():
                 # if value being replaced is a model or list of models,
                 # delete it/them from the database first
                 if isinstance(value, list):
                     old = getattr(m, key)
                     newitems = [i for i in value if i not in old]
                     olditems = [i for i in old if i not in value]
                     for item in olditems:
                         old.remove(item)
                         if issubclass(type(item), Association):
                             self.db.delete(item)
                     for item in newitems:
                         old.append(item)
                 else:
                     setattr(m, key, value)
             self.db.commit()
             self.db.refresh(m)
             response = HTTPResponse(status=200, body=json.dumps(m.to_dict()))
             response.content_type = "application/json"
             return response
     abort(404)
开发者ID:wwu-housing,项目名称:schedule,代码行数:25,代码来源:routes.py

示例3: get_response_from_exception

def get_response_from_exception(excep, exception_mapping):
    status = exception_mapping.get(excep.__class__, None)
    if status is None:
        status = 500
    ret = HTTPResponse(status=status, body=str(excep))
    ret.add_header("Content-Type", "text/plain")
    return ret
开发者ID:19317362,项目名称:conan,代码行数:7,代码来源:return_handler.py

示例4: kml_index

    def kml_index(self):
        session = self.beaker
        print 'kml_index'
        err, suc = [], []
        kml_layer_name = ''
        with self.session() as s:
            try:
                if request.method == 'POST':
                    csrf = request.params.get('csrf', '')
                    if session.get('csrf', '') != csrf:
                        print 'csrf token mismatch'
                        r = HTTPResponse(status=302)
                        r.set_header('Location: /kml/')
                        raise r

                    print 'method = POST'
                    name = request.params.get('name', '')
                    name = name.decode('utf-8')
                    upload = request.files.get('kml_file', '')
                    if not name:
                        err.append(u'KMLレイヤーの名前を入力してください')
                    else:
                        kml_layer_name = name

                    if not upload:
                        err.append(u'ファイルがアップロードされていません')

                    if not err:
                        tmp_fname = '/tmp/minarepo_kml_%s' % random_str(40)
                        upload.save(tmp_fname)
                        try:
                            with open(tmp_fname, 'rb') as fh:
                                fdata = fh.read()

                            geo_layer = GeoLayer(
                                name=name,
                                content=fdata,
                                file_size=len(fdata)
                            )
                            s.add(geo_layer)
                        finally:
                            os.remove(tmp_fname)

                    suc.append(u'KMLレイヤーを作成しました: %s' % name)
                    kml_layer_name = ''

                layers = s.query(GeoLayer).order_by(GeoLayer.created.desc())
                layers = [ l.to_api_dict() for l in layers ]

            except:
                s.rollback()
                raise
            else:
                s.commit()
                print 'commited'

        session['csrf'] = random_str(100)

        return self._render('kml.html.j2', err=err, suc=suc,
            layers=layers, kml_layer_name=kml_layer_name, session=self.beaker)
开发者ID:htlab,项目名称:minarepo-web-viewer,代码行数:60,代码来源:server.py

示例5: postTest

def postTest():
	var1 = request.forms.get('prm1')
	var2 = request.forms.get('prm2')
	retBody = 'Hello Post ' + var1 + ', ' + var2
	r = HTTPResponse(status=200, body=retBody)
	r.set_header('Content-Type', 'text/html')
	return r
开发者ID:take-iwiw,项目名称:PythonBottleBasic,代码行数:7,代码来源:index.py

示例6: method_not_allowed

def method_not_allowed(res):
    if request.method == 'OPTIONS':
        new_res = HTTPResponse()
        new_res.set_header('Access-Control-Allow-Origin', '*')
        new_res.set_header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE')
        return new_res
    res.headers['Allow'] += ', OPTIONS'
    return request.app.default_error_handler(res)
开发者ID:fabiand,项目名称:k8s-start,代码行数:8,代码来源:__main__.py

示例7: auth_fail

 def auth_fail(self, gss_context=None):
   resp = HTTPResponse(self._fail_response, status=401)
   resp.set_header('Content-Type', self._content_type)
   resp.set_header(
     'WWW-Authenticate',
     'Negotiate' + (' ' + gss_context if gss_context else '')
   )
   return resp
开发者ID:CodeWarltz,项目名称:commons,代码行数:8,代码来源:kerberos.py

示例8: getTest

def getTest():
	print request
	var1 = request.query.prm1
	var2 = request.query.prm2
	retBody = 'Hello Get ' + var1 + ', ' + var2
	r = HTTPResponse(status=200, body=retBody)
	r.set_header('Content-Type', 'text/html')
	return r
开发者ID:take-iwiw,项目名称:PythonBottleBasic,代码行数:8,代码来源:index.py

示例9: apikeyNotValid

def apikeyNotValid():
    response = HTTPResponse()
    response.status = 200
    response.body = json.dumps(
        {
            'message': 'api key not valid',
        }
    ) + "\n"
    return response
开发者ID:nasa9084,项目名称:charakoba_fault_info,代码行数:9,代码来源:api.py

示例10: method_not_allowed

def method_not_allowed(res):
    if request.method == 'OPTIONS':
        new_res = HTTPResponse()
        new_res.headers['Access-Control-Allow-Origin'] = '*'
        new_res.headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, PUT'
        new_res.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept'
        return new_res
    res.headers['Allow'] += ', OPTIONS'
    return request.app.default_error_handler(res)
开发者ID:phylotastic,项目名称:phylo_webservices,代码行数:9,代码来源:webapi.py

示例11: success

def success():
    response = HTTPResponse()
    response.status = 200
    response.body = json.dumps(
        {
            'message': 'Success'
        }
    ) + "\n"
    return response
开发者ID:nasa9084,项目名称:charakoba_fault_info,代码行数:9,代码来源:api.py

示例12: postTestJson

def postTestJson():
	var = request.json
	retBody = {
		"ret": "ok",
		"retPrm": "XX " + var["prm1"] + var["prm2"],
	}
	r = HTTPResponse(status=200, body=retBody)
	r.set_header('Content-Type', 'application/json')
	return r
开发者ID:take-iwiw,项目名称:PythonBottleBasic,代码行数:9,代码来源:index.py

示例13: get

 def get(self, id=None):
     if id:
         match = self.query().get(id).to_dict()
         if match:
             return json.dumps(match)
         abort(404)
     else:
         response = HTTPResponse(status=200, body=json.dumps([m.to_dict() for m in self.query().all()]))
         response.content_type = "application/json"
         return response
开发者ID:wwu-housing,项目名称:schedule,代码行数:10,代码来源:routes.py

示例14: make_error

def make_error(message):
    formats = {
        'json': 'application/json',
        'xml': 'application/xml',
        'jsonp': 'application/javascript',
    }
    format_ = bottle.request.query.get('format', 'json')
    response = HTTPResponse(status=message, content_type=formats[format_])
    response.headers['Access-Control-Allow-Origin'] = '*'
    return response
开发者ID:ederfranco23,项目名称:postmon,代码行数:10,代码来源:PostmonServer.py

示例15: cannotTweet

def cannotTweet():
    response = HTTPResponse()
    response.status = 500
    response.body = json.dumps(
        {
            'message': 'Failed',
            'Error': 'CannotTweet'
        }
    ) + "\n"
    return response
开发者ID:nasa9084,项目名称:charakoba_fault_info,代码行数:10,代码来源:api.py


注:本文中的bottle.HTTPResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。