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


Python Response.content_type_params方法代码示例

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


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

示例1: xls_response

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import content_type_params [as 别名]
def xls_response(rows, encoding='ISO-8859-1', filename='response.xls', num_formats=(), col_widths=()):
    """Creates a downloadable webob.Response instance with the given row data
    as an XLS (Excel) file.

    :param rows: The spreadsheet data as rows.
    :type rows: iterable

    :param encoding: The character encoding for the data in the spreadsheet.
    :type encoding: str

    :param filename: The suggested filename for the user to save the file as.
    :type filename: str

    :param num_formats: A tuple of Excel format strings for numeric values.
    :type num_formats: tuple
    """
    stream = StringIO()

    wb = xlwt.Workbook(encoding=encoding)
    ws = wb.add_sheet('Nuorisovaalit 2011')

    # Compile the style objects
    styles = []
    for fmt in num_formats:
        if fmt is None:
            styles.append(None)
        else:
            styles.append(xlwt.easyxf(num_format_str=fmt))

    # Set column formatting styles.
    if len(rows) > 0 and len(num_formats) == len(rows[0]):
        for c in xrange(len(rows[0])):
            if styles[c] is not None:
                ws.col(c).set_style(styles[c])

    # Set column widths.
    if len(rows) > 0 and len(col_widths) == len(rows[0]):
        for c in xrange(len(rows[0])):
            if col_widths[c] is not None:
                ws.col(c).width = col_widths[c]

    for r, row in enumerate(rows):
        for c, item in enumerate(row):
            if len(styles) == len(row) and styles[c] is not None:
                ws.write(r, c, item, styles[c])
            else:
                ws.write(r, c, item)

    wb.save(stream)

    response = Response()
    response.body = stream.getvalue()
    stream.close()

    # Set Response headers.
    response.content_type = 'application/vnd.ms-excel'
    response.content_type_params = {}
    response.content_disposition = 'attachment; filename={0}'.format(filename)

    return response
开发者ID:verkkodemokratiaseura,项目名称:verkkovaali,代码行数:62,代码来源:school.py

示例2: send_legacy_result

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import content_type_params [as 别名]
def send_legacy_result(code, headers):
    resp = Response()
    if 'content-type' not in headers:
        headers['content-type'] = "text/plain"

    resp.headers = headers
    resp.status = code
    if code > 399:
        return resp

    resp.content_type_params = {'charset': 'UTF-8'}

    return resp
开发者ID:Cerberus98,项目名称:keystone,代码行数:15,代码来源:utils.py

示例3: send_error

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import content_type_params [as 别名]
def send_error(code, req, result):
    content = None

    resp = Response()
    resp.headers['content-type'] = None
    resp.status = code

    if result:
        if is_xml_response(req):
            content = result.to_xml()
            resp.headers['content-type'] = "application/xml"
        else:
            content = result.to_json()
            resp.headers['content-type'] = "application/json"

        resp.content_type_params = {'charset': 'UTF-8'}
        resp.unicode_body = content.decode('UTF-8')

    return resp
开发者ID:Cerberus98,项目名称:keystone,代码行数:21,代码来源:utils.py

示例4: send_error

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import content_type_params [as 别名]
def send_error(code, req, result):
    content = None

    resp = Response()
    resp.headers["content-type"] = None
    resp.headers["Vary"] = "X-Auth-Token"
    resp.status = code

    if result:
        if is_xml_response(req):
            content = result.to_xml()
            resp.headers["content-type"] = "application/xml"
        else:
            content = result.to_json()
            resp.headers["content-type"] = "application/json"

        resp.content_type_params = {"charset": "UTF-8"}
        resp.unicode_body = content.decode("UTF-8")

    return resp
开发者ID:kayyagari,项目名称:keystone,代码行数:22,代码来源:utils.py

示例5: xls_response_multiple

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import content_type_params [as 别名]
def xls_response_multiple(sheets, encoding='ISO-8859-1', filename='response.xls', num_formats=(), col_widths=()):
    """Creates a downloadable webob.Response instance with the given row data
    as an XLS (Excel) file.

    :param sheets: The spreadsheet data as an iterable of (sheet_name,
                   rows) tuples with the row data of a sheet in the
                   rows iterable.
    :type sheets: iterable

    :param encoding: The character encoding for the data in the spreadsheet.
    :type encoding: str

    :param filename: The suggested filename for the user to save the file as.
    :type filename: str

    :param num_formats: A tuple of Excel format strings for numeric values.
    :type num_formats: tuple
    """
    wb = xlwt.Workbook(encoding=encoding)

    # Compile the style objects
    styles = []
    for fmt in num_formats:
        if fmt is None:
            styles.append(None)
        else:
            styles.append(xlwt.easyxf(num_format_str=fmt))

    if not sheets:
        wb.add_sheet(u'Tyhjä taulukko')

    for sheet_name, rows in sheets:

        # Worksheet name must not be longer than 31 characters.
        if len(sheet_name) > 31:
            sheet_name = sheet_name[:31]

        # Create a new sheet and write to it.
        ws = wb.add_sheet(sheet_name)

        # Set column widths.
        if len(rows) > 0 and len(col_widths) == len(rows[0]):
            for c in xrange(len(rows[0])):
                if col_widths[c] is not None:
                    ws.col(c).width = col_widths[c]

        for r, row in enumerate(rows):
            for c, item in enumerate(row):
                if len(styles) == len(row) and styles[c] is not None:
                    ws.write(r, c, item, styles[c])
                else:
                    ws.write(r, c, item)

    stream = StringIO()
    wb.save(stream)

    response = Response()
    response.body = stream.getvalue()
    stream.close()

    # Set Response headers.
    response.content_type = 'application/vnd.ms-excel'
    response.content_type_params = {}
    response.content_disposition = 'attachment; filename={0}'.format(filename)

    return response
开发者ID:verkkodemokratiaseura,项目名称:verkkovaali,代码行数:68,代码来源:school.py

示例6: test_content_type_params_set_ok_param_quoting

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import content_type_params [as 别名]
def test_content_type_params_set_ok_param_quoting():
    res = Response()
    res.content_type_params = {'a':''}
    eq_(res.headers['Content-Type'], 'text/html; a=""')
开发者ID:GdZ,项目名称:scriptfile,代码行数:6,代码来源:test_response.py

示例7: test_content_type_params_set_value_dict_empty

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import content_type_params [as 别名]
def test_content_type_params_set_value_dict_empty():
    res = Response()
    res.headers['Content-Type'] = 'foo;bar'
    res.content_type_params = None
    eq_(res.headers['Content-Type'], 'foo')
开发者ID:GdZ,项目名称:scriptfile,代码行数:7,代码来源:test_response.py


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