Edit a device's attachment.

        :param resource: :class:`attachments.Attachment <attachments.Attachment>` object
        :return: :class:`attachments.Attachment <attachments.Attachment>` object
        :rtype: attachments.Attachment
164846
def edit(self, resource): # pylint: disable=invalid-name,redefined-builtin
        
        schema = AttachmentSchema(exclude=('id', 'created', 'updated', 'size', 'path', 'device_id'))
        json = self.service.encode(schema, resource)

        schema = AttachmentSchema()
        resp = self.service.edit(self._base(resource.device_id), resource.id, json)
        return self.service.decode(schema, resp)
1310876
def attach(self, id, filename, url):
        
        Attachment = self.client.model('ir.attachment')
        return Attachment.add_attachment_from_url(
            filename, url, '%s,%s' % (self.model_name, id)
        )
1140650
def add_attachment(self, attachment):
        
        log = logging.getLogger(self.cls_logger + '.add_attachment')
        if not isinstance(attachment, SlackAttachment):
            msg = 'attachment must be of type: SlackAttachment'
            log.error(msg)
            raise ValueError(msg)
        self.attachments.append(attachment.attachment)
        log.debug('Added attachment: {a}'.format(a=attachment))
937963
def update_in_hdx(self, **kwargs):
        # type: (Any) -> None
        
        self._check_load_existing_object('resource', 'id')
        if self.file_to_upload and 'url' in self.data:
            del self.data['url']
        self._merge_hdx_update('resource', 'id', self.file_to_upload, **kwargs)
1097565
def apply(self, resource):
        
        if not isinstance(resource, Image.Image):
            raise ValueError('Unknown resource format')

        resource_format = resource.format
        if resource.mode != 'RGBA':  # pragma: no cover
            resource = resource.convert('RGBA')

        layer = Image.new('RGBA', resource.size, (0, 0, 0, 0))
        image, left, upper = getattr(self, '_' + self.position + '_position')(resource)
        layer.paste(image, (left, upper))

        image = Image.composite(layer, resource, layer)
        image.format = resource_format

        return image
1248157
def attach(doc_id, doc_rev, attachment_name, data, opts=nil)

      if opts.nil?
        opts = data
        data = attachment_name
        attachment_name = doc_rev
        doc_rev = doc_id['_rev']
        doc_id = doc_id['_id']
      end

      attachment_name = attachment_name.gsub(/\//, '%2F')

      ct = opts[:content_type]

      raise(ArgumentError.new(
        ":content_type option must be specified"
      )) unless ct

      opts[:cache] = false

      path = adjust("#{doc_id}/#{attachment_name}?rev=#{doc_rev}")

      if @http.variant == :patron

        # patron, as of 0.4.5 (~> 0.4.10), has difficulties when PUTting
        # attachements
        # this is a fallback to net/http

        require 'net/http'

        http = Net::HTTP.new(@http.host, @http.port)

        req = Net::HTTP::Put.new(path)
        req['User-Agent'] =
          "rufus-jig #{Rufus::Jig::VERSION} (patron 0.4.x fallback to net/http)"
        req['Content-Type'] =
          opts[:content_type]
        req['Accept'] =
          'application/json'
        req.body = data

        res = Rufus::Jig::HttpResponse.new(http.start { |h| h.request(req) })

        return @http.send(:respond, :put, path, nil, opts, nil, res)
      end

      @http.put(path, data, opts)
    end
812632
def add_resource(self, resource):
        
        updated_sentence = NeedsProfile.format_sentence(
            resource['Readable sentence'], resource)
        if self.edit_item:
            item = self.edit_item
            item.setText(updated_sentence)
            self.edit_item = None
        else:
            item = QtWidgets.QListWidgetItem(updated_sentence)
        item.resource_full = resource
        self.resources_list.addItem(item)
326454
def add(self, resource):
        
        if isinstance(resource, collections.Iterable):
            for r in resource:
                self.resources.append(r)
        else:
            self.resources.append(resource)
910530
def edit(self, resource):
        
        schema = TagSchema(only=('name', 'configs', 'devices', 'packages', 'results'))
        json = self.service.encode(schema, resource)

        schema = TagSchema()
        resp = self.service.edit(self.base, resource.name, json)
        return self.service.decode(schema, resp)
745522
def update_resource(self, resource):
        ''''''
        index = self.resources.index(resource)
        data = {
            'resources__{index}'.format(index=index): resource
        }
        self.update(**data)
        self.reload()
        post_save.send(self.__class__, document=self)
1305772
def edit(self, **kwargs):
        
        response = self._requester.request(
            'PUT',
            'calendar_events/{}'.format(self.id),
            _kwargs=combine_kwargs(**kwargs)
        )

        if 'title' in response.json():
            super(CalendarEvent, self).set_attributes(response.json())

        return CalendarEvent(self._requester, response.json())
388999
def put_resource(self, resource):
        
        rtracker = self._get_tracker(resource)

        try:
            self._put(rtracker)
        except PoolFullError:
            self._remove(rtracker)
827089
def addAttachment(self, oid, file_path):
        
        if self.hasAttachments == True:
            attachURL = self._url + "/%s/addAttachment" % oid
            params = {'f':'json'}
            parsed = urlparse.urlparse(attachURL)

            files = {'attachment': file_path}
            res = self._post(url=attachURL,
                             param_dict=params,
                             files=files,
                             securityHandler=self._securityHandler,
                             proxy_port=self._proxy_port,
                             proxy_url=self._proxy_url)
            return self._unicode_convert(res)
        else:
            return "Attachments are not supported for this feature service."
684182
def _attach(self, fcp, assigner_id, target_wwpn, target_lun,
                multipath, os_version, mount_point):
        
        LOG.info('Start to attach device to %s' % assigner_id)
        self.fcp_mgr.init_fcp(assigner_id)
        new = self.fcp_mgr.increase_fcp_usage(fcp, assigner_id)
        try:
            if new:
                self._dedicate_fcp(fcp, assigner_id)

            self._add_disk(fcp, assigner_id, target_wwpn, target_lun,
                           multipath, os_version, mount_point)
        except exception.SDKBaseException as err:
            errmsg = 'rollback attach because error:' + err.format_message()
            LOG.error(errmsg)
            connections = self.fcp_mgr.decrease_fcp_usage(fcp, assigner_id)
            # if connections less than 1, undedicate the device
            if not connections:
                with zvmutils.ignore_errors():
                    self._undedicate_fcp(fcp, assigner_id)
            raise exception.SDKBaseException(msg=errmsg)
        # TODO: other exceptions?

        LOG.info('Attaching device to %s is done.' % assigner_id)
38059
def openattachment(self, attachid):
        
        attachments = self.get_attachments(None, attachid)
        data = attachments["attachments"][str(attachid)]
        xmlrpcbinary = data["data"]

        ret = BytesIO()
        ret.write(xmlrpcbinary.data)
        ret.name = data["file_name"]
        ret.seek(0)
        return ret
1280251
def apply(self, resource):
        
        if not isinstance(resource, Image.Image):
            raise ValueError('Unknown resource format')

        resource_format = resource.format
        resource = resource.rotate(self.angle, expand=True)
        resource.format = resource_format

        return resource
43515
def update(self):
        
        super(AttachmentsViewlet, self).update()
        self.attachments_view = self.get_attachments_view()