jnpr/space/resource.py
def put(self, new_val_obj=None, request_body=None,
            accept=None, content_type=None):
        """Modifies the state of this resource on Space by sending a PUT request
        with the new state. The attributes of *new_val_obj* are
        formatted to form the XML request body for the PUT request. If the
        parameter *new_val_obj* is ``None``, then the argument *request_body*,
        if present, is used as the request body. If this is also ``None``, then
        the attributes of this object itself are formatted to form the XML
        request body. Once the PUT request successfully completes, it
        re-initializes the state of this Resource object based on the XML
        response from Space.

        :param new_val_obj: A Resource object with the newly desired state for
            the resource. This defaults to ``None``.
        :type new_val_obj: jnpr.space.resource.Resource

        :param str request_body: This can be used to supply a string that must
            be used as the request body in the request. This defaults to
            ``None`` and in this case SpaceEZ will create the request body
            using the supplied ``new_val_obj`` argument or from the current
            state of this object.

        :param str accept: This can be used to supply a media-type that must
            be used as the Accept header in the request. This defaults to
            ``None`` and in this case SpaceEZ will use the media-type modeled
            in the description file.

        :param str content_type: This can be used to supply a media-type that must
            be used as the Content-Type header in the request. This defaults to
            ``None`` and in this case SpaceEZ will use the media-type modeled
            in the description file.

        :returns: ``None``
        :raises: ``jnpr.space.rest.RestException`` if the PUT method results in
            an error response. The exception's ``response`` attribute will have
            the full response from Space.

        """
        if request_body is not None:
            body = request_body
            if new_val_obj is not None:
                raise ValueError('Cannot use both request_body and new_val_obj')
        elif new_val_obj is not None:
            body = etree.tostring(new_val_obj.form_xml(), encoding='unicode')
        else:
            body = etree.tostring(self.form_xml(), encoding='unicode')

        if content_type is not None:
            mtype = content_type
        else:
            mtype = self.get_meta_object().get_media_type(None)

        headers = {'content-type': mtype}

        if accept is not None:
            headers['accept'] = accept

        response = self._rest_end_point.put(self.get_href(),
                                            headers,
                                            body)
        if response.status_code != 200:
            raise rest.RestException("PUT failed on %s" % self.get_href(),
                                     response)

        # Fixing issue #17
        #r = response.text
        # Skip the <?xml> line to avoid encoding errors in lxml
        #start = r.index('?><') + 2
        #root = etree.fromstring(r[start:])
        #root = etree.fromstring(response.content)

        # Fixing issue #19 self._xml_data = root
        resp_text = xmlutil.get_text_from_response(response)
        self._xml_data = xmlutil.xml2obj(resp_text)
Modifies the state of this resource on Space by sending a PUT request
        with the new state. The attributes of *new_val_obj* are
        formatted to form the XML request body for the PUT request. If the
        parameter *new_val_obj* is ``None``, then the argument *request_body*,
        if present, is used as the request body. If this is also ``None``, then
        the attributes of this object itself are formatted to form the XML
        request body. Once the PUT request successfully completes, it
        re-initializes the state of this Resource object based on the XML
        response from Space.

        :param new_val_obj: A Resource object with the newly desired state for
            the resource. This defaults to ``None``.
        :type new_val_obj: jnpr.space.resource.Resource

        :param str request_body: This can be used to supply a string that must
            be used as the request body in the request. This defaults to
            ``None`` and in this case SpaceEZ will create the request body
            using the supplied ``new_val_obj`` argument or from the current
            state of this object.

        :param str accept: This can be used to supply a media-type that must
            be used as the Accept header in the request. This defaults to
            ``None`` and in this case SpaceEZ will use the media-type modeled
            in the description file.

        :param str content_type: This can be used to supply a media-type that must
            be used as the Content-Type header in the request. This defaults to
            ``None`` and in this case SpaceEZ will use the media-type modeled
            in the description file.

        :returns: ``None``
        :raises: ``jnpr.space.rest.RestException`` if the PUT method results in
            an error response. The exception's ``response`` attribute will have
            the full response from Space.

        
Modifies the state of this resource on Space by sending a PUT request
with the new state. The attributes of *new_val_obj* are
formatted to form the XML request body for the PUT request. If the
parameter *new_val_obj* is ``None``, then the argument *request_body*,
if present, is used as the request body. If this is also ``None``, then
the attributes of this object itself are formatted to form the XML
request body. Once the PUT request successfully completes, it
re-initializes the state of this Resource object based on the XML
response from Space.
Modifies the state of this resource on Space by sending a PUT request with the new state . The attributes of * new_val_obj * are formatted to form the XML request body for the PUT request . If the parameter * new_val_obj * is ` ` None ` ` then the argument * request_body * if present is used as the request body . If this is also ` ` None ` ` then the attributes of this object itself are formatted to form the XML request body . Once the PUT request successfully completes it re - initializes the state of this Resource object based on the XML response from Space .
def put(self, new_val_obj=None, request_body=None,
            accept=None, content_type=None):
        if request_body is not None:
            body = request_body
            if new_val_obj is not None:
                raise ValueError('Cannot use both request_body and new_val_obj')
        elif new_val_obj is not None:
            body = etree.tostring(new_val_obj.form_xml(), encoding='unicode')
        else:
            body = etree.tostring(self.form_xml(), encoding='unicode')
        if content_type is not None:
            mtype = content_type
        else:
            mtype = self.get_meta_object().get_media_type(None)
        headers = {'content-type': mtype}
        if accept is not None:
            headers['accept'] = accept
        response = self._rest_end_point.put(self.get_href(),
                                            headers,
                                            body)
        if response.status_code != 200:
            raise rest.RestException("PUT failed on %s" % self.get_href(),
                                     response)
        resp_text = xmlutil.get_text_from_response(response)
        self._xml_data = xmlutil.xml2obj(resp_text)
