ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 02.01.2026

Просмотров: 2697

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

49.2. OTHER INTERFACES

__contains__(k)

Return True if key k exists in the dictionary.

keys()

Return a list of keys from the dictionary

items()

Return a list of [(k,v)] pairs from the dictionary

clear()

Clear all values from the dictionary

get(k, default=None)

Return the value for key k from the renderer dictionary, or the default if no such value exists.

__setitem__(k, value)

Set a key/value pair into the dictionary

pop(k, default=None)

Pop the key k from the dictionary and return its value. If k doesn’t exist, and default is provided, return the default. If k doesn’t exist and default is not provided, raise a KeyError.

update(d)

Update the renderer dictionary with another dictionary d.

__iter__()

Return an iterator over the keys of this dictionary

has_key(k)

Return True if key k exists in the dictionary.

values()

Return a list of values from the dictionary

itervalues()

Return an iterator of values from the dictionary

iteritems()

Return an iterator of (k,v) pairs from the dictionary

popitem()

Pop the item with key k from the dictionary and return it as a two-tuple (k, v). If k doesn’t exist, raise a KeyError.

595


49. PYRAMID.INTERFACES

iterkeys()

Return an iterator of keys from the dictionary

interface IMultiDict

Extends: pyramid.interfaces.IDict

An ordered dictionary that can have multiple values for each key. A multidict adds the methods getall, getone, mixed, extend add, and dict_of_lists to the normal dictionary interface. A multidict data structure is used as request.POST, request.GET, and request.params within an Pyramid application.

extend(other=None, **kwargs)

Add a set of keys and values, not overwriting any previous values. The other structure may be a list of two-tuples or a dictionary. If **kwargs is passed, its value will overwrite existing values.

getall(key)

Return a list of all values matching the key (may be an empty list)

add(key, value)

Add the key and value, not overwriting any previous value.

getone(key)

Get one value matching the key, raising a KeyError if multiple values were found.

dict_of_lists()

Returns a dictionary where each key is associated with a list of values.

mixed()

Returns a dictionary where the values are either single values, or a list of values when a key/value appears more than once in this dictionary. This is similar to the kind of dictionary often used to represent the variables in a web request.

interface IResponse

Represents a WSGI response using the WebOb response interface. Some attribute and method documentation of this interface references RFC 2616.

This interface is most famously implemented by pyramid.response.Response and the HTTP exception classes in pyramid.httpexceptions.

content_length

Gets and sets and deletes the Content-Length header. For more information on Content-Length see RFC 2616 section 14.17. Converts using int.

596


49.2. OTHER INTERFACES

status

The status string.

encode_content(encoding=’gzip’, lazy=False)

Encode the content with the given encoding (only gzip and identity are supported).

cache_expires

Get/set the Cache-Control and Expires headers. This sets the response to expire in the number of seconds passed when set.

set_cookie(key, value=’‘, max_age=None, path=’/’, domain=None, secure=False, httponly=False, comment=None, expires=None,

overwrite=False)

Set (add) a cookie for the response

vary

Gets and sets and deletes the Vary header. For more information on Vary see section 14.44. Converts using list.

retry_after

Gets and sets and deletes the Retry-After header. For more information on RetryAfter see RFC 2616 section 14.37. Converts using HTTP date or delta seconds.

www_authenticate

Gets and sets and deletes the WWW-Authenticate header. For more information on WWW-Authenticate see RFC 2616 section 14.47. Converts using ‘parse_auth’ and ‘serialize_auth’.

content_language

Gets and sets and deletes the Content-Language header. Converts using list. For more information about Content-Language see RFC 2616 section 14.12.

etag

Gets and sets and deletes the ETag header. For more information on ETag see RFC 2616 section 14.19. Converts using Entity tag.

content_location

Gets and sets and deletes the Content-Location header. For more information on Content-Location see RFC 2616 section 14.14.

server

Gets and sets and deletes the Server header. For more information on Server see RFC216 section 14.38.

597


49. PYRAMID.INTERFACES

unset_cookie(key, strict=True)

Unset a cookie with the given name (remove it from the response).

pragma

Gets and sets and deletes the Pragma header. For more information on Pragma see RFC 2616 section 14.32.

app_iter

Returns the app_iter of the response.

If body was set, this will create an app_iter from that body (a single-item list)

headers

The headers in a dictionary-like object

