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


Python client.CONTENT_TYPE_RE类代码示例

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


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

示例1: post

    def post(self, path, data={}, content_type=MULTIPART_CONTENT,
             **extra):
        "Construct a POST request."

        if content_type is MULTIPART_CONTENT:
            post_data = encode_multipart(BOUNDARY, data)
        else:
            # Encode the content so that the byte representation is correct.
            match = CONTENT_TYPE_RE.match(content_type)
            if match:
                charset = match.group(1)
            else:
                charset = settings.DEFAULT_CHARSET
            post_data = smart_str(data, encoding=charset)

        parsed = urlparse(path)
        r = {
            'CONTENT_LENGTH': len(post_data),
            'CONTENT_TYPE':   content_type,
            'PATH_INFO':      self._get_path(parsed),
            'QUERY_STRING':   parsed[4],
            'REQUEST_METHOD': 'POST',
            'wsgi.input':     FakePayload(post_data),
        }
        r.update(extra)
        return self.request(**r)
开发者ID:Diviei,项目名称:django-subdomains,代码行数:26,代码来源:requestfactory.py

示例2: put

def put(self, path, data={}, content_type=MULTIPART_CONTENT,
         follow=False, **extra):
    """
    Requests a response from the server using POST.
    """
    if content_type is MULTIPART_CONTENT:
        post_data = encode_multipart(BOUNDARY, data)
    else:
        # Encode the content so that the byte representation is correct.
        match = CONTENT_TYPE_RE.match(content_type)
        if match:
            charset = match.group(1)
        else:
            charset = settings.DEFAULT_CHARSET
        post_data = smart_str(data, encoding=charset)

    parsed = urlparse(path)
    r = {
        'CONTENT_LENGTH': len(post_data),
        'CONTENT_TYPE':   content_type,
        'PATH_INFO':      urllib.unquote(parsed[2]),
        'QUERY_STRING':   parsed[4],
        'REQUEST_METHOD': 'PUT',
        'wsgi.input':     FakePayload(post_data),
    }
    r.update(extra)

    response = self.request(**r)
    if follow:
        response = self._handle_redirects(response)
    return response
开发者ID:sproutcoreisyournewbicycle,项目名称:django-spoutcore,代码行数:31,代码来源:tests.py

示例3: return_text_file

def return_text_file(request):
    "A view that parses and returns text as a file."
    match = CONTENT_TYPE_RE.match(request.META['CONTENT_TYPE'])
    if match:
        charset = match.group(1)
    else:
        charset = settings.DEFAULT_CHARSET

    return HttpResponse(request.body, status=200, content_type='text/plain; charset=%s' % charset)
开发者ID:MattBlack85,项目名称:django,代码行数:9,代码来源:views.py

示例4: _encode_data

 def _encode_data(self, data, content_type, ):
     if content_type is MULTIPART_CONTENT:
         return encode_multipart(BOUNDARY, data)
     else:
         # Encode the content so that the byte representation is correct.
         match = CONTENT_TYPE_RE.match(content_type)
         if match:
             charset = match.group(1)
         else:
             charset = settings.DEFAULT_CHARSET
         return smart_str(data, encoding=charset)
开发者ID:kidosoft,项目名称:django-smarttest,代码行数:11,代码来源:compat.py

示例5: return_json_file

def return_json_file(request):
    "A view that parses and returns a JSON string as a file."
    match = CONTENT_TYPE_RE.match(request.META["CONTENT_TYPE"])
    if match:
        charset = match.group(1)
    else:
        charset = settings.DEFAULT_CHARSET

    # This just checks that the uploaded data is JSON
    obj_dict = json.loads(request.body.decode(charset))
    obj_json = json.dumps(obj_dict, cls=DjangoJSONEncoder, ensure_ascii=False)
    response = HttpResponse(obj_json.encode(charset), status=200, content_type="application/json; charset=%s" % charset)
    response["Content-Disposition"] = "attachment; filename=testfile.json"
    return response
开发者ID:isotoma,项目名称:django,代码行数:14,代码来源:views.py

示例6: return_json_file

def return_json_file(request, default_charset='utf-8'):
    "A view that parses and returns a JSON string as a file."
    match = CONTENT_TYPE_RE.match(request.META['CONTENT_TYPE'])
    if match:
        charset = match.group(1)
    else:
        charset = default_charset

    # This just checks that the uploaded data is JSON
    obj_dict = json.loads(request.body.decode(charset))
    obj_json = json.dumps(obj_dict, cls=DjangoJSONEncoder, ensure_ascii=False)
    response = HttpResponse(obj_json.encode(charset), status=200,
                            content_type='application/json; charset=%s' % charset)
    response['Content-Disposition'] = 'attachment; filename=testfile.json'
    return response
开发者ID:SlashRoot,项目名称:django,代码行数:15,代码来源:views.py

示例7: return_json_file

def return_json_file(request):
    "A view that parses and returns a JSON string as a file."
    match = CONTENT_TYPE_RE.match(request.META['CONTENT_TYPE'])
    if match:
        charset = match.group(1)
    else:
        charset = settings.DEFAULT_CHARSET

    # This just checks that the uploaded data is JSON
    obj_dict = simplejson.loads(request.raw_post_data.decode(charset))
    obj_json = simplejson.dumps(obj_dict, encoding=charset,
                                cls=DjangoJSONEncoder,
                                ensure_ascii=False)
    response = HttpResponse(smart_str(obj_json, encoding=charset), status=200,
                            mimetype='application/json; charset=' + charset)
    response['Content-Disposition'] = 'attachment; filename=testfile.json'
    return response
开发者ID:BillyWu,项目名称:django,代码行数:17,代码来源:views.py

示例8: endpoint

def endpoint(request):
    if request.method != 'POST':
        return HttpResponseBadRequest()

    match = CONTENT_TYPE_RE.match(request.META['CONTENT_TYPE'])
    if match:
        charset = match.group(1)
    else:
        charset = settings.DEFAULT_CHARSET

    data = json.loads(request.body.decode(charset))
    run_actions(request, data)

    result = {}
    for (namespace, render) in achilles_renders().items():
        result[namespace] = render(request)

    return HttpResponse(json.dumps(result), content_type="application/json")
开发者ID:blaxter,项目名称:django-achilles,代码行数:18,代码来源:views.py


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