Get all parts for a specific multipart upload.

        :param multipart: A :class:`invenio_files_rest.models.MultipartObject`
            instance.
        :returns: A :class:`invenio_files_rest.models.Part` instance.
498954
def query_by_multipart(cls, multipart):
        
        upload_id = multipart.upload_id \
            if isinstance(multipart, MultipartObject) else multipart
        return cls.query.filter_by(
            upload_id=upload_id
        )
213463
def wrap_multipart_params(func):
    

    def wrapper(request, *args, **kwargs):
        ctype, pdict = parse_header(request.headers.get('Content-Type', ''))
        if ctype == "multipart/form-data":

            if isinstance(pdict['boundary'], str):
                pdict['boundary'] = pdict['boundary'].encode()

            params = {}
            mp = MultipartParser(BytesIO(request.body), pdict['boundary'])
            for part in mp:
                params[part.name] = {
                    "filename": part.filename,
                    "file": part.file,
                }

            request.params = merge_dicts(getattr(request, "params", None), params)
            request.multipart_params = params

        return func(request, *args, **kwargs)
    return wrapper
790377
private void loadAllParts()
        throws IOException
    {
        // Get first boundary
        String line = _in.readLine();
        if (!line.equals(_boundary))
        {
            log.warn(line);
            throw new IOException("Missing initial multi part boundary");
        }
        
        // Read each part
        while (!_lastPart)
        {
            // Read Part headers
            Part part = new Part();
            
            String content_disposition=null;
            while ((line=_in.readLine())!=null)
            {
                // If blank line, end of part headers
                if (line.length()==0)
                    break;

                if(log.isDebugEnabled())log.debug("LINE="+line);
                
                // place part header key and value in map
                int c = line.indexOf(':',0);
                if (c>0)
                {
                    String key = line.substring(0,c).trim().toLowerCase();
                    String value = line.substring(c+1,line.length()).trim();
                    String ev = (String) part._headers.get(key);
                    part._headers.put(key,(ev!=null)?(ev+';'+value):value);
                    if(log.isDebugEnabled())log.debug(key+": "+value);
                    if (key.equals("content-disposition"))
                        content_disposition=value;
                }
            }

            // Extract content-disposition
            boolean form_data=false;
            if (content_disposition==null)
            {
                throw new IOException("Missing content-disposition");
            }
            
            StringTokenizer tok =
                new StringTokenizer(content_disposition,";");
            while (tok.hasMoreTokens())
            {
                String t = tok.nextToken().trim();
                String tl = t.toLowerCase();
                if (t.startsWith("form-data"))
                    form_data=true;
                else if (tl.startsWith("name="))
                    part._name=value(t);
                else if (tl.startsWith("filename="))
                    part._filename=value(t);
            }

            // Check disposition
            if (!form_data)
            {
                log.warn("Non form-data part in multipart/form-data");
                continue;
            }
            if (part._name==null || part._name.length()==0)
            {
                log.warn("Part with no name in multipart/form-data");
                continue;
            }
            if(log.isDebugEnabled())log.debug("name="+part._name);
            if(log.isDebugEnabled())log.debug("filename="+part._filename);
            _partMap.add(part._name,part);
            part._data=readBytes();
        }       
    }
462149
def part_lister(mpupload, part_number_marker=None):
    
    more_results = True
    part = None
    while more_results:
        parts = mpupload.get_all_parts(None, part_number_marker)
        for part in parts:
            yield part
        part_number_marker = mpupload.next_part_number_marker
        more_results= mpupload.is_truncated
1139348
def _part_cls_for(cls, content_type):
        
        if content_type in cls.part_type_for:
            return cls.part_type_for[content_type]
        return cls.default_part_type
938353
def _list_object_parts(self, bucket_name, object_name, upload_id):
        
        is_valid_bucket_name(bucket_name)
        is_non_empty_string(object_name)
        is_non_empty_string(upload_id)

        query = {
            'uploadId': upload_id,
            'max-parts': '1000'
        }

        is_truncated = True
        part_number_marker = ''
        while is_truncated:
            if part_number_marker:
                query['part-number-marker'] = str(part_number_marker)

            response = self._url_open('GET',
                                      bucket_name=bucket_name,
                                      object_name=object_name,
                                      query=query)

            parts, is_truncated, part_number_marker = parse_list_parts(
                response.data,
                bucket_name=bucket_name,
                object_name=object_name,
                upload_id=upload_id
            )
            for part in parts:
                yield part
524796
def mkFilter(parts):
    
    # Convert the parts into a list, and pass to mkCompoundFilter
    if parts is None:
        parts = [BasicServiceEndpoint]

    try:
        parts = list(parts)
    except TypeError:
        return mkCompoundFilter([parts])
    else:
        return mkCompoundFilter(parts)
