Create an Attachment object in the given container
551427
def create_attachment(self, container, attachment_file, **kw):
        
        filename = getattr(attachment_file, "filename", "Attachment")
        attachment = api.create(container, "Attachment", title=filename)
        attachment.edit(AttachmentFile=attachment_file, **kw)
        attachment.processForm()
        attachment.reindexObject()
        logger.info("Created new Attachment {} in {}".format(
            repr(attachment), repr(container)))
        return attachment
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."
562074
private function constructBody ()
    {

        // Set variables

        $body	= NULL;

        // Create body string

        foreach ($this->_body as $bodyBlock)
        {
            $body .= $bodyBlock;
        }

        // Add as an attachment

        return $this->addAttachment (FALSE, NULL, $body);

    }
367435
def attach(obj, schema):
  """"""

  # We have a silly exception for lists, since they have no 'attach_schema'
  # method, and I don't feel like making a subclass for List just to add it.
  # So, we recursively search the list for tuples and attach the schema in
  # there.
  if framework.is_list(obj) and isinstance(schema, ListSchema):
    for x in obj:
      attach(x, schema.element_schema)
    return

  # Otherwise, the object should be able to handle its own schema attachment.
  getattr(obj, 'attach_schema', nop)(schema)
1169500
public SoapServerFaultResponseActionBuilder attachment(String contentId, String contentType, Resource contentResource, Charset charset) {
        SoapAttachment attachment = new SoapAttachment();
        attachment.setContentId(contentId);
        attachment.setContentType(contentType);

        try {
            attachment.setContent(FileUtils.readToString(contentResource, charset));
        } catch (IOException e) {
            throw new CitrusRuntimeException("Failed to read attachment resource", e);
        }

        getAction().getAttachments().add(attachment);

        return this;
    }
1210158
def macros_attachment_create(self, data, **kwargs):
        ""
        api_path = "/api/v2/macros/attachments.json"
        return self.call(api_path, method="POST", data=data, **kwargs)
1207314
def _copy_attachment(self, name, data, mimetype, mfg_event):
    """"""
    attachment = mfg_event.attachment.add()
    attachment.name = name
    if isinstance(data, unicode):
      data = data.encode('utf8')
    attachment.value_binary = data
    if mimetype in test_runs_converter.MIMETYPE_MAP:
      attachment.type = test_runs_converter.MIMETYPE_MAP[mimetype]
    elif mimetype == test_runs_pb2.MULTIDIM_JSON:
      attachment.type = mimetype
    else:
      attachment.type = test_runs_pb2.BINARY
369791
def create_container(app_id,container_id,container_name):
    
    try:
        conn = get_conn()
        c = conn.cursor()
        c.execute("INSERT INTO container (id,name,app_id) VALUES ('{0}','{1}','{2}')"
            .format(container_id,container_name,app_id))
        conn.commit()
        conn.close()
        print 'create container %s succeed!' % app_id
    except Exception,e :
        raise RuntimeError('create container %s failed! %s' % (app_id,e))
881827
def addAttachment(self, attachment):
        
        if not isinstance(attachment, (list, tuple)):
            attachment = [attachment]

        original = self.getAttachment() or []

        # Function addAttachment can accept brain, objects or uids
        original = map(api.get_uid, original)
        attachment = map(api.get_uid, attachment)

        # Boil out attachments already assigned to this Analysis Request
        attachment = filter(lambda at: at not in original, attachment)
        if attachment:
            original.extend(attachment)
            self.setAttachment(original)
1218682
def add_attachment(self, file_path, mimetype=None):
        """"""
        if not mimetype:
            mimetype, _ = mimetypes.guess_type(file_path)

        if mimetype is None:
            mimetype = 'application/octet-stream'

        type_maj, type_min = mimetype.split('/')
        with open(file_path, 'rb') as fh:
            part_data = fh.read()

            part = MIMEBase(type_maj, type_min)
            part.set_payload(part_data)
            email_encoders.encode_base64(part)

            part_filename = os.path.basename(self._encoded(file_path))
            part.add_header('Content-Disposition', 'attachment; filename="%s"'
                            % part_filename)

            self._parts.append((mimetype, part))
1140898
def upload_file(self, container, src_file_path, dst_name=None, put=True,
                    content_type=None):
        """"""
        if not os.path.exists(src_file_path):
            raise RuntimeError('file not found: ' + src_file_path)
        if not dst_name:
            dst_name = os.path.basename(src_file_path)
        if not content_type:
            content_type = "application/octet.stream"
        headers = dict(self._base_headers)
        if content_type:
            headers["content-length"] = content_type
        else:
            headers["content-length"] = "application/octet.stream"
        headers["content-length"] = str(os.path.getsize(src_file_path))
        headers['content-disposition'] = 'attachment; filename=' + dst_name
        if put:
            method = 'PUT'
            url = self.make_url(container, dst_name, None)
        else:
            method = 'POST'
            url = self.make_url(container, None, None)
        with open(src_file_path, 'rb') as up_file:
            try:
                rsp = requests.request(method, url, headers=headers,
                                       data=up_file, timeout=self._timeout)
            except requests.exceptions.ConnectionError as e:
                RestHttp._raise_conn_error(e)

        return self._handle_response(rsp)
465110
def to_email_attachment(self, filename, filedata, **kw):
        
        maintype = "application"
        subtype = "octet-stream"

        mime_type = mimetypes.guess_type(filename)[0]
        if mime_type is not None:
            maintype, subtype = mime_type.split("/")

        attachment = MIMEBase(maintype, subtype, **kw)
        attachment.set_payload(filedata)
        encoders.encode_base64(attachment)
        attachment.add_header("Content-Disposition",
                              "attachment; filename=%s" % filename)
        return attachment
1046549
def attach(self, stdout=True, stderr=True, stream=True, logs=False):
        

        try:
            data = parse_stream(self.client.attach(self.id, stdout, stderr, stream, logs))
        except KeyboardInterrupt:
            logger.warning(
                "service container: {0} has been interrupted. "
                "The container will be stopped but will not be deleted.".format(self.name)
            )
            data = None
            self.stop()

        return data
25940
def create(cls, attachment_public_uuid, custom_headers=None):
        

        if custom_headers is None:
            custom_headers = {}

        request_map = {
            cls.FIELD_ATTACHMENT_PUBLIC_UUID: attachment_public_uuid
        }
        request_map_string = converter.class_to_json(request_map)
        request_map_string = cls._remove_field_for_request(request_map_string)

        api_client = client.ApiClient(cls._get_api_context())
        request_bytes = request_map_string.encode()
        endpoint_url = cls._ENDPOINT_URL_CREATE
        response_raw = api_client.post(endpoint_url, request_bytes,
                                       custom_headers)

        return BunqResponseStr.cast_from_bunq_response(
            cls._process_for_uuid(response_raw)
        )
95717
public MultipartBuilder attachment(InputStream is, String filename) {
        return bodyPart(new StreamDataBodyPart(ATTACHMENT_NAME, is, filename));
    }
287913
def container_tree(container=None,image_package=None):
    '''
    '''

    guts = get_container_contents(container=container,
                                  image_package=image_package,
                                  split_delim="\n")

    # Make the tree and return it
    tree = make_container_tree(folders = guts["folders.txt"],
                               files = guts['files.txt'])
    return tree
1135515
def add_attachment(self, attachment):
        
        self._attachments = self._ensure_append(attachment, self._attachments)