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


Python HTTPResponse.set_header方法代码示例

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


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

示例1: kml_index

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
    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,代码行数:62,代码来源:server.py

示例2: postTest

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
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,代码行数:9,代码来源:index.py

示例3: getTest

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
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,代码行数:10,代码来源:index.py

示例4: auth_fail

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
 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,代码行数:10,代码来源:kerberos.py

示例5: method_not_allowed

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
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,代码行数:10,代码来源:__main__.py

示例6: postTestJson

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
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,代码行数:11,代码来源:index.py

示例7: get_entries

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
def get_entries():
  # エントリーの一覧
  entries = []
  # エントリーの一覧をファイルから取得
  entries_file = config.get('alarm', 'entries_json_path')
  with open(entries_file, 'r') as f:
    entries = json.load(f)
  # JSONデータにして返却
  r = HTTPResponse(status=200, body=json.dumps(entries))
  r.set_header('Content-Type', 'application/json')
  return r
开发者ID:macole,项目名称:note,代码行数:13,代码来源:bottle_app.py

示例8: index

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
def index(data):
    data_array = numpy.array(data.split('_'),dtype=numpy.float)

    # 機械学習結果のモデルを読み込み
    clf = joblib.load('./clf/sample01.pkl')

    # 実行
    result = clf.predict([data_array])
    r = HTTPResponse(sattus=200, body = '<h1>%d</h1>' % result)
    r.set_header('Access-Control-Allow-Origin','*');
    return r
开发者ID:pukuman,项目名称:sample,代码行数:13,代码来源:websv.py

示例9: tapIf

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
def tapIf():
	var = request.json
	# print (var)
	tapNum = tap()
	retBody = {
		"ret": "ok",
		"tapNum": tapNum
	}
	r = HTTPResponse(status=200, body=retBody)
	r.set_header('Content-Type', 'application/json')
	return r
开发者ID:take-iwiw,项目名称:RaspberryPiControllerQtPython,代码行数:13,代码来源:index.py

示例10: rotaryEncoderIf

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
def rotaryEncoderIf():
	var = request.json
	# print (var)
	rotate = rotaryEncoder()
	retBody = {
		"ret": "ok",
		"rotate": rotate
	}
	r = HTTPResponse(status=200, body=retBody)
	r.set_header('Content-Type', 'application/json')
	return r
开发者ID:take-iwiw,项目名称:RaspberryPiControllerQtPython,代码行数:13,代码来源:index.py

示例11: buttonIf

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
def buttonIf():
	var = request.json
	# print (var)
	index = int(var["index"])
	onoff = button(index)
	retBody = {
		"ret": "ok",
		"onoff": "on" if onoff == True else "off"
	}
	r = HTTPResponse(status=200, body=retBody)
	r.set_header('Content-Type', 'application/json')
	return r
开发者ID:take-iwiw,项目名称:RaspberryPiControllerQtPython,代码行数:14,代码来源:index.py

示例12: GSensorIf

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
def GSensorIf():
	var = request.json
	# print (var)
	xyz = GSensor()
	retBody = {
		"ret": "ok",
		"x": xyz[0],
		"y": xyz[1],
		"z": xyz[2],
	}
	r = HTTPResponse(status=200, body=retBody)
	r.set_header('Content-Type', 'application/json')
	return r
开发者ID:take-iwiw,项目名称:RaspberryPiControllerQtPython,代码行数:15,代码来源:index.py

示例13: send_response

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
def send_response(code, message=None):
    r = HTTPResponse(status=code)
    r.add_header('Access-Control-Allow-Origin', '*')
    r.set_header('Content-Type', 'application/json')
    if message is None:
        r.set_header('Content-Type', 'text/plain')
    elif type(message) is str:
        e = {'error': message}
        r.body = json.dumps(e)
    elif type(message) is dict:
        r.body = json.dumps(message)
    else:
        r.body = message
    return r
开发者ID:nhurman,项目名称:Lorre,代码行数:16,代码来源:api.py

示例14: return_analysis_result

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
def return_analysis_result():
    """
    Example of analyzer API(GET)
    """
    # Get submitted contents.
    text = request.query.input_text
    # Analyze.
    _text = your_tool.lowercase(text)

    # Make a request.
    body = json.dumps(_text)
    r = HTTPResponse(status=200, body=body)
    r.set_header("Content-Type", "application/json")
    return r
开发者ID:kanjirz50,项目名称:web-nlp-interface,代码行数:16,代码来源:sample.py

示例15: open_image

# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import set_header [as 别名]
def open_image(file_path):
    image = Image.open(file_path)

    # カラーモードを変換する
    image = image.convert("RGBA")

    # 更新をbufferにpngで保存
    buf = StringIO()
    image.save(buf, "png")

    # bufferからレスポンス作成
    response = HTTPResponse(status=200, body=buf.getvalue())
    response.set_header("Content-type", "Image")
    return response
开发者ID:sharkattack51,项目名称:OpenImageProxy,代码行数:16,代码来源:OpenImageProxy.py


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