Turn the raw bucket data into a list of tuples containing the object,
        number of documents and a flag indicating whether this value has been
        selected or not.
970853
def get_values(self, data, filter_values):
        
        values = super(ModelTermsFacet, self).get_values(data, filter_values)
        ids = [key for (key, doc_count, selected) in values]
        # Perform a model resolution: models are feched from DB
        # We use model field to cast IDs
        ids = [self.model_field.to_mongo(id) for id in ids]
        objects = self.model.objects.in_bulk(ids)

        return [
            (objects.get(self.model_field.to_mongo(key)), doc_count, selected)
            for (key, doc_count, selected) in values
        ]
181111
def csv_to_map(fields, delimiter=','):
    

    def _csv_to_list(csv_input):
        """
        Util function to overcome the use of files by in-memory io buffer

        :param csv_input:
        :return:
        """
        io_file = io.StringIO(csv_input)
        return next(csv.reader(io_file, delimiter=delimiter))

    def _app(current_tuple, e=None):
        if current_tuple is None or len(current_tuple) == 0:
            return None, "no input"
        csv_list = _csv_to_list(current_tuple)
        if len(csv_list) != len(fields):
            e = {"input": "unexpected number of fields {} obtained {} expected".format(len(csv_list), len(fields))}
            return None, e
        return {k: v for (k, v) in zip(fields, csv_list)}, e
    if fields is None or len(fields) == 0:
        return fixed_input(None, "no fields provided, cannot proceed without order")
    return _app
116982
async def dump_tuple(self, elem, elem_type, params=None, obj=None):
        
        if len(elem) != len(elem_type.f_specs()):
            raise ValueError('Fixed size tuple has not defined size: %s' % len(elem_type.f_specs()))

        elem_fields = params[0] if params else None
        if elem_fields is None:
            elem_fields = elem_type.f_specs()

        obj = [] if obj is None else x.get_elem(obj)
        for idx, elem in enumerate(elem):
            try:
                self.tracker.push_index(idx)
                fvalue = await self._dump_field(elem, elem_fields[idx], params[1:] if params else None)
                obj.append(fvalue)
                self.tracker.pop()

            except Exception as e:
                raise helpers.ArchiveException(e, tracker=self.tracker) from e

        return obj
119387
def selected_objects(self):
        """"""

        return [
            obj
            for obj in self.text_objects
            if contains_or_overlap(self.table_bbox, obj.bbox)
        ]
619491
private static Document objectForInsert(Tuple tuple, Document dbObject) {
		MongoDBTupleSnapshot snapshot = (MongoDBTupleSnapshot) tuple.getSnapshot();
		for ( TupleOperation operation : tuple.getOperations() ) {
			String column = operation.getColumn();
			if ( notInIdField( snapshot, column ) ) {
				switch ( operation.getType() ) {
					case PUT:
						MongoHelpers.setValue( dbObject, column, operation.getValue() );
						break;
					case PUT_NULL:
					case REMOVE:
						MongoHelpers.resetValue( dbObject, column );
						break;
					}
			}
		}
		return dbObject;
	}
710705
def bucket(things, key):
    """"""
    ret = defaultdict(list)
    for thing in things:
        ret[key(thing)].append(thing)
    return ret
534088
def term_count_buckets(self):

        

        buckets = {}
        for term, count in self.term_counts().items():
            if count in buckets: buckets[count].append(term)
            else: buckets[count] = [term]

        return buckets
864342
def _make_it_list(dict_, field_name, value):
    '''
    
    '''
    prev_value = []
    # firsly we'll collect the prev value
    if field_name in dict_:
        prev_value = dict_[field_name]
    if value is None:
        return prev_value
    elif isinstance(value, (tuple, list)):
        # other type of iterables
        if field_name in ('source_port', 'destination_port'):
            # port fields are more special
            # they can either be a list of integers, either a list of tuples
            # list of integers = a list of ports
            # list of tuples = a list of ranges,
            # e.g.: [(1000, 2000), (3000, 4000)] means the 1000-2000 and 3000-4000 ranges
            portval = []
            for port in value:
                if not isinstance(port, (tuple, list)):
                    # to make sure everything is consistent,
                    # we'll transform indivitual ports into tuples
                    # thus an individual port e.g. 1000 will be transormed into the port range 1000-1000
                    # which is the equivalent
                    # but assures consistency for the Capirca parser
                    portval.append((port, port))
                else:
                    portval.append(port)
            translated_portval = []
            # and the ports sent as string, e.g. ntp instead of 123
            # needs to be translated
            # again, using the same /etc/services
            for port_start, port_end in portval:
                if not isinstance(port_start, int):
                    port_start = _translate_port(port_start)
                if not isinstance(port_end, int):
                    port_end = _translate_port(port_end)
                translated_portval.append(
                    (port_start, port_end)
                )
            return list(set(prev_value + translated_portval))
        return list(set(prev_value + list(value)))
    if field_name in ('source_port', 'destination_port'):
        if not isinstance(value, int):
            value = _translate_port(value)
        return list(set(prev_value + [(value, value)]))  # a list of tuples
    # anything else will be enclosed in a list-type
    return list(set(prev_value + [value]))