def put ( self , new_val_obj = None , request_body = None , accept = None , content_type = None ) : if request_body is not None : body = request_body if new_val_obj is not None : raise ValueError ( 'Cannot use both request_body and new_val_obj' ) elif new_val_obj is not None : body = etree . tostring ( new_val_obj . form_xml ( ) , encoding = 'unicode' ) else : body = etree . tostring ( self . form_xml ( ) , encoding = 'unicode' ) if content_type is not None : mtype = content_type else : mtype = self . get_meta_object ( ) . get_media_type ( None ) headers = { 'content-type' : mtype } if accept is not None : headers [ 'accept' ] = accept response = self . _rest_end_point . put ( self . get_href ( ) , headers , body ) if response . status_code != 200 : raise rest . RestException ( "PUT failed on %s" % self . get_href ( ) , response ) resp_text = xmlutil . get_text_from_response ( response ) self . _xml_data = xmlutil . xml2obj ( resp_text )
Modifies the state of this resource on Space by sending a PUT request
with the new state.
Modifies the state of this resource on Space by sending a PUT request with the new state .
"""Modifies the state of this resource on Space by sending a PUT request
        with the new state. The attributes of *new_val_obj* are
        formatted to form the XML request body for the PUT request. If the
        parameter *new_val_obj* is ``None``, then the argument *request_body*,
        if present, is used as the request body. If this is also ``None``, then
        the attributes of this object itself are formatted to form the XML
        request body. Once the PUT request successfully completes, it
        re-initializes the state of this Resource object based on the XML
        response from Space.

        :param new_val_obj: A Resource object with the newly desired state for
            the resource. This defaults to ``None``.
        :type new_val_obj: jnpr.space.resource.Resource

        :param str request_body: This can be used to supply a string that must
            be used as the request body in the request. This defaults to
            ``None`` and in this case SpaceEZ will create the request body
            using the supplied ``new_val_obj`` argument or from the current
            state of this object.

        :param str accept: This can be used to supply a media-type that must
            be used as the Accept header in the request. This defaults to
            ``None`` and in this case SpaceEZ will use the media-type modeled
            in the description file.

        :param str content_type: This can be used to supply a media-type that must
            be used as the Content-Type header in the request. This defaults to
            ``None`` and in this case SpaceEZ will use the media-type modeled
            in the description file.

        :returns: ``None``
        :raises: ``jnpr.space.rest.RestException`` if the PUT method results in
            an error response. The exception's ``response`` attribute will have
            the full response from Space.

        """ # Fixing issue #17 #r = response.text # Skip the <?xml> line to avoid encoding errors in lxml #start = r.index('?><') + 2 #root = etree.fromstring(r[start:]) #root = etree.fromstring(response.content) # Fixing issue #19 self._xml_data = root
None
``jnpr.space.rest.RestException`` if the PUT method results in
an error response. The exception's ``response`` attribute will have
the full response from Space.
` ` jnpr . space . rest . RestException ` ` if the PUT method results in an error response . The exception ' s ` ` response ` ` attribute will have the full response from Space .
self
new_val_obj
A Resource object with the newly desired state for
the resource. This defaults to ``None``.
A Resource object with the newly desired state for the resource . This defaults to ` ` None ` ` .
``None``
request_body
This can be used to supply a string that must
be used as the request body in the request. This defaults to
``None`` and in this case SpaceEZ will create the request body
using the supplied ``new_val_obj`` argument or from the current
state of this object.
This can be used to supply a string that must be used as the request body in the request . This defaults to ` ` None ` ` and in this case SpaceEZ will create the request body using the supplied ` ` new_val_obj ` ` argument or from the current state of this object .
accept
This can be used to supply a media-type that must
be used as the Accept header in the request. This defaults to
``None`` and in this case SpaceEZ will use the media-type modeled
in the description file.
This can be used to supply a media - type that must be used as the Accept header in the request . This defaults to ` ` None ` ` and in this case SpaceEZ will use the media - type modeled in the description file .
content_type
This can be used to supply a media-type that must
be used as the Content-Type header in the request. This defaults to
``None`` and in this case SpaceEZ will use the media-type modeled
in the description file.
This can be used to supply a media - type that must be used as the Content - Type header in the request . This defaults to ` ` None ` ` and in this case SpaceEZ will use the media - type modeled in the description file .