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


Python Response.text方法代码示例

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


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

示例1: update_path

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
    def update_path(self, id_doc, path, value):
        """
        Update base in proposed path
        """
        response = Response(content_type='application/json')
        url = self.lbgenerator_rest_url + '/' + self.lbbase.metadata.name + '/doc/' + id_doc
        url = url + '/' + path
        params = {
            'value': value
        }

        result = requests.put(
            url=url,
            data=params
        )

        if result.status_code >= 300:
            response.status_code = 500
            response.text = result.text

            return response

        response.status_code = 200
        response.text = result

        return response
开发者ID:lightbase,项目名称:LBSociam,代码行数:28,代码来源:crimes.py

示例2: api

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
def api(request):
    try:
        # Parse the request
        params = _parse_request(request)

        # Remove auth stuff
        del params["sid"]
        del params["token"]

        # Perform the lookup
        lookdown_result = _lookdown(VENDORS, **params)
        if lookdown_result is None:
            response = "[]"
        else:
            response = {"data": lookdown_result}

        result = Response(json.dumps(response))

    except HTTPException as exc:
        result = exc
        result.text = exc.detail

    except:
        log.error("Server Error", exc_info=True)
        result = Response("Server error", status=500)

    result.content_type = "application/json"
    return result
开发者ID:jrudder,项目名称:phone-lookup,代码行数:30,代码来源:server.py

示例3: get_reporting_instance_usage_file

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
 def get_reporting_instance_usage_file(self):
     conn = self.get_connection(conn_type='ec2reports')
     if not self.is_csrf_valid():
         return JSONResponse(status=400, message="missing CSRF token")
     granularity = self.request.params.get('granularity')
     group_by = self.request.params.get('groupBy')
     dates = self.dates_from_params(self.request.params)
     filters = self.request.params.get('filters') or '[]'
     filters = json.loads(filters)
     with boto_error_handler(self.request):
         # use "ViewInstanceUsageReport" call to fetch usage information
         ret = conn.view_instance_usage_report(
             dates.from_date, dates.to_date, filters, group_by, report_granularity=granularity
         )
         filename = 'EucalyptusInstanceUsage-{0}-{1}-{2}.csv'.format(
             self.request.session.get('account'),
             dates.from_date,
             dates.to_date
         )
         response = Response(content_type='text/csv')
         response.text = ret.get('usageReport')
         response.content_disposition = 'attachment; filename="{name}"'.format(name=filename)
         response.cache_control = 'no-store'
         response.pragma = 'no-cache'
         return response
开发者ID:,项目名称:,代码行数:27,代码来源:

示例4: inline_edit

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
def inline_edit(request):
    print(request.POST)
    pk = int(request.POST.get("pk"))
    name = request.POST.get("name")
    value = request.POST.get("value")

    name_to_be_edited = names.get(pk)

    form = NameForm(obj=name_to_be_edited)
    field = getattr(form, name)
    field.process_formdata([value])  # change the value of the field

    if form.validate():  # the change was good!
        setattr(name_to_be_edited, name, value)
        # session.commit()  # in ORM you'd commit the change!
        response = Response()
        return response  # 200 OK tells X-Editable everything worked
    else:  # change was bad!
        # Since validation failed, no change is made!
        response = Response()
        response.status_int = 422  # Unprocessable Entity is most-correct
        errors = []
        for error_key in form.errors.keys():
            errors.extend(map(lambda x: error_key + x, form.errors[error_key]))
        response.text = "\n".join(errors)
        return response
开发者ID:MaxwellGBrown,项目名称:notebook,代码行数:28,代码来源:views.py