66047
def list_objects(Bucket, Delimiter=None, EncodingType=None, Prefix=None,
                 FetchOwner=False, StartAfter=None, region=None, key=None,
                 keyid=None, profile=None):
    '''
    

    '''

    try:
        Contents = []
        args = {'Bucket': Bucket, 'FetchOwner': FetchOwner}
        args.update({'Delimiter': Delimiter}) if Delimiter else None
        args.update({'EncodingType': EncodingType}) if Delimiter else None
        args.update({'Prefix': Prefix}) if Prefix else None
        args.update({'StartAfter': StartAfter}) if StartAfter else None
        conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
        IsTruncated = True
        while IsTruncated:
            ret = conn.list_objects_v2(**args)
            IsTruncated = ret.get('IsTruncated', False)
            if IsTruncated in ('True', 'true', True):
                args['ContinuationToken'] = ret['NextContinuationToken']
            Contents += ret.get('Contents', [])
        return {'Contents': Contents}
    except ClientError as e:
        return {'error': __utils__['boto3.get_error'](e)}
943945
def clean_data(data: dict) -> dict:
    """"""
    new_data = {}
    for key, value in data.items():
        # Verify that only explicitly passed args get passed on
        if not isinstance(value, bool) and not value:
            continue

        # Multiple choice command are passed as tuples, convert to list to match schema
        if isinstance(value, tuple):
            value = list(value)
        new_data[key] = value
    return new_data
63813
def _parse_list_buckets(self, (response, xml_bytes)):
        
        root = XML(xml_bytes)
        buckets = []
        for bucket_data in root.find("Buckets"):
            name = bucket_data.findtext("Name")
            date_text = bucket_data.findtext("CreationDate")
            date_time = parseTime(date_text)
            bucket = Bucket(name, date_time)
            buckets.append(bucket)
        return buckets
477953
def tuple_to_schema(tuple_):
    
    schema = []
    for element in tuple_:
        if isinstance(element, (tuple, list)):
            try:
                if isinstance(element[1], six.string_types):
                    schema.append((element[0],))
                else:
                    schema.append(tuple_to_schema(element))
            except IndexError:
                schema.append((element[0],))
        else:
            schema.append(element)
    return tuple(schema)
414912
def list_data(self):
        
        fn = (lambda v: json.loads(decode(v))) if self._use_json else decode
        return map(fn, self._data.values())
774406
def get(self, url=None, delimiter="/"):
        
        params = {'Delimiter': delimiter}
        bucket, obj_key = _parse_url(url)

        if bucket:
            params['Bucket'] = bucket
        else:
            return self.call("ListBuckets", response_data_key="Buckets")

        if obj_key:
            params['Prefix'] = obj_key

        objects = self.call("ListObjects", response_data_key="Contents",
                            **params)
        if objects:
            for obj in objects:
                obj['url'] = "s3://{0}/{1}".format(bucket, obj['Key'])

        return objects
581669
def buckets(self):
        
        buckets = []
        for table in self.__metadata.sorted_tables:
            bucket = self.__mapper.restore_bucket(table.name)
            if bucket is not None:
                buckets.append(bucket)
        return buckets
794342
def to_value(self, obj, resource, visited=set()):
        """"""

        if id(obj) in visited:
            raise ValueError('Circular reference detected when attempting to serialize object')

        if isinstance(obj, (list, tuple, set)):
            return [self.to_value(x, resource) if hasattr(x, '__dict__') else x for x in obj]
        elif hasattr(obj, '__dict__'):
            attrs = obj.__dict__.copy()
            for key in six.iterkeys(obj.__dict__):
                if key.startswith('_'):
                    del attrs[key]

            return {
                self.reverse_aliases.get(k, k):
                    self.to_value(v, resource) if hasattr(v, '__dict__') or isinstance(v, (list, tuple, set)) else v
                for k, v in six.iteritems(attrs)
            }
        else:
            return obj
1219971
def list_documents(self, limit=None):
        
        from itertools import chain

        return chain(self.backend.dataset_index.list_documents(limit=limit),
                     self.backend.partition_index.list_documents(limit=limit),
                     self.backend.identifier_index.list_documents(limit=limit))