desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Returns a list of ResourceExtension objects.'
| def get_resources(self):
| resources = []
resources.append(ResourceExtension('extensions', ExtensionsResource(self)))
for ext in self.extensions.values():
try:
resources.extend(ext.get_resources())
except AttributeError:
pass
return resources
|
'Returns a list of ControllerExtension objects.'
| def get_controller_extensions(self):
| controller_exts = []
for ext in self.extensions.values():
try:
get_ext_method = ext.get_controller_extensions
except AttributeError:
continue
controller_exts.extend(get_ext_method())
return controller_exts
|
'Checks for required methods in extension objects.'
| def _check_extension(self, extension):
| try:
LOG.debug(_('Ext name: %s'), extension.name)
LOG.debug(_('Ext alias: %s'), extension.alias)
LOG.debug(_('Ext description: %s'), ' '.join(extension.__doc__.strip().split()))
LOG.debug(_('Ext namespace: %s'), extension.namespace)
LOG.debug(_('Ext... |
'Execute an extension factory.
Loads an extension. The \'ext_factory\' is the name of a
callable that will be imported and called with one
argument--the extension manager. The factory callable is
expected to call the register() method at least once.'
| def load_extension(self, ext_factory):
| LOG.debug(_('Loading extension %s'), ext_factory)
factory = importutils.import_class(ext_factory)
LOG.debug(_('Calling extension factory %s'), ext_factory)
factory(self)
|
'Load extensions specified on the command line.'
| def _load_extensions(self):
| extensions = list(self.cls_list)
old_contrib_path = 'monitor.api.openstack.servicemanage.contrib.standard_extensions'
new_contrib_path = 'monitor.api.contrib.standard_extensions'
if (old_contrib_path in extensions):
LOG.warn(_('osapi_servicemanage_extension is set to deprecated pa... |
'Return href string with proper limit and marker params.'
| def _get_next_link(self, request, identifier):
| params = request.params.copy()
params['marker'] = identifier
prefix = self._update_link_prefix(request.application_url, FLAGS.osapi_servicemanage_base_URL)
url = os.path.join(prefix, request.environ['monitor.context'].project_id, self._collection_name)
return ('%s?%s' % (url, dict_to_query_str(param... |
'Return an href string pointing to this object.'
| def _get_href_link(self, request, identifier):
| prefix = self._update_link_prefix(request.application_url, FLAGS.osapi_servicemanage_base_URL)
return os.path.join(prefix, request.environ['monitor.context'].project_id, self._collection_name, str(identifier))
|
'Create a URL that refers to a specific resource.'
| def _get_bookmark_link(self, request, identifier):
| base_url = remove_version_from_href(request.application_url)
base_url = self._update_link_prefix(base_url, FLAGS.osapi_servicemanage_base_URL)
return os.path.join(base_url, request.environ['monitor.context'].project_id, self._collection_name, str(identifier))
|
'Retrieve \'next\' link, if applicable.'
| def _get_collection_links(self, request, items, id_key='uuid'):
| links = []
limit = int(request.params.get('limit', 0))
if (limit and (limit == len(items))):
last_item = items[(-1)]
if (id_key in last_item):
last_item_id = last_item[id_key]
else:
last_item_id = last_item['id']
links.append({'rel': 'next', 'href': se... |
'Marshal the metadata attribute of a parsed request'
| def extract_metadata(self, metadata_node):
| if (metadata_node is None):
return {}
metadata = {}
for meta_node in self.find_children_named(metadata_node, 'meta'):
key = meta_node.getAttribute('key')
metadata[key] = self.extract_text(meta_node)
return metadata
|
'Initialize view builder.'
| def __init__(self):
| super(ViewBuilder, self).__init__()
|
'Show a list of backups without many details.'
| def summary_list(self, request, backups):
| return self._list_view(self.summary, request, backups)
|
'Detailed view of a list of backups .'
| def detail_list(self, request, backups):
| return self._list_view(self.detail, request, backups)
|
'Generic, non-detailed view of a backup.'
| def summary(self, request, backup):
| return {'backup': {'id': backup['id'], 'name': backup['display_name'], 'links': self._get_links(request, backup['id'])}}
|
'Generic, non-detailed view of a restore.'
| def restore_summary(self, request, restore):
| return {'restore': {'backup_id': restore['backup_id'], 'servicemanage_id': restore['servicemanage_id']}}
|
'Detailed view of a single backup.'
| def detail(self, request, backup):
| return {'backup': {'id': backup.get('id'), 'status': backup.get('status'), 'size': backup.get('size'), 'object_count': backup.get('object_count'), 'availability_zone': backup.get('availability_zone'), 'container': backup.get('container'), 'created_at': backup.get('created_at'), 'name': backup.get('display_name'), '... |
'Provide a view for a list of backups.'
| def _list_view(self, func, request, backups):
| backups_list = [func(request, backup)['backup'] for backup in backups]
backups_links = self._get_collection_links(request, backups, self._collection_name)
backups_dict = dict(backups=backups_list)
if backups_links:
backups_dict['backups_links'] = backups_links
return backups_dict
|
'Trim away extraneous servicemanage type attributes.'
| def show(self, request, servicemanage_type, brief=False):
| trimmed = dict(id=servicemanage_type.get('id'), name=servicemanage_type.get('name'), extra_specs=servicemanage_type.get('extra_specs'))
return (trimmed if brief else dict(servicemanage_type=trimmed))
|
'Index over trimmed servicemanage types'
| def index(self, request, servicemanage_types):
| servicemanage_types_list = [self.show(request, servicemanage_type, True) for servicemanage_type in servicemanage_types]
return dict(servicemanage_types=servicemanage_types_list)
|
'Builder for absolute limits
absolute_limits should be given as a dict of limits.
For example: {"ram": 512, "gigabytes": 1024}.'
| def _build_absolute_limits(self, absolute_limits):
| limit_names = {'ram': ['maxTotalRAMSize'], 'instances': ['maxTotalInstances'], 'cores': ['maxTotalCores'], 'gigabytes': ['maxTotalServiceManageGigabytes'], 'servicemanages': ['maxTotalServiceManages'], 'key_pairs': ['maxTotalKeypairs'], 'floating_ips': ['maxTotalFloatingIps'], 'metadata_items': ['maxServerMeta', 'm... |
':param base_url: url of the root wsgi application'
| def __init__(self, base_url):
| self.base_url = base_url
|
'Generate a container of links that refer to the provided version.'
| def _build_links(self, version_data):
| href = self.generate_href()
links = [{'rel': 'self', 'href': href}]
return links
|
'Create an url that refers to a specific version_number.'
| def generate_href(self, path=None):
| version_number = 'v1'
if path:
path = path.strip('/')
return os.path.join(self.base_url, version_number, path)
else:
return (os.path.join(self.base_url, version_number) + '/')
|
'Initialize the selector.
Each argument is a subsequent index into the object.'
| def __init__(self, *chain):
| self.chain = chain
|
'Return a representation of the selector.'
| def __repr__(self):
| return ('Selector' + repr(self.chain))
|
'Select a datum to operate on.
Selects the relevant datum within the object.
:param obj: The object from which to select the object.
:param do_raise: If False (the default), return None if the
indexed datum does not exist. Otherwise,
raise a KeyError.'
| def __call__(self, obj, do_raise=False):
| for elem in self.chain:
if callable(elem):
obj = elem(obj)
else:
try:
obj = obj[elem]
except (KeyError, IndexError):
if do_raise:
raise KeyError(elem)
return None
return obj
|
'Returns empty string if the selected value does not exist.'
| def __call__(self, obj, do_raise=False):
| try:
return super(EmptyStringSelector, self).__call__(obj, True)
except KeyError:
return ''
|
'Initialize the selector.
:param value: The value to return.'
| def __init__(self, value):
| self.value = value
|
'Return a representation of the selector.'
| def __repr__(self):
| return repr(self.value)
|
'Select a datum to operate on.
Returns a constant value. Compatible with
Selector.__call__().'
| def __call__(self, _obj, _do_raise=False):
| return self.value
|
'Initialize an element.
Initializes an element in the template. Keyword arguments
specify attributes to be set on the element; values must be
callables. See TemplateElement.set() for more information.
:param tag: The name of the tag to create.
:param attrib: An optional dictionary of element attributes.
:param select... | def __init__(self, tag, attrib=None, selector=None, subselector=None, **extra):
| if (selector is None):
selector = Selector()
elif (not callable(selector)):
selector = Selector(selector)
if ((subselector is not None) and (not callable(subselector))):
subselector = Selector(subselector)
self.tag = tag
self.selector = selector
self.subselector = subsele... |
'Return a representation of the template element.'
| def __repr__(self):
| return ('<%s.%s %r at %#x>' % (self.__class__.__module__, self.__class__.__name__, self.tag, id(self)))
|
'Return the number of child elements.'
| def __len__(self):
| return len(self._children)
|
'Determine whether a child node named by key exists.'
| def __contains__(self, key):
| return (key in self._childmap)
|
'Retrieve a child node by index or name.'
| def __getitem__(self, idx):
| if isinstance(idx, basestring):
return self._childmap[idx]
else:
return self._children[idx]
|
'Append a child to the element.'
| def append(self, elem):
| elem = elem.unwrap()
if (elem.tag in self._childmap):
raise KeyError(elem.tag)
self._children.append(elem)
self._childmap[elem.tag] = elem
|
'Append children to the element.'
| def extend(self, elems):
| elemmap = {}
elemlist = []
for elem in elems:
elem = elem.unwrap()
if ((elem.tag in self._childmap) or (elem.tag in elemmap)):
raise KeyError(elem.tag)
elemmap[elem.tag] = elem
elemlist.append(elem)
self._children.extend(elemlist)
self._childmap.update(ele... |
'Insert a child element at the given index.'
| def insert(self, idx, elem):
| elem = elem.unwrap()
if (elem.tag in self._childmap):
raise KeyError(elem.tag)
self._children.insert(idx, elem)
self._childmap[elem.tag] = elem
|
'Remove a child element.'
| def remove(self, elem):
| elem = elem.unwrap()
if ((elem.tag not in self._childmap) or (self._childmap[elem.tag] != elem)):
raise ValueError(_('element is not a child'))
self._children.remove(elem)
del self._childmap[elem.tag]
|
'Get an attribute.
Returns a callable which performs datum selection.
:param key: The name of the attribute to get.'
| def get(self, key):
| return self.attrib[key]
|
'Set an attribute.
:param key: The name of the attribute to set.
:param value: A callable taking an object and optional boolean
do_raise indicator and returning the datum bound
to the attribute. If None, a Selector() will be
constructed from the key. If a string, a
Selector() will be constructed from the string.'
| def set(self, key, value=None):
| if (value is None):
value = Selector(key)
elif (not callable(value)):
value = Selector(value)
self.attrib[key] = value
|
'Return the attribute names.'
| def keys(self):
| return self.attrib.keys()
|
'Return the attribute names and values.'
| def items(self):
| return self.attrib.items()
|
'Unwraps a template to return a template element.'
| def unwrap(self):
| return self
|
'Wraps a template element to return a template.'
| def wrap(self):
| return Template(self)
|
'Apply text and attributes to an etree.Element.
Applies the text and attribute instructions in the template
element to an etree.Element instance.
:param elem: An etree.Element instance.
:param obj: The base object associated with this template
element.'
| def apply(self, elem, obj):
| if (self.text is not None):
elem.text = unicode(self.text(obj))
for (key, value) in self.attrib.items():
try:
elem.set(key, unicode(value(obj, True)))
except KeyError:
pass
|
'Internal rendering.
Renders the template node into an etree.Element object.
Returns the etree.Element object.
:param parent: The parent etree.Element instance.
:param datum: The datum associated with this template element.
:param patches: A list of other template elements that must
also be applied.
:param nsmap: An op... | def _render(self, parent, datum, patches, nsmap):
| if callable(self.tag):
tagname = self.tag(datum)
else:
tagname = self.tag
elem = etree.Element(tagname, nsmap=nsmap)
if (parent is not None):
parent.append(elem)
if (datum is None):
return elem
self.apply(elem, datum)
for patch in patches:
patch.apply(... |
'Render an object.
Renders an object against this template node. Returns a list
of two-item tuples, where the first item is an etree.Element
instance and the second item is the datum associated with that
instance.
:param parent: The parent for the etree.Element instances.
:param obj: The object to render this template... | def render(self, parent, obj, patches=[], nsmap=None):
| data = (None if (obj is None) else self.selector(obj))
if (not self.will_render(data)):
return []
elif (data is None):
return [(self._render(parent, None, patches, nsmap), None)]
if (not isinstance(data, list)):
data = [data]
elif (parent is None):
raise ValueError(_(... |
'Hook method.
An overridable hook method to determine whether this template
element will be rendered at all. By default, returns False
(inhibiting rendering) if the datum is None.
:param datum: The datum associated with this template element.'
| def will_render(self, datum):
| return (datum is not None)
|
'Template element text.
Either None or a callable taking an object and optional
boolean do_raise indicator and returning the datum bound to
the text of the template element.'
| def _text_get(self):
| return self._text
|
'Return string representation of the template tree.
Returns a representation of the template rooted at this
element as a string, suitable for inclusion in debug logs.'
| def tree(self):
| contents = [self.tag, ('!selector=%r' % self.selector)]
if (self.text is not None):
contents.append(('!text=%r' % self.text))
for (key, value) in self.attrib.items():
contents.append(('%s=%r' % (key, value)))
if (len(self) == 0):
return ('<%s/>' % ' '.join([str(i) for i in con... |
'Initialize a template.
:param root: The root element of the template.
:param nsmap: An optional namespace dictionary to be
associated with the root element of the
template.'
| def __init__(self, root, nsmap=None):
| self.root = (root.unwrap() if (root is not None) else None)
self.nsmap = (nsmap or {})
self.serialize_options = dict(encoding='UTF-8', xml_declaration=True)
|
'Internal serialization.
Recursive routine to build a tree of etree.Element instances
from an object based on the template. Returns the first
etree.Element instance rendered, or None.
:param parent: The parent etree.Element instance. Can be
None.
:param obj: The object to render.
:param siblings: The TemplateElement ... | def _serialize(self, parent, obj, siblings, nsmap=None):
| elems = siblings[0].render(parent, obj, siblings[1:], nsmap)
seen = set()
for (idx, sibling) in enumerate(siblings):
for child in sibling:
if (child.tag in seen):
continue
seen.add(child.tag)
nieces = [child]
for sib in siblings[(idx + ... |
'Serialize an object.
Serializes an object against the template. Returns a string
with the serialized XML. Positional and keyword arguments are
passed to etree.tostring().
:param obj: The object to serialize.'
| def serialize(self, obj, *args, **kwargs):
| elem = self.make_tree(obj)
if (elem is None):
return ''
for (k, v) in self.serialize_options.items():
kwargs.setdefault(k, v)
return etree.tostring(elem, *args, **kwargs)
|
'Create a tree.
Serializes an object against the template. Returns an Element
node with appropriate children.
:param obj: The object to serialize.'
| def make_tree(self, obj):
| if (self.root is None):
return None
siblings = self._siblings()
nsmap = self._nsmap()
return self._serialize(None, obj, siblings, nsmap)
|
'Hook method for computing root siblings.
An overridable hook method to return the siblings of the root
element. By default, this is the root element itself.'
| def _siblings(self):
| return [self.root]
|
'Hook method for computing the namespace dictionary.
An overridable hook method to return the namespace dictionary.'
| def _nsmap(self):
| return self.nsmap.copy()
|
'Unwraps a template to return a template element.'
| def unwrap(self):
| return self.root
|
'Wraps a template element to return a template.'
| def wrap(self):
| return self
|
'Hook method for determining slave applicability.
An overridable hook method used to determine if this template
is applicable as a slave to a given master template.
:param master: The master template to test.'
| def apply(self, master):
| return True
|
'Return string representation of the template tree.
Returns a representation of the template as a string, suitable
for inclusion in debug logs.'
| def tree(self):
| return ('%r: %s' % (self, self.root.tree()))
|
'Initialize a master template.
:param root: The root element of the template.
:param version: The version number of the template.
:param nsmap: An optional namespace dictionary to be
associated with the root element of the
template.'
| def __init__(self, root, version, nsmap=None):
| super(MasterTemplate, self).__init__(root, nsmap)
self.version = version
self.slaves = []
|
'Return string representation of the template.'
| def __repr__(self):
| return ('<%s.%s object version %s at %#x>' % (self.__class__.__module__, self.__class__.__name__, self.version, id(self)))
|
'Hook method for computing root siblings.
An overridable hook method to return the siblings of the root
element. This is the root element plus the root elements of
all the slave templates.'
| def _siblings(self):
| return ([self.root] + [slave.root for slave in self.slaves])
|
'Hook method for computing the namespace dictionary.
An overridable hook method to return the namespace dictionary.
The namespace dictionary is computed by taking the master
template\'s namespace dictionary and updating it from all the
slave templates.'
| def _nsmap(self):
| nsmap = self.nsmap.copy()
for slave in self.slaves:
nsmap.update(slave._nsmap())
return nsmap
|
'Attach one or more slave templates.
Attaches one or more slave templates to the master template.
Slave templates must have a root element with the same tag as
the master template. The slave template\'s apply() method will
be called to determine if the slave should be applied to this
master; if it returns False, that ... | def attach(self, *slaves):
| slave_list = []
for slave in slaves:
slave = slave.wrap()
if (slave.root.tag != self.root.tag):
slavetag = slave.root.tag
mastertag = self.root.tag
msg = (_('Template tree mismatch; adding slave %(slavetag)s to master %(mastertag)s') % ... |
'Return a copy of this master template.'
| def copy(self):
| tmp = self.__class__(self.root, self.version, self.nsmap)
tmp.slaves = self.slaves[:]
return tmp
|
'Initialize a slave template.
:param root: The root element of the template.
:param min_vers: The minimum permissible version of the master
template for this slave template to apply.
:param max_vers: An optional upper bound for the master
template version.
:param nsmap: An optional namespace dictionary to be
associated... | def __init__(self, root, min_vers, max_vers=None, nsmap=None):
| super(SlaveTemplate, self).__init__(root, nsmap)
self.min_vers = min_vers
self.max_vers = max_vers
|
'Return string representation of the template.'
| def __repr__(self):
| return ('<%s.%s object versions %s-%s at %#x>' % (self.__class__.__module__, self.__class__.__name__, self.min_vers, self.max_vers, id(self)))
|
'Hook method for determining slave applicability.
An overridable hook method used to determine if this template
is applicable as a slave to a given master template. This
version requires the master template to have a version number
between min_vers and max_vers.
:param master: The master template to test.'
| def apply(self, master):
| if (master.version < self.min_vers):
return False
if ((self.max_vers is not None) and (master.version > self.max_vers)):
return False
return True
|
'Construct and return a template.
:param copy: If True (the default), a copy of the template
will be constructed and returned, if possible.'
| def __new__(cls, copy=True):
| if (cls._tmpl is None):
tmp = super(TemplateBuilder, cls).__new__(cls)
cls._tmpl = tmp.construct()
if (copy and hasattr(cls._tmpl, 'copy')):
return cls._tmpl.copy()
return cls._tmpl
|
'Construct a template.
Called to construct a template instance, which it must return.
Only called once.'
| def construct(self):
| raise NotImplementedError(_('subclasses must implement construct()!'))
|
'Simple paste factory, :class:`monitor.wsgi.Router` doesn\'t have'
| @classmethod
def factory(cls, global_config, **local_config):
| return cls()
|
'Determine the requested response content-type.'
| def best_match_content_type(self):
| if ('monitor.best_content_type' not in self.environ):
content_type = None
parts = self.path.rsplit('.', 1)
if (len(parts) > 1):
possible_type = ('application/' + parts[1])
if (possible_type in SUPPORTED_CONTENT_TYPES):
content_type = possible_type
... |
'Determine content type of the request body.
Does not do any body introspection, only checks header'
| def get_content_type(self):
| if ('Content-Type' not in self.headers):
return None
allowed_types = SUPPORTED_CONTENT_TYPES
content_type = self.content_type
if (content_type not in allowed_types):
raise exception.InvalidContentType(content_type=content_type)
return content_type
|
'Find and call local method.'
| def dispatch(self, *args, **kwargs):
| action = kwargs.pop('action', 'default')
action_method = getattr(self, str(action), self.default)
return action_method(*args, **kwargs)
|
':param metadata: information needed to deserialize xml into
a dictionary.'
| def __init__(self, metadata=None):
| super(XMLDeserializer, self).__init__()
self.metadata = (metadata or {})
|
'Convert a minidom node to a simple Python type.
:param listnames: list of XML node names whose subnodes should
be considered list items.'
| def _from_xml_node(self, node, listnames):
| if ((len(node.childNodes) == 1) and (node.childNodes[0].nodeType == 3)):
return node.childNodes[0].nodeValue
elif (node.nodeName in listnames):
return [self._from_xml_node(n, listnames) for n in node.childNodes]
else:
result = dict()
for attr in node.attributes.keys():
... |
'Search a nodes children for the first child with a given name'
| def find_first_child_named(self, parent, name):
| for node in parent.childNodes:
if (node.nodeName == name):
return node
return None
|
'Return all of a nodes children who have the given name'
| def find_children_named(self, parent, name):
| for node in parent.childNodes:
if (node.nodeName == name):
(yield node)
|
'Get the text field contained by the given node'
| def extract_text(self, node):
| if (len(node.childNodes) == 1):
child = node.childNodes[0]
if (child.nodeType == child.TEXT_NODE):
return child.nodeValue
return ''
|
'Get an attribute value; fallback to an element if not found'
| def find_attribute_or_element(self, parent, name):
| if parent.hasAttribute(name):
return parent.getAttribute(name)
node = self.find_first_child_named(parent, name)
if node:
return self.extract_text(node)
return None
|
'Marshal the metadata attribute of a parsed request'
| def extract_metadata(self, metadata_node):
| metadata = {}
if (metadata_node is not None):
for meta_node in self.find_children_named(metadata_node, 'meta'):
key = meta_node.getAttribute('key')
metadata[key] = self.extract_text(meta_node)
return metadata
|
':param metadata: information needed to deserialize xml into
a dictionary.
:param xmlns: XML namespace to include with serialized xml'
| def __init__(self, metadata=None, xmlns=None):
| super(XMLDictSerializer, self).__init__()
self.metadata = (metadata or {})
self.xmlns = xmlns
|
'Recursive method to convert data members to XML nodes.'
| def _to_xml_node(self, doc, metadata, nodename, data):
| result = doc.createElement(nodename)
xmlns = metadata.get('xmlns', None)
if xmlns:
result.setAttribute('xmlns', xmlns)
if isinstance(data, list):
collections = metadata.get('list_collections', {})
if (nodename in collections):
metadata = collections[nodename]
... |
'Convert the xml object to an xml string.'
| def _to_xml(self, root):
| return etree.tostring(root, encoding='UTF-8', xml_declaration=True)
|
'Binds serializers with an object.
Takes keyword arguments akin to the @serializer() decorator
for specifying serializers. Serializers specified will be
given preference over default serializers or method-specific
serializers on return.'
| def __init__(self, obj, code=None, **serializers):
| self.obj = obj
self.serializers = serializers
self._default_code = 200
self._code = code
self._headers = {}
self.serializer = None
self.media_type = None
|
'Retrieves a header with the given name.'
| def __getitem__(self, key):
| return self._headers[key.lower()]
|
'Sets a header with the given name to the given value.'
| def __setitem__(self, key, value):
| self._headers[key.lower()] = value
|
'Deletes the header with the given name.'
| def __delitem__(self, key):
| del self._headers[key.lower()]
|
'Binds method serializers with the response object.
Binds the method serializers with the response object.
Serializers specified to the constructor will take precedence
over serializers specified to this method.
:param meth_serializers: A dictionary with keys mapping to
response types and values containing
serializer o... | def _bind_method_serializers(self, meth_serializers):
| for (mtype, serializer) in meth_serializers.items():
self.serializers.setdefault(mtype, serializer)
|
'Returns the serializer for the wrapped object.
Returns the serializer for the wrapped object subject to the
indicated content type. If no serializer matching the content
type is attached, an appropriate serializer drawn from the
default serializers will be used. If no appropriate
serializer is available, raises Inva... | def get_serializer(self, content_type, default_serializers=None):
| default_serializers = (default_serializers or {})
try:
mtype = _MEDIA_TYPE_MAP.get(content_type, content_type)
if (mtype in self.serializers):
return (mtype, self.serializers[mtype])
else:
return (mtype, default_serializers[mtype])
except (KeyError, TypeError)... |
'Prepares the serializer that will be used to serialize.
Determines the serializer that will be used and prepares an
instance of it for later call. This allows the serializer to
be accessed by extensions for, e.g., template extension.'
| def preserialize(self, content_type, default_serializers=None):
| (mtype, serializer) = self.get_serializer(content_type, default_serializers)
self.media_type = mtype
self.serializer = serializer()
|
'Attach slave templates to serializers.'
| def attach(self, **kwargs):
| if (self.media_type in kwargs):
self.serializer.attach(kwargs[self.media_type])
|
'Serializes the wrapped object.
Utility method for serializing the wrapped object. Returns a
webob.Response object.'
| def serialize(self, request, content_type, default_serializers=None):
| if self.serializer:
serializer = self.serializer
else:
(_mtype, _serializer) = self.get_serializer(content_type, default_serializers)
serializer = _serializer()
response = webob.Response()
response.status_int = self.code
for (hdr, value) in self._headers.items():
resp... |
'Retrieve the response status.'
| @property
def code(self):
| return (self._code or self._default_code)
|
'Retrieve the headers.'
| @property
def headers(self):
| return self._headers.copy()
|
':param controller: object that implement methods created by routes lib
:param action_peek: dictionary of routines for peeking into an action
request body to determine the desired action'
| def __init__(self, controller, action_peek=None, **deserializers):
| self.controller = controller
default_deserializers = dict(xml=XMLDeserializer, json=JSONDeserializer)
default_deserializers.update(deserializers)
self.default_deserializers = default_deserializers
self.default_serializers = dict(xml=XMLDictSerializer, json=JSONDictSerializer)
self.action_peek = ... |
'Registers controller actions with this resource.'
| def register_actions(self, controller):
| actions = getattr(controller, 'wsgi_actions', {})
for (key, method_name) in actions.items():
self.wsgi_actions[key] = getattr(controller, method_name)
|
'Registers controller extensions with this resource.'
| def register_extensions(self, controller):
| extensions = getattr(controller, 'wsgi_extensions', [])
for (method_name, action_name) in extensions:
extension = getattr(controller, method_name)
if action_name:
if (action_name not in self.wsgi_action_extensions):
self.wsgi_action_extensions[action_name] = []
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.