pyramid.response¶
- class Response(body=None, status=None, headerlist=None, app_iter=None, content_type=None, conditional_response=None, charset=<object object>, **kw)[ソース]¶
- property accept_ranges¶
- Gets and sets the - Accept-Rangesheader (HTTP spec section 14.5).
 - property age¶
- Gets and sets the - Ageheader (HTTP spec section 14.6). Converts it using int.
 - property allow¶
- Gets and sets the - Allowheader (HTTP spec section 14.7). Converts it using list.
 - property app_iter¶
- Returns the - app_iterof the response.- If - bodywas set, this will create an- app_iterfrom that- body(a single-item list).
 - app_iter_range(start, stop)[ソース]¶
- Return a new - app_iterbuilt from the response- app_iter, that serves up only the given- start:stoprange.
 - property body¶
- The body of the response, as a - bytes. This will read in the entire app_iter if necessary.
 - property body_file¶
- A file-like object that can be used to write to the body. If you passed in a list - app_iter, that- app_iterwill be modified by writes.
 - property cache_control¶
- Get/set/modify the Cache-Control header (HTTP spec section 14.9). 
 - property charset¶
- Get/set the - charsetspecified in- Content-Type.- There is no checking to validate that a - content_typeactually allows for a- charsetparameter.
 - conditional_response_app(environ, start_response)[ソース]¶
- Like the normal - __call__interface, but checks conditional headers:- If-Modified-Since(- 304 Not Modified; only on- GET,- HEAD)
- If-None-Match(- 304 Not Modified; only on- GET,- HEAD)
- Range(- 406 Partial Content; only on- GET,- HEAD)
 
 - property content_disposition¶
- Gets and sets the - Content-Dispositionheader (HTTP spec section 19.5.1).
 - property content_encoding¶
- Gets and sets the - Content-Encodingheader (HTTP spec section 14.11).
 - property content_language¶
- Gets and sets the - Content-Languageheader (HTTP spec section 14.12). Converts it using list.
 - property content_length¶
- Gets and sets the - Content-Lengthheader (HTTP spec section 14.17). Converts it using int.
 - property content_location¶
- Gets and sets the - Content-Locationheader (HTTP spec section 14.14).
 - property content_md5¶
- Gets and sets the - Content-MD5header (HTTP spec section 14.14).
 - property content_range¶
- Gets and sets the - Content-Rangeheader (HTTP spec section 14.16). Converts it using ContentRange object.
 - property content_type¶
- Get/set the - Content-Typeheader. If no- Content-Typeheader is set, this will return- None.- バージョン 1.7 で変更: Setting a new - Content-Typewill remove all- Content-Typeparameters and reset the- charsetto the default if the- Content-Typeis- text/*or XML (- application/xmlor- */*+xml).- To preserve all - Content-Typeparameters, you may use the following code:- resp = Response() params = resp.content_type_params resp.content_type = 'application/something' resp.content_type_params = params 
 - property content_type_params¶
- A dictionary of all the parameters in the content type. - (This is not a view, set to change, modifications of the dict will not be applied otherwise.) 
 - property date¶
- Gets and sets the - Dateheader (HTTP spec section 14.18). Converts it using HTTP date.
 - delete_cookie(name, path='/', domain=None)[ソース]¶
- Delete a cookie from the client. Note that - pathand- domainmust match how the cookie was originally set.- This sets the cookie to the empty string, and - max_age=0so that it should expire immediately.
 - encode_content(encoding='gzip', lazy=False)[ソース]¶
- Encode the content with the given encoding (only - gzipand- identityare supported).
 - property etag¶
- Gets and sets the - ETagheader (HTTP spec section 14.19). Converts it using Entity tag.
 - property expires¶
- Gets and sets the - Expiresheader (HTTP spec section 14.21). Converts it using HTTP date.
 - classmethod from_file(fp)[ソース]¶
- Reads a response from a file-like object (it must implement - .read(size)and- .readline()).- It will read up to the end of the response, not the end of the file. - This reads the response as represented by - str(resp); it may not read every valid HTTP response properly. Responses must have a- Content-Length.
 - property has_body¶
- Determine if the the response has a - body. In contrast to simply accessing- body, this method will not read the underlying- app_iter.
 - property headerlist¶
- The list of response headers. 
 - property headers¶
- The headers in a dictionary-like object. 
 - property json¶
- Set/get the body of the response as JSON. 
 - property json_body¶
- Set/get the body of the response as JSON. 
 - property last_modified¶
- Gets and sets the - Last-Modifiedheader (HTTP spec section 14.29). Converts it using HTTP date.
 - property location¶
- Gets and sets the - Locationheader (HTTP spec section 14.30).
 - md5_etag(body=None, set_content_md5=False)[ソース]¶
- Generate an etag for the response object using an MD5 hash of the body (the - bodyparameter, or- self.bodyif not given).- Sets - self.etag.- If - set_content_md5is- True, sets- self.content_md5as well.
 - merge_cookies(resp)[ソース]¶
- Merge the cookies that were set on this response with the given - respobject (which can be any WSGI application).- If the - respis a- webob.Responseobject, then the other object will be modified in-place.
 - property pragma¶
- Gets and sets the - Pragmaheader (HTTP spec section 14.32).
 - property retry_after¶
- Gets and sets the - Retry-Afterheader (HTTP spec section 14.37). Converts it using HTTP date or delta seconds.
 - property server¶
- Gets and sets the - Serverheader (HTTP spec section 14.38).
 - set_cookie(name, value='', max_age=None, path='/', domain=None, secure=False, httponly=False, comment=None, expires=None, overwrite=False, samesite=None)[ソース]¶