774361
def parts(self):
        """"""

        parts = []

        upserts = dict()
        deletes = []

        # we keep track of the batch size as we go (pretty close approximation!) so we can chunk it small enough
        # to limit the HTTP posts to under 700KB - server limits to 750KB, so play it safe
        max_upload_size = 700000

        # loop upserts first - fit the deletes in afterward
        # '{"replace_all": true, "complete": false, "guid": "6659fbfc-3f08-42ee-998c-9109f650f4b7", "upserts": [], "deletes": []}'
        base_part_size = 118
        if not self.replace_all:
            base_part_size += 1  # yeah, this is totally overkill :)

        part_size = base_part_size
        for value in self.upserts:
            if (part_size + self.upserts_size[value]) >= max_upload_size:
                # this record would put us over the limit - close out the batch part and start a new one
                parts.append(BatchPart(self.replace_all, upserts, deletes))
                upserts = dict()
                deletes = []
                part_size = base_part_size

            # for the new upserts dict, drop the lower-casing of value
            upserts[self.lower_val_to_val[value]] = self.upserts[value]
            part_size += self.upserts_size[value]    # updating the approximate size of the batch

        for value in self.deletes:
            # delete adds length of string plus quotes, comma and space
            if (part_size + len(value) + 4) >= max_upload_size:
                parts.append(BatchPart(self.replace_all, upserts, deletes))
                upserts = dict()
                deletes = []
                part_size = base_part_size

            # for the new deletes set, drop the lower-casing of value
            deletes.append({'value': self.lower_val_to_val[value]})
            part_size += len(value) + 4

        if len(upserts) + len(deletes) > 0:
            # finish the batch
            parts.append(BatchPart(self.replace_all, upserts, deletes))

        if len(parts) == 0:
            if not self.replace_all:
                raise ValueError("Batch has no data, and 'replace_all' is False")
            parts.append(BatchPart(self.replace_all, dict(), []))

        # last part finishes the batch
        parts[-1].set_last_part()
        return parts
837533
def submit(self):

        
        futures = []
        while self.submitted < 4 and not self.done():
            part = self.parts.pop(0)
            part_number = part['part']
            part_read_offset = part['offset']
            part_read_limit = part['limit']

            self.fp.seek(part_read_offset)
            part_data = self.fp.read(part_read_limit - part_read_offset)

            futures.append(
                self.pool.submit(
                    _upload_part, self.api, self.session,
                    self._URL['upload_part'], self.upload_id,
                    part_number, part_data, self.retry, self.timeout
                )
            )

            self.submitted += 1
            self.total_submitted += 1

        return futures
783398
private Part createPart(Attachment a) {
        return Part.builder().setName(a.getName() != null ? a.getName() : a.getId()).setSize(a.getSize()).setType(a.getType()).setUrl(a.getUrl()).build();
    }
1334007
static Map<String,Collection<String>> extractTextParts(Multipart multiPart) throws MessagingException, IOException {
        HashMap<String,Collection<String>> bodies = new HashMap<>();
        for(int i = 0; i < multiPart.getCount(); i++) {
            checkPartForTextType(bodies, multiPart.getBodyPart(i));
        }
        return bodies;
    }
712597
def getPartitionList(self):
        
        if self._partList is None:
            self._partList = []
            for (disk,parts) in self.getPartitionDict().iteritems():
                for part in parts:
                    self._partList.append((disk,part))
        return self._partList
385995
def create(cls, mp, part_number, stream=None, **kwargs):
        """"""
        if part_number < 0 or part_number > mp.last_part_number:
            raise MultipartInvalidPartNumber()

        with db.session.begin_nested():
            obj = cls(
                multipart=mp,
                part_number=part_number,
            )
            db.session.add(obj)
        if stream:
            obj.set_contents(stream, **kwargs)
        return obj
1243586
def get_assessment_part_form(self, *args, **kwargs):
        """"""
        # This method might be a bit sketchy. Time will tell.
        if isinstance(args[-1], list) or 'assessment_part_record_types' in kwargs:
            return self.get_assessment_part_form_for_create(*args, **kwargs)
        else:
            return self.get_assessment_part_form_for_update(*args, **kwargs)
1043831
def rectify_multipart_form_data(self, data):
        
        for name, field in self.base_fields.items():
            try:
                field.implode_multi_values(name, data)
            except AttributeError:
                pass
        return data
367154
def files(self):
        
        files = FormsDict()
        for name, item in self.POST.allitems():
            if isinstance(item, FileUpload):
                files[name] = item
        return files
624995
def normalize(self, parts):
        

        part = parts.list[0]

        return {
            'content': part.file.read(),
            'content-type': part.type,
            'file-ext': extensions.get(part.type),
            'file-name': part.filename,
        }