charset

Get/set the charset (in the Content-Type)

unicode_body

Get/set the unicode value of the body (using the charset of the Content-Type)

status_int

The status as an integer

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)

delete_cookie(key, path=’/’, domain=None)

Delete a cookie from the client. Note that path and domain must match how the cookie was originally set. This sets the cookie to the empty string, and max_age=0 so that it should expire immediately.

content_range

Gets and sets and deletes the Content-Range header. For more information on Content-Range see section 14.16. Converts using ContentRange object.

content_encoding

Gets and sets and deletes the Content-Encoding header. For more information about Content-Encoding see RFC 2616 section 14.11.

598

49.2. OTHER INTERFACES

__call__(environ, start_response)

WSGI call interface, should call the start_response callback and should return an iterable

content_md5

Gets and sets and deletes the Content-MD5 header. For more information on Content-MD5 see RFC 2616 section 14.14.

content_disposition

Gets and sets and deletes the Content-Disposition header. For more information on Content-Disposition see RFC 2616 section 19.5.1.

cache_control

Get/set/modify the Cache-Control header (RFC 2616 section 14.9)

location

Gets and sets and deletes the Location header. For more information on Location see RFC 2616 section 14.30.

body

The body of the response, as a str. This will read in the entire app_iter if necessary.

expires

Gets and sets and deletes the Expires header. For more information on Expires see RFC 2616 section 14.21. Converts using HTTP date.

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 would not be applied otherwise.

md5_etag(body=None, set_content_md5=False)

Generate an etag for the response object using an MD5 hash of the body (the body parameter, or self.body if not given). Sets self.etag. If set_content_md5 is True sets self.content_md5 as well

app_iter_range(start, stop)

Return a new app_iter built from the response app_iter that serves up only the given start:stop range.

last_modified

Gets and sets and deletes the Last-Modified header. For more information on LastModified see RFC 2616 section 14.29. Converts using HTTP date.

599


49. PYRAMID.INTERFACES

RequestClass

Alias for pyramid.request.Request

content_type

Get/set the Content-Type header (or None), without the charset or any parameters. If you include parameters (or ; at all) when setting the content_type, any existing parameters will be deleted; otherwise they will be preserved.

date

Gets and sets and deletes the Date header. For more information on Date see RFC 2616 section 14.18. Converts using HTTP date.

copy()

Makes a copy of the response and returns the copy.

accept_ranges

Gets and sets and deletes the Accept-Ranges header. For more information on Accept-Ranges see RFC 2616, section 14.5

age

Gets and sets and deletes the Age header. Converts using int. For more information on Age see RFC 2616, section 14.6.

request

Return the request associated with this response if any.

merge_cookies(resp)

Merge the cookies that were set on this response with the given resp object (which can be any WSGI application). If the resp is a webob.Response object, then the other object will be modified in-place.

headerlist

The list of response headers.

environ

Get/set the request environ associated with this response, if any.

allow

Gets and sets and deletes the Allow header. Converts using list. For more information on Allow see RFC 2616, Section 14.7.

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_iter will be modified by writes.

600

49.2. OTHER INTERFACES

interface IIntrospectable

An introspectable object used for configuration introspection. In addition to the methods below, objects which implement this interface must also implement all the methods of Python’s collections.MutableMapping (the “dictionary interface”), and must be hashable.

register(introspector, action_info)

Register this IIntrospectable with an introspector. This method is invoked during action execution. Adds the introspectable and its relations to the introspector. introspector should be an object implementing IIntrospector. action_info should be a object implementing the interface pyramid.interfaces.IActionInfo representing the call that registered this introspectable. Pseudocode for an implementation of this method:

def register(self, introspector, action_info): self.action_info = action_info introspector.add(self)

for methodname, category_name, discriminator in self._relations: method = getattr(introspector, methodname) method((i.category_name, i.discriminator),

(category_name, discriminator))

discriminator_hash

an integer hash of the discriminator

title

Text title describing this introspectable

relate(category_name, discriminator)

Indicate an intent to relate this IIntrospectable with another IIntrospectable (the one associated with the category_name and discriminator) during action execution.

type_name

Text type name describing this introspectable

unrelate(category_name, discriminator)

Indicate an intent to break the relationship between this IIntrospectable with another IIntrospectable (the one associated with the category_name and discriminator) during action execution.

601