- Set (add) a cookie for the response. - Arguments are: - name- The cookie name. - value- The cookie value, which should be a string or - None. If- valueis- None, it's equivalent to calling the- webob.response.Response.unset_cookie()method for this cookie key (it effectively deletes the cookie on the client).- max_age- An integer representing a number of seconds, - datetime.timedelta, or- None. This value is used as the- Max-Ageof the generated cookie. If- expiresis not passed and this value is not- None, the- max_agevalue will also influence the- Expiresvalue of the cookie (- Expireswill be set to- now+- max_age). If this value is- None, the cookie will not have a- Max-Agevalue (unless- expiresis set). If both- max_ageand- expiresare set, this value takes precedence.- path- A string representing the cookie - Pathvalue. It defaults to- /.- domain- A string representing the cookie - Domain, or- None. If domain is- None, no- Domainvalue will be sent in the cookie.- secure- A boolean. If it's - True, the- secureflag will be sent in the cookie, if it's- False, the- secureflag will not be sent in the cookie.- httponly- A boolean. If it's - True, the- HttpOnlyflag will be sent in the cookie, if it's- False, the- HttpOnlyflag will not be sent in the cookie.- samesite- A string representing the - SameSiteattribute of the cookie or- None. If samesite is- Noneno- SameSitevalue will be sent in the cookie. Should only be- "strict",- "lax", or- "none".- comment- A string representing the cookie - Commentvalue, or- None. If- commentis- None, no- Commentvalue will be sent in the cookie.- expires- A - datetime.timedeltaobject representing an amount of time,- datetime.datetimeor- None. A non-- Nonevalue is used to generate the- Expiresvalue of the generated cookie. If- max_ageis not passed, but this value is not- None, it will influence the- Max-Ageheader. If this value is- None, the- Expirescookie value will be unset (unless- max_ageis set). If- max_ageis set, it will be used to generate the- expiresand this value is ignored.- If a - datetime.datetimeis provided it has to either be timezone aware or be based on UTC.- datetime.datetimeobjects that are local time are not supported. Timezone aware- datetime.datetimeobjects are converted to UTC.- This argument will be removed in future versions of WebOb (version 1.9). - overwrite- If this key is - True, before setting the cookie, unset any existing cookie.
 - property status¶
- The status string. 
 - property status_code¶
- The status as an integer. 
 - property status_int¶
- The status as an integer. 
 - property text¶
- Get/set the text value of the body using the - charsetof the- Content-Typeor the- default_body_encoding.
 - property ubody¶
- Deprecated alias for .text 
 - property unicode_body¶
- Deprecated alias for .text 
 - unset_cookie(name, strict=True)[ソース]¶
- Unset a cookie with the given name (remove it from the response). 
 - property vary¶
- Gets and sets the - Varyheader (HTTP spec section 14.44). Converts it using list.
 - property www_authenticate¶
- Gets and sets the - WWW-Authenticateheader (HTTP spec section 14.47). Converts it using- parse_authand- serialize_auth.
 
- class FileResponse(path, request=None, cache_max_age=None, content_type=None, content_encoding=None)[ソース]¶
- A Response object that can be used to serve a static file from disk simply. - pathis a file path on disk.- requestmust be a Pyramid request object. Note that a request must be passed if the response is meant to attempt to use the- wsgi.file_wrapperfeature of the web server that you're using to serve your Pyramid application.- cache_max_ageis the number of seconds that should be used to HTTP cache this response.- content_typeis the content_type of the response.- content_encodingis the content_encoding of the response. It's generally safe to leave this set to- Noneif you're serving a binary file. This argument will be ignored if you also leave- content-typeas- None.
- class FileIter(file, block_size=262144)[ソース]¶
- A fixed-block-size iterator for use as a WSGI app_iter. - fileis a Python file pointer (or at least an object with a- readmethod that takes a size hint).- block_sizeis an optional block size for iteration.
Functions¶
- response_adapter(*types_or_ifaces, **kwargs)[ソース]¶
- Decorator activated via a scan which treats the function being decorated as a response adapter for the set of types or interfaces passed as - *types_or_ifacesto the decorator constructor.- For example, if you scan the following response adapter: - from pyramid.response import Response from pyramid.response import response_adapter @response_adapter(int) def myadapter(i): return Response(status=i) - You can then return an integer from your view callables, and it will be converted into a response with the integer as the status code. - More than one type or interface can be passed as a constructor argument. The decorated response adapter will be called for each type or interface. - import json from pyramid.response import Response from pyramid.response import response_adapter @response_adapter(dict, list) def myadapter(ob): return Response(json.dumps(ob)) - This method will have no effect until a scan is performed agains the package or module which contains it, ala: - from pyramid.config import Configurator config = Configurator() config.scan('somepackage_containing_adapters') - Two additional keyword arguments which will be passed to the venusian - attachfunction are- _depthand- _category.- _depthis provided for people who wish to reuse this class from another decorator. The default value is- 0and should be specified relative to the- response_adapterinvocation. It will be passed in to the venusian- attachfunction as the depth of the callstack when Venusian checks if the decorator is being used in a class or module context. It's not often used, but it can be useful in this circumstance.- _categorysets the decorator category name. It can be useful in combination with the- categoryargument of- scanto control which views should be processed.- See the - venusian.attach()function in Venusian for more information about the- _depthand- _categoryarguments.- バージョン 1.9.1 で変更: Added the - _depthand- _categoryarguments.
 