示例5: response

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
    def response(self, request, error):
        """
            Render an API Response

            Create a Response object, similar to the JSONP renderer
            [TODO: re-factor in to the JSONP renderer]
            Return the Response object with the appropriate error code
        """

        jsonp_render = request.registry._jsonp_render

        default = jsonp_render._make_default(request)
        val = self.serializer(self.envelope(success=False, error=error.error),
                              default=default,
                              **jsonp_render.kw)
        callback = request.GET.get(jsonp_render.param_name)
        response = Response("", status=200)  # API Error code is always 200

        if callback is None:
            ct = 'application/json'
            response.status = error.code
            response.body = val
        else:
            ct = 'application/javascript'
            response.text = '%s(%s)' % (callback, val)

        if response.content_type == response.default_content_type:
            response.content_type = ct
        return response
开发者ID:mattjeffery,项目名称:hairy-octo-bear,代码行数:31,代码来源:wrapper.py

示例6: state_post

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
def state_post(context, request):
    id = request.matchdict["id"]
    object_type = request.POST.get('type', 'string')
    operation_type = request.POST.get("op", "set")
    
    parameters = {}
    for k, v in request.POST.iteritems():
        if k not in ["op", "type"]:
            parameters[k] = v
            
    # Create redis client
    client = redisconnect.connect()

    # Create top level         
    st = state.State("user", client)

    obj = st.get_or_create(id, object_type)
        
    obj.op(operation_type, **parameters)
        
    resp = Response()
    resp.content_type = "text/plain"
    resp.text = u"OK"
    # return the old value of the key
    return resp
开发者ID:Faqer,项目名称:jarvis,代码行数:27,代码来源:views.py

示例7: find_entities

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
    def find_entities(self):
        #page_limit, current_page, start, end = self._get_pagin_data()
        user = get_current()
        dace_catalog = find_catalog('dace')
        system_catalog = find_catalog('system')
        novaideo_catalog = find_catalog('novaideo')
        filter_schema = FindEntitiesJson(self.context, self.request)
        try:
            appstruct = filter_schema.calculate_posted_filter()
        except Exception as e:
            return {'items': [], 'total_count': 0, 'error': True,
                    'message': '{}: {}'.format(
                            e.__class__.__name__, e.args[0])}

        if appstruct is None:
            return {'items': [], 'total_count': 0, 'error': True,
                    'message': 'appstruct is None'}

        content_types_tree = appstruct['metadata_filter'].get('content_types', {}).copy()
        content_types = list(content_types_tree.keys())
        appstruct['metadata_filter'] = appstruct.get('metadata_filter', {})
        appstruct['metadata_filter']['content_types'] = content_types
        appstruct['dace'] = dace_catalog
        appstruct['system'] = system_catalog
        appstruct['novaideo'] = novaideo_catalog
        entities = find_entities(
            user=user, sort_on='release_date', include_site=True, **appstruct)

        def dumps(obj):
            """return values of attributes descibed in
               the colander schema node 'node' """
            registry = get_current_registry()
            content_type = registry.content.typeof(obj)
            fields = content_types_tree.get(content_type, {})
            result, to_add = get_obj_value(obj, fields)
            if result is None:
                return {}, to_add

            return result, to_add

        def merge_items(old_items, new_items):
            for item in new_items:
                oid = item.get('@id', None)
                if oid and oid not in old_items:
                    old_items[oid] = item
                elif oid:
                    old_item = old_items[oid]
                    old_items[oid] = merge_dicts([item, old_item])

        items = {}
        for entity in entities:
            values, to_add = dumps(entity)
            to_add.append(values)
            merge_items(items, to_add)

        result = {'items': list(items.values()), 'total_count': len(items)}
        response = Response()
        response.content_type = "application/json"
        response.text = json.dumps(result, indent=2)
        return response
开发者ID:ecreall,项目名称:nova-ideo,代码行数:62,代码来源:export_entities.py

示例8: job_preset

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
def job_preset(request):
    id = request.matchdict['job']
    session = DBSession()
    job = session.query(Job).get(id)
    response = Response()
    response.text = job.josm_preset
    response.content_disposition = 'attachment; filename=hotosm_tasking_manager_job_%s.xml' % job.id
    response.content_type = 'application/x-josm-preset'
    return response
开发者ID:Bulathge,项目名称:osm-tasking-manager,代码行数:11,代码来源:jobs.py

示例9: probe_status_view

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
def probe_status_view(request):
    response = Response("OK")
    response.content_type = 'text/plain'
    try:
        DBSession.execute('select name from sys.cluster')
    except sqlalchemy.exc.DBAPIError as e:
        response.status = 503
        response.text = 'DBFailure {}'.format(e)
    return response
开发者ID:dobe,项目名称:ep2014tutorial,代码行数:11,代码来源:views.py

示例10: remove_file

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
    def remove_file(self, id_doc, id_file):
        """
        Remove image from base
        """
        # First gets document
        document = self.get_document(id_doc)

        # Now create a new image dict removing selected files
        new_image = list()
        for image in document.get('images'):
            if image['id_file'] != id_file:
                new_image.append(image)

        # Finally update document and submit it back to base
        document['images'] = new_image

        response = Response(content_type='application/json')
        try:
            log.debug(document)
            result = self.update_document(id_doc, document)
        except HTTPError as e:

            response.status_code = 500
            response.text = e.message

            return response

        # TODO: Not yet implemented. Need fix
        # Now remove file from database
        #url = self.lbgenerator_rest_url + '/' + self.lbbase._metadata.name + '/' + id_file
        #result = requests.delete(
        #    url=url
        #)
        #if result.status_code >= 300:
        #    response.status_code = result.status_code
        #    response.text = result.text

        #    return response

        response.status_code = 200
        response.text = result

        return response
开发者ID:lightbase,项目名称:LBSociam,代码行数:45,代码来源:crimes.py

示例11: logout

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
def logout(request):
    """ Logout user throw him out
    """
    if request.session.get('email'):
        del request.session['email']
    headers = forget(request)
    response = Response()
    response.headerlist.extend(headers)
    response.text = "logged out "
    return response
开发者ID:jysandy,项目名称:chestify,代码行数:12,代码来源:views.py

示例12: view_export_locations

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
def view_export_locations(request):
    contents = ""
    for location in DBSession.query(ShippingLocation).all():
        contents += location.name + ';' + location.address + '\n'

    resp = Response()
    resp.charset = "utf-8"
    resp.text = contents
    resp.headerlist.append(("Content-Disposition", "attachment"))
    return resp
开发者ID:varesa,项目名称:shopify_shipping_calculator,代码行数:12,代码来源:views_data_locations.py

示例13: return_plain_data

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
def return_plain_data(content):

    response = Response(content_type='application/html')
    headers = response.headers
    if not response.charset:
        response.charset = 'utf8'
    response.text = content
    headers['Content-Type'] = 'text/plain'

    return response
开发者ID:yeastgenome,项目名称:SGDFrontend,代码行数:12,代码来源:__init__.py

示例14: set_download_file

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
def set_download_file(filename, content):
    
    response = Response(content_type='application/file')
    headers = response.headers
    if not response.charset:
        response.charset = 'utf8'
    response.text = content
    headers['Content-Type'] = 'text/plain'
    headers['Content-Disposition'] = str('attachment; filename=' + '"' + filename + '"')
    headers['Content-Description'] = 'File Transfer'
    return response
开发者ID:yeastgenome,项目名称:SGDFrontend,代码行数:13,代码来源:__init__.py

示例15: template

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import text [as 别名]
 def template(self, template, content_type='text/html', backup='../../', status=None, theme=''):
     """ Template renderer for dynamic themes """
     try:
         self.determine_instance(theme)
         response  = Response(content_type=content_type, status=status)
         response.text = render(backup + 'themes/' + self.response['instance_id'] + '/' + self.theme + '/templates/' + template, self.response, self.request)
         return response
     except Exception as e:
         print "ERROR: " + str(e)
         raise HTTPForbidden()
         
开发者ID:polklibrary,项目名称:quizsmith,代码行数:12,代码来源:__init__.py


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