當前位置: 首頁>>代碼示例>>Python>>正文


Python HTTPStatus.NO_CONTENT屬性代碼示例

本文整理匯總了Python中http.HTTPStatus.NO_CONTENT屬性的典型用法代碼示例。如果您正苦於以下問題:Python HTTPStatus.NO_CONTENT屬性的具體用法?Python HTTPStatus.NO_CONTENT怎麽用?Python HTTPStatus.NO_CONTENT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在http.HTTPStatus的用法示例。


在下文中一共展示了HTTPStatus.NO_CONTENT屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: response_wrapper_factory

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def response_wrapper_factory(app, handler):
    @wraps(handler)
    async def wrap_response_middleware(request):
        response = await handler(request)
        if not isinstance(response, Response):
            if isinstance(response, tuple):
                body = response[0]
                status = response[1]
                response = Response(status=status, body=body)
            elif isinstance(response, dict) or isinstance(response, str):
                response = Response(body=response)
            elif response is None:
                response = Response(status=HTTPStatus.NO_CONTENT)
            else:
                raise ValueError('Request handler returned an invalid type.'
                                 ' Return types should be one of '
                                 '[Response, dict, str, None, (dict, int)]')
        return response
    return wrap_response_middleware 
開發者ID:wasp,項目名稱:waspy,代碼行數:21,代碼來源:app.py

示例2: put

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def put(self, device_id):
        self._authenticate(device_id)
        payload = json.loads(self.request.data)
        send_email = SendEmail(payload)
        send_email.validate()

        account = AccountRepository(self.db).get_account_by_device_id(device_id)

        if account:
            message = EmailMessage()
            message['Subject'] = str(send_email.title)
            message['From'] = str(send_email.sender)
            message.set_content(str(send_email.body))
            message['To'] = account.email_address
            self._send_email(message)
            response = '', HTTPStatus.OK
        else:
            response = '', HTTPStatus.NO_CONTENT
        return response 
開發者ID:MycroftAI,項目名稱:selene-backend,代碼行數:21,代碼來源:device_email.py

示例3: _build_response

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def _build_response(self, device_id, response_data):
        if response_data is None:
            response = Response(
                '',
                status=HTTPStatus.NO_CONTENT,
                content_type='application/json'
            )
        else:
            response = Response(
                json.dumps(response_data),
                status=HTTPStatus.OK,
                content_type='application/json'
            )
            self._add_etag(DEVICE_SKILL_ETAG_KEY.format(device_id=device_id))

        return response 
開發者ID:MycroftAI,項目名稱:selene-backend,代碼行數:18,代碼來源:device_skill_settings.py

示例4: get

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def get(self, device_id):
        self._authenticate(device_id)
        self._validate_etag(device_etag_key(device_id))
        device = DeviceRepository(self.db).get_device_by_id(device_id)

        if device is not None:
            response_data = dict(
                uuid=device.id,
                name=device.name,
                description=device.placement,
                coreVersion=device.core_version,
                enclosureVersion=device.enclosure_version,
                platform=device.platform,
                user=dict(uuid=device.account_id)
            )
            response = response_data, HTTPStatus.OK

            self._add_etag(device_etag_key(device_id))
        else:
            response = '', HTTPStatus.NO_CONTENT

        return response 
開發者ID:MycroftAI,項目名稱:selene-backend,代碼行數:24,代碼來源:device.py

示例5: send_order

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def send_order(data):

    token = ''

    headers = {
        'Authorization': f'Token {token}',
        'Content-type': 'application/json'
    }

    response = requests.post(
        'http://127.0.0.1:8000/api/order/add/',
        headers=headers,
        data=json.dumps(data))

    if response.status_code == HTTPStatus.NO_CONTENT:
        print('Ops! Something went wrong!')
        sys.exit(1)

    print('Request was successfull') 
開發者ID:PacktPublishing,項目名稱:Python-Programming-Blueprints,代碼行數:21,代碼來源:send_order.py

示例6: send_order

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def send_order(data):

    token = '8d19ddce090211fffe22af6c06cdfd06ecb94f4e'

    headers = {
        'Authorization': f'Token {token}',
        'Content-type': 'application/json'
    }

    response = requests.post(
        'http://127.0.0.1:8000/api/order/add/',
        headers=headers,
        data=json.dumps(data))

    if response.status_code == HTTPStatus.NO_CONTENT:
        print('Ops! Something went wrong!')
        sys.exit(1)

    print('Request was successfull') 
開發者ID:PacktPublishing,項目名稱:Python-Programming-Blueprints,代碼行數:21,代碼來源:send_order.py

示例7: get

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def get(self, id):
        """A specific koji build details. From koji_build hash, filled by worker."""
        builds_list = KojiBuildModel.get_all_by_build_id(str(id))
        if bool(builds_list.first()):
            build = builds_list[0]

            build_dict = build.api_structure.copy()
            build_dict["srpm_logs"] = (
                build.srpm_build.logs if build.srpm_build else None
            )
            build = make_response(dumps(build_dict))
            build.headers["Content-Type"] = "application/json"
            build.headers["Access-Control-Allow-Origin"] = "*"
            return build if build else ("", HTTPStatus.NO_CONTENT)

        else:
            return "", HTTPStatus.NO_CONTENT 
開發者ID:packit-service,項目名稱:packit-service,代碼行數:19,代碼來源:koji_builds.py

示例8: register

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def register(self):
        """
        View function to register user. Supports html and json requests.
        """
        form = self._get_form('SECURITY_REGISTER_FORM')
        if form.validate_on_submit():
            user = self.security_service.user_manager.create(**form.to_dict())
            self.security_service.register_user(user)
            if request.is_json:
                return '', HTTPStatus.NO_CONTENT
            return self.redirect('SECURITY_POST_REGISTER_REDIRECT_ENDPOINT')

        elif form.errors and request.is_json:
            return self.errors(form.errors)

        return self.render('register',
                           register_user_form=form,
                           **self.security.run_ctx_processor('register')) 
開發者ID:briancappello,項目名稱:flask-unchained,代碼行數:20,代碼來源:security_controller.py

示例9: send_confirmation_email

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def send_confirmation_email(self):
        """
        View function which sends confirmation token and instructions to a user.
        """
        form = self._get_form('SECURITY_SEND_CONFIRMATION_FORM')
        if form.validate_on_submit():
            self.security_service.send_email_confirmation_instructions(form.user)
            self.flash(_('flask_unchained.bundles.security:flash.confirmation_request',
                         email=form.user.email), category='info')
            if request.is_json:
                return '', HTTPStatus.NO_CONTENT
            return self.redirect('send_confirmation_email')

        elif form.errors and request.is_json:
            return self.errors(form.errors)

        return self.render('send_confirmation_email',
                           send_confirmation_form=form,
                           **self.security.run_ctx_processor('send_confirmation_email')) 
開發者ID:briancappello,項目名稱:flask-unchained,代碼行數:21,代碼來源:security_controller.py

示例10: forgot_password

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def forgot_password(self):
        """
        View function to request a password recovery email with a reset token.
        Supports html and json requests.
        """
        form = self._get_form('SECURITY_FORGOT_PASSWORD_FORM')
        if form.validate_on_submit():
            self.security_service.send_reset_password_instructions(form.user)
            self.flash(_('flask_unchained.bundles.security:flash.password_reset_request',
                         email=form.user.email),
                       category='info')
            if request.is_json:
                return '', HTTPStatus.NO_CONTENT
            return self.redirect('forgot_password')

        elif form.errors and request.is_json:
            return self.errors(form.errors)

        return self.render('forgot_password',
                           forgot_password_form=form,
                           **self.security.run_ctx_processor('forgot_password')) 
開發者ID:briancappello,項目名稱:flask-unchained,代碼行數:23,代碼來源:security_controller.py

示例11: test_delete_accepts_incomplete

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def test_delete_accepts_incomplete(self):
        self.client.delete.return_value = self.mock_response(
            '/v2/service_instances/instance_id',
            HTTPStatus.NO_CONTENT,
            None)
        self.client.v2.service_instances.remove('instance_id', accepts_incomplete=True)
        self.client.delete.assert_called_with(self.client.delete.return_value.url,
                                              params=dict(accepts_incomplete="true"))

        self.client.delete.return_value = self.mock_response(
            '/v2/service_instances/instance_id',
            HTTPStatus.NO_CONTENT,
            None)
        self.client.v2.service_instances.remove('instance_id', accepts_incomplete="true")
        self.client.delete.assert_called_with(self.client.delete.return_value.url,
                                              params=dict(accepts_incomplete="true")) 
開發者ID:cloudfoundry-community,項目名稱:cf-python-client,代碼行數:18,代碼來源:test_service_instances.py

示例12: test_delete_purge

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def test_delete_purge(self):
        self.client.delete.return_value = self.mock_response(
            '/v2/service_instances/instance_id',
            HTTPStatus.NO_CONTENT,
            None)
        self.client.v2.service_instances.remove('instance_id', accepts_incomplete=True, purge=True)
        self.client.delete.assert_called_with(self.client.delete.return_value.url,
                                              params=dict(accepts_incomplete='true', purge="true"))

        self.client.delete.return_value = self.mock_response(
            '/v2/service_instances/instance_id',
            HTTPStatus.NO_CONTENT,
            None)
        self.client.v2.service_instances.remove('instance_id', purge="true")
        self.client.delete.assert_called_with(self.client.delete.return_value.url,
                                              params=dict(purge="true"))

        self.client.delete.return_value = self.mock_response(
            '/v2/service_instances/instance_id',
            HTTPStatus.NO_CONTENT,
            None)
        self.client.v2.service_instances.remove('instance_id', purge="true")
        self.client.delete.assert_called_with(self.client.delete.return_value.url,
                                              params=dict(purge="true")) 
開發者ID:cloudfoundry-community,項目名稱:cf-python-client,代碼行數:26,代碼來源:test_service_instances.py

示例13: test_send_error

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def test_send_error(self):
        allow_transfer_encoding_codes = (HTTPStatus.NOT_MODIFIED,
                                         HTTPStatus.RESET_CONTENT)
        for code in (HTTPStatus.NO_CONTENT, HTTPStatus.NOT_MODIFIED,
                     HTTPStatus.PROCESSING, HTTPStatus.RESET_CONTENT,
                     HTTPStatus.SWITCHING_PROTOCOLS):
            self.con.request('SEND_ERROR', '/{}'.format(code))
            res = self.con.getresponse()
            self.assertEqual(code, res.status)
            self.assertEqual(None, res.getheader('Content-Length'))
            self.assertEqual(None, res.getheader('Content-Type'))
            if code not in allow_transfer_encoding_codes:
                self.assertEqual(None, res.getheader('Transfer-Encoding'))

            data = res.read()
            self.assertEqual(b'', data) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:18,代碼來源:test_httpservers.py

示例14: test_container_generate_upload_url

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def test_container_generate_upload_url(container, binary_stream, temp_file):
    form_post = container.generate_upload_url(
        settings.BINARY_FORM_FILENAME, **settings.BINARY_OPTIONS
    )
    assert "url" in form_post and "fields" in form_post
    assert uri_validator(form_post["url"])

    url = form_post["url"]
    fields = form_post["fields"]
    multipart_form_data = {
        "file": (settings.BINARY_FORM_FILENAME, binary_stream, "image/png"),
    }
    response = requests.post(url, data=fields, files=multipart_form_data)
    assert response.status_code == HTTPStatus.NO_CONTENT, response.text

    blob = container.get_blob(settings.BINARY_FORM_FILENAME)
    assert blob.meta_data == settings.BINARY_OPTIONS["meta_data"]
    assert blob.content_type == settings.BINARY_OPTIONS["content_type"]
    # assert blob.content_disposition == settings.BINARY_OPTIONS['content_disposition']
    # assert blob.cache_control == settings.BINARY_OPTIONS['cache_control'] 
開發者ID:scottwernervt,項目名稱:cloudstorage,代碼行數:22,代碼來源:test_drivers_minio.py

示例15: test_container_generate_upload_url

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NO_CONTENT [as 別名]
def test_container_generate_upload_url(container, binary_stream):
    form_post = container.generate_upload_url(
        blob_name="prefix_", **settings.BINARY_OPTIONS
    )
    assert "url" in form_post and "fields" in form_post
    assert uri_validator(form_post["url"])

    url = form_post["url"]
    fields = form_post["fields"]
    multipart_form_data = {
        "file": (settings.BINARY_FORM_FILENAME, binary_stream, "image/png"),
    }
    response = requests.post(url, data=fields, files=multipart_form_data)
    assert response.status_code == HTTPStatus.NO_CONTENT, response.text

    blob = container.get_blob("prefix_" + settings.BINARY_FORM_FILENAME)
    assert blob.meta_data == settings.BINARY_OPTIONS["meta_data"]
    assert blob.content_type == settings.BINARY_OPTIONS["content_type"]
    assert blob.content_disposition == settings.BINARY_OPTIONS["content_disposition"]
    assert blob.cache_control == settings.BINARY_OPTIONS["cache_control"] 
開發者ID:scottwernervt,項目名稱:cloudstorage,代碼行數:22,代碼來源:test_drivers_google.py


注:本文中的http.HTTPStatus.NO_CONTENT